-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTest1.cs
More file actions
51 lines (41 loc) · 1.47 KB
/
Copy pathUnitTest1.cs
File metadata and controls
51 lines (41 loc) · 1.47 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
using MattSourceGenHelpers.Abstractions;
namespace MattSourceGenHelpers.Tests;
public class Tests
{
[Test]
public void ColorsClassLikeGenerator_ProducesExpectedRuntimeOutput()
{
TestColorsClass testColorsClass = new TestColorsClass();
string allColors = testColorsClass.GetAllColorsString();
Assert.That(allColors, Is.EqualTo("Red, Green, Blue"));
}
[Test]
public void ColorsClassLikeGenerator_ProducesExpectedGeneratedCode()
{
string generatedCode = GeneratedCodeTestHelper.ReadGeneratedCode("TestColorsClass_GetAllColorsString.g.cs");
string expectedCode = """
namespace MattSourceGenHelpers.Tests;
partial class TestColorsClass
{
public partial string GetAllColorsString()
{
return "Red, Green, Blue";
}
}
""".ReplaceLineEndings("\n").TrimEnd();
Assert.That(generatedCode, Is.EqualTo(expectedCode));
}
}
public enum TestColorsEnum
{
Red,
Green,
Blue
}
public partial class TestColorsClass
{
public partial string GetAllColorsString();
[GeneratesMethod(nameof(GetAllColorsString))]
private static string GetAllColorsString_Generator() =>
string.Join(", ", Enum.GetNames<TestColorsEnum>());
}