Skip to content

Commit dea8504

Browse files
authored
removed attribute generator insted (#13)
Co-authored-by: James <jkbindrak@gmail.com>
1 parent 83b9094 commit dea8504

19 files changed

Lines changed: 59 additions & 333 deletions

Readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ file:
105105
Include="TenJames.CompMap"
106106
Version="latest_version"
107107
OutputItemType="Analyzer"
108-
ReferenceOutputAssembly="false"
109108
/>
110109
```
111110

TenJames.CompMap/TenJames.CompMap.IntegrationTests/MappingIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace TenJames.CompMap.IntegrationTests;
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6-
using Mappper;
6+
using TenJames.CompMap.Mapper;
77
using Xunit;
88

99
public class MappingIntegrationTests

TenJames.CompMap/TenJames.CompMap.IntegrationTests/TenJames.CompMap.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<ItemGroup>
2222
<ProjectReference Include="..\TenJames.CompMap\TenJames.CompMap.csproj"
2323
OutputItemType="Analyzer"
24-
ReferenceOutputAssembly="false"/>
24+
/>
2525
</ItemGroup>
2626

2727
</Project>

TenJames.CompMap/TenJames.CompMap.IntegrationTests/TestDtos.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace TenJames.CompMap.IntegrationTests;
55
using System.Globalization;
66
using System.Linq;
77
using Attributes;
8-
using Mappper;
8+
using Mapper;
99

1010
/// <summary>
1111
/// DTO for reading product data

TenJames.CompMap/TenJames.CompMap.Tests/MapperGeneratorTests.cs

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,6 @@ namespace TenJames.CompMap.Tests;
99

1010
public 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)

TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace TenJames.CompMap;
55
/// <summary>
66
/// Information about a mapping attribute.
77
/// </summary>
8-
public class AttributeDefinition
8+
internal class AttributeDefinition
99
{
1010
/// <summary>
1111
/// Name of the attribute.
@@ -26,7 +26,7 @@ public class AttributeDefinition
2626
/// <summary>
2727
/// Information about an argument for a mapping attribute.
2828
/// </summary>
29-
public class ArgumentDefinition
29+
internal class ArgumentDefinition
3030
{
3131
/// <summary>
3232
/// Name of the argument.
@@ -47,7 +47,7 @@ public class ArgumentDefinition
4747
/// <summary>
4848
/// Static class containing predefined attribute definitions.
4949
/// </summary>
50-
public static class AttributeDefinitions
50+
internal static class AttributeDefinitions
5151
{
5252
private static readonly AttributeDefinition MapFrom = new()
5353
{

TenJames.CompMap/TenJames.CompMap/AttributeGenerator.cs

Lines changed: 0 additions & 238 deletions
This file was deleted.

0 commit comments

Comments
 (0)