-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.cs
91 lines (77 loc) · 3.02 KB
/
Tests.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
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
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using TestsHelper.SourceGenerator.Attributes;
using TestsHelper.SourceGenerator.Diagnostics;
using TestsHelper.SourceGenerator.MockWrapping;
using TestsHelper.SourceGenerator.SourceGeneratorImplementations;
namespace TestsHelper.SourceGenerator.Tests;
[TestFixture]
public class Tests : TestSuite<IncrementalMockFillerSourceGenerator>
{
public Tests()
{
References.AddRange(new[] {
MetadataReference.CreateFromFile(typeof(FillMocksAttribute).Assembly.Location),
MetadataReference.CreateFromFile(typeof(FillMocksWithWrappersAttribute).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Mock).Assembly.Location),
MetadataReference.CreateFromFile(typeof(ILoggerFactory).Assembly.Location),
MetadataReference.CreateFromFile(typeof(Assert).Assembly.Location),
});
IgnoredDiagnostics.Add("CS0169");
IgnoredDiagnostics.Add("CS0414");
IgnoredDiagnostics.Add("CS8019");
}
[Test]
public void OnGivenTestedClassWithFillMocksWithWrappersAttribute_GenerateWrappers()
{
// Arrange + Act
GeneratorDriverRunResult result = RunGenerator("GenerateWrappers");
// Assert
Assert.That(result.Diagnostics, Is.Empty);
}
[Test]
public void OnGivenTestedClassWithFillMocksAttribute_GenerateMocks()
{
// Arrange + Act
GeneratorDriverRunResult result = RunGenerator("GenerateMocks");
// Assert
Assert.That(result.Diagnostics, Is.Empty);
}
[Test]
public void OnTestClassNotPartial_DoNotGenerate()
{
// Arrange + Act
GeneratorDriverRunResult result = RunGenerator("TestClassNotPartial");
// Assert
Assert.That(result.Diagnostics, Is.Empty);
}
[Test]
public void OnMoreThanOneFillMocksUsage_ReportDiagnostic()
{
// Arrange + Act
GeneratorDriverRunResult result = RunGenerator("TestMoreThanOneFillMocksUsage");
// Assert
Assert.That(result.Diagnostics.Length, Is.EqualTo(1));
Assert.That(result.Diagnostics[0].Descriptor, Is.EqualTo(DiagnosticRegistry.MoreThanOneFillMockUsage));
}
[Test]
public void DefaultValue_GivenWrongTypeExistingParameter_ReportDiagnostic()
{
// Arrange + Act
GeneratorDriverRunResult result = RunGenerator("WrongTypeDefaultValue");
// Assert
Assert.That(result.Diagnostics.Length, Is.EqualTo(1));
Assert.That(result.Diagnostics[0].Descriptor, Is.EqualTo(DiagnosticRegistry.DefaultValueWithWrongType));
}
[Test]
public void DefaultValue_GivenNotExistingParameter_ReportDiagnostic()
{
// Arrange + Act
GeneratorDriverRunResult result = RunGenerator("NotExistsDefaultValue");
// Assert
Assert.That(result.Diagnostics.Length, Is.EqualTo(1));
Assert.That(result.Diagnostics[0].Descriptor, Is.EqualTo(DiagnosticRegistry.DefaultValueToUnknownParameter));
}
}