@@ -9,78 +9,6 @@ namespace TenJames.CompMap.Tests;
99
1010public class MapperGeneratorTests
1111{
12- [ Fact ]
13- public void AttributeGenerator_ShouldGenerateMapFromAttribute ( )
14- {
15- // Arrange
16- var attributeGenerator = new AttributeGenerator ( ) ;
17- var driver = CSharpGeneratorDriver . Create ( attributeGenerator ) ;
18- var compilation = CSharpCompilation . Create (
19- nameof ( AttributeGenerator_ShouldGenerateMapFromAttribute ) ,
20- references : new [ ] { MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) }
21- ) ;
22-
23- // Act
24- var runResult = driver . RunGenerators ( compilation ) . GetRunResult ( ) ;
25-
26- // Assert
27- var generatedAttribute = runResult . GeneratedTrees
28- . FirstOrDefault ( t => t . FilePath . EndsWith ( "MapFromAttribute.g.cs" , StringComparison . Ordinal ) ) ;
29-
30- Assert . NotNull ( generatedAttribute ) ;
31- var generatedCode = generatedAttribute . GetText ( ) . ToString ( ) ;
32- Assert . Contains ( "public class MapFromAttribute" , generatedCode ) ;
33- Assert . Contains ( "Type sourceType" , generatedCode ) ;
34- }
35-
36- [ Fact ]
37- public void AttributeGenerator_ShouldGenerateMapToAttribute ( )
38- {
39- // Arrange
40- var attributeGenerator = new AttributeGenerator ( ) ;
41- var driver = CSharpGeneratorDriver . Create ( attributeGenerator ) ;
42- var compilation = CSharpCompilation . Create (
43- nameof ( AttributeGenerator_ShouldGenerateMapToAttribute ) ,
44- references : new [ ] { MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) }
45- ) ;
46-
47- // Act
48- var runResult = driver . RunGenerators ( compilation ) . GetRunResult ( ) ;
49-
50- // Assert
51- var generatedAttribute = runResult . GeneratedTrees
52- . FirstOrDefault ( t => t . FilePath . EndsWith ( "MapToAttribute.g.cs" , StringComparison . Ordinal ) ) ;
53-
54- Assert . NotNull ( generatedAttribute ) ;
55- var generatedCode = generatedAttribute . GetText ( ) . ToString ( ) ;
56- Assert . Contains ( "public class MapToAttribute" , generatedCode ) ;
57- Assert . Contains ( "Type destinationType" , generatedCode ) ;
58- }
59-
60- [ Fact ]
61- public void AttributeGenerator_ShouldGenerateMapperInterface ( )
62- {
63- // Arrange
64- var attributeGenerator = new AttributeGenerator ( ) ;
65- var driver = CSharpGeneratorDriver . Create ( attributeGenerator ) ;
66- var compilation = CSharpCompilation . Create (
67- nameof ( AttributeGenerator_ShouldGenerateMapperInterface ) ,
68- references : new [ ] { MetadataReference . CreateFromFile ( typeof ( object ) . Assembly . Location ) }
69- ) ;
70-
71- // Act
72- var runResult = driver . RunGenerators ( compilation ) . GetRunResult ( ) ;
73-
74- // Assert
75- var generatedMapper = runResult . GeneratedTrees
76- . FirstOrDefault ( t => t . FilePath . EndsWith ( "Mapper.g.cs" , StringComparison . Ordinal ) ) ;
77-
78- Assert . NotNull ( generatedMapper ) ;
79- var generatedCode = generatedMapper . GetText ( ) . ToString ( ) ;
80- Assert . Contains ( "public interface IMapper" , generatedCode ) ;
81- Assert . Contains ( "public class BaseMapper : IMapper" , generatedCode ) ;
82- Assert . Contains ( "TDestination Map<TDestination>(object source)" , generatedCode ) ;
83- }
8412
8513 [ Fact ]
8614 public void MapperGenerator_ShouldRunWithoutErrors ( )
@@ -106,7 +34,7 @@ public partial class Target
10634}" ;
10735
10836 var compilation = CreateCompilation ( sourceCode ) ;
109- var generators = new IIncrementalGenerator [ ] { new AttributeGenerator ( ) , new MapperGenerator ( ) } ;
37+ var generators = new IIncrementalGenerator [ ] { new MapperGenerator ( ) } ;
11038 var driver = CSharpGeneratorDriver . Create ( generators ) ;
11139
11240 // Act
@@ -120,7 +48,7 @@ public partial class Target
12048 Assert . Empty ( errors ) ;
12149
12250 // Check that some code was generated
123- Assert . True ( outputCompilation . SyntaxTrees . Count ( ) > 1 , "Generator should produce additional syntax trees" ) ;
51+ Assert . True ( outputCompilation . SyntaxTrees . Any ( ) , "Generator should produce additional syntax trees" ) ;
12452 }
12553
12654 private static CSharpCompilation CreateCompilation ( string source )
0 commit comments