This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TemplateVerificationExceptionTests.cs
49 lines (38 loc) · 1.76 KB
/
TemplateVerificationExceptionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace TestProject;
using FluentAssertions;
using Microsoft.TemplateEngine.Authoring.TemplateVerifier;
using Xunit.Abstractions;
using Xunit.Extensions.Logging;
public class TemplateVerificationExceptionTests(ITestOutputHelper outputHelper)
{
private readonly VerificationEngine engine = new(new XunitLogger(outputHelper, nameof(TemplateVerificationExceptionTests), (_, _) => true));
[Fact]
public async Task Should_Return_Error_Code_106_When_Template_Path_Is_Invalid()
{
var options = new TemplateVerifierOptions("my-template")
{
TemplatePath = CreateBadName(),
DisableDiffTool = true,
};
var act = () => engine.Execute(options);
var exception = await act.Should().ThrowAsync<TemplateVerificationException>();
exception.Which.TemplateVerificationErrorCode.Should()
.Be(TemplateVerificationErrorCode.InstallFailed, "because the path is invalid and error code reported in the exception message and ILogger are both '106'");
}
[Fact]
public async Task Should_Return_Error_Code_103_When_Template_Name_Is_Invalid()
{
var options = new TemplateVerifierOptions(CreateBadName())
{
TemplatePath = "my-template",
DisableDiffTool = true,
};
var act = () => engine.Execute(options);
var exception = await act.Should().ThrowAsync<TemplateVerificationException>();
exception
.Which.TemplateVerificationErrorCode.Should()
.Be(TemplateVerificationErrorCode.TemplateDoesNotExist, "because the template does not exist and the error code reported in the exception message and ILogger are both '103'");
}
private static string CreateBadName()
=> Guid.NewGuid().ToString();
}