-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathExampleTemplateTest.cs
More file actions
96 lines (84 loc) · 4.45 KB
/
ExampleTemplateTest.cs
File metadata and controls
96 lines (84 loc) · 4.45 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Extensions.Logging;
using Microsoft.TemplateEngine.Authoring.TemplateApiVerifier;
using Microsoft.TemplateEngine.TestHelper;
using Microsoft.TemplateEngine.Tests;
namespace Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests
{
public class ExampleTemplateTest : TestBase
{
private readonly ILogger _log;
public ExampleTemplateTest(ITestOutputHelper log)
{
_log = new XunitLoggerProvider(log).CreateLogger("TestRun");
}
// Following 2 tests share identical snapshot folder - that's the reason for the additional
// naming parameters (DoNotPrependCallerMethodNameToScenarioName, DoNotAppendTemplateArgsToScenarioName, ScenarioName)
// The identity of snapshots ilustrates that execution through API and through full blown command leads to identical results
[Fact]
public async Task VerificationEngineSampleDogfoodTest()
{
string workingDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", string.Empty));
string templateShortName = "TestAssets.SampleTestTemplate";
//get the template location
string templateLocation = Path.Combine(TestTemplatesLocation, "TestTemplate");
TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName)
{
TemplateSpecificArgs = new string[] { "--paramB", "true" },
TemplatePath = templateLocation,
SnapshotsDirectory = "Snapshots",
OutputDirectory = workingDir,
VerifyCommandOutput = true,
DoNotPrependCallerMethodNameToScenarioName = true,
DoNotAppendTemplateArgsToScenarioName = true,
ScenarioName = "SampleDogfoodTest",
// This is here just for testing and documentation purposes - showing functionality of differing snapshots for arch
UniqueFor = UniqueForOption.Architecture,
}
.WithCustomScrubbers(
ScrubbersDefinition.Empty
.AddScrubber(sb => sb.Replace("B is enabled", "*******"))
.AddScrubber((path, content) =>
{
if (path.Replace(Path.DirectorySeparatorChar, '/') == "std-streams/stdout.txt")
{
content.Replace("SampleTestTemplate", "%TEMPLATE%");
}
}));
VerificationEngine engine = new VerificationEngine(_log);
await engine.Execute(options);
}
[Fact]
public async Task VerificationEngineSampleDogfoodTest_ExecThroughApi()
{
string workingDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", string.Empty));
string templateShortName = "TestAssets.SampleTestTemplate";
//get the template location
string templateLocation = Path.Combine(TestTemplatesLocation, "TestTemplate");
TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName)
{
TemplatePath = templateLocation,
SnapshotsDirectory = "Snapshots",
OutputDirectory = workingDir,
VerifyCommandOutput = true,
DoNotPrependCallerMethodNameToScenarioName = true,
ScenarioName = "SampleDogfoodTest",
UniqueFor = UniqueForOption.Architecture,
}
.WithInstantiationThroughTemplateCreatorApi(new Dictionary<string, string?>() { { "paramB", "true" } })
.WithCustomScrubbers(
ScrubbersDefinition.Empty
.AddScrubber(sb => sb.Replace("B is enabled", "*******"))
.AddScrubber((path, content) =>
{
if (path.Replace(Path.DirectorySeparatorChar, '/') == "std-streams/stdout.txt")
{
content.Replace("SampleTestTemplate", "%TEMPLATE%");
}
}));
VerificationEngine engine = new VerificationEngine(_log);
await engine.Execute(options);
}
}
}