Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ file:
Include="TenJames.CompMap"
Version="latest_version"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
/>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace TenJames.CompMap.IntegrationTests;
using System;
using System.Collections.Generic;
using System.Linq;
using Mappper;
using TenJames.CompMap.Mapper;
using Xunit;

public class MappingIntegrationTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\TenJames.CompMap\TenJames.CompMap.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TenJames.CompMap.IntegrationTests;
using System.Globalization;
using System.Linq;
using Attributes;
using Mappper;
using Mapper;

/// <summary>
/// DTO for reading product data
Expand Down
76 changes: 2 additions & 74 deletions TenJames.CompMap/TenJames.CompMap.Tests/MapperGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,6 @@ namespace TenJames.CompMap.Tests;

public class MapperGeneratorTests
{
[Fact]
public void AttributeGenerator_ShouldGenerateMapFromAttribute()
{
// Arrange
var attributeGenerator = new AttributeGenerator();
var driver = CSharpGeneratorDriver.Create(attributeGenerator);
var compilation = CSharpCompilation.Create(
nameof(AttributeGenerator_ShouldGenerateMapFromAttribute),
references: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }
);

// Act
var runResult = driver.RunGenerators(compilation).GetRunResult();

// Assert
var generatedAttribute = runResult.GeneratedTrees
.FirstOrDefault(t => t.FilePath.EndsWith("MapFromAttribute.g.cs", StringComparison.Ordinal));

Assert.NotNull(generatedAttribute);
var generatedCode = generatedAttribute.GetText().ToString();
Assert.Contains("public class MapFromAttribute", generatedCode);
Assert.Contains("Type sourceType", generatedCode);
}

[Fact]
public void AttributeGenerator_ShouldGenerateMapToAttribute()
{
// Arrange
var attributeGenerator = new AttributeGenerator();
var driver = CSharpGeneratorDriver.Create(attributeGenerator);
var compilation = CSharpCompilation.Create(
nameof(AttributeGenerator_ShouldGenerateMapToAttribute),
references: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }
);

// Act
var runResult = driver.RunGenerators(compilation).GetRunResult();

// Assert
var generatedAttribute = runResult.GeneratedTrees
.FirstOrDefault(t => t.FilePath.EndsWith("MapToAttribute.g.cs", StringComparison.Ordinal));

Assert.NotNull(generatedAttribute);
var generatedCode = generatedAttribute.GetText().ToString();
Assert.Contains("public class MapToAttribute", generatedCode);
Assert.Contains("Type destinationType", generatedCode);
}

[Fact]
public void AttributeGenerator_ShouldGenerateMapperInterface()
{
// Arrange
var attributeGenerator = new AttributeGenerator();
var driver = CSharpGeneratorDriver.Create(attributeGenerator);
var compilation = CSharpCompilation.Create(
nameof(AttributeGenerator_ShouldGenerateMapperInterface),
references: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }
);

// Act
var runResult = driver.RunGenerators(compilation).GetRunResult();

// Assert
var generatedMapper = runResult.GeneratedTrees
.FirstOrDefault(t => t.FilePath.EndsWith("Mapper.g.cs", StringComparison.Ordinal));

Assert.NotNull(generatedMapper);
var generatedCode = generatedMapper.GetText().ToString();
Assert.Contains("public interface IMapper", generatedCode);
Assert.Contains("public class BaseMapper : IMapper", generatedCode);
Assert.Contains("TDestination Map<TDestination>(object source)", generatedCode);
}

[Fact]
public void MapperGenerator_ShouldRunWithoutErrors()
Expand All @@ -106,7 +34,7 @@ public partial class Target
}";

var compilation = CreateCompilation(sourceCode);
var generators = new IIncrementalGenerator[] { new AttributeGenerator(), new MapperGenerator() };
var generators = new IIncrementalGenerator[] { new MapperGenerator() };
var driver = CSharpGeneratorDriver.Create(generators);

// Act
Expand All @@ -120,7 +48,7 @@ public partial class Target
Assert.Empty(errors);

// Check that some code was generated
Assert.True(outputCompilation.SyntaxTrees.Count() > 1, "Generator should produce additional syntax trees");
Assert.True(outputCompilation.SyntaxTrees.Any(), "Generator should produce additional syntax trees");
}

private static CSharpCompilation CreateCompilation(string source)
Expand Down
6 changes: 3 additions & 3 deletions TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@
/// <summary>
/// Information about a mapping attribute.
/// </summary>
public class AttributeDefinition
internal class AttributeDefinition
{
/// <summary>
/// Name of the attribute.
/// </summary>
public string Name { get; set; }

Check warning on line 13 in TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

/// <summary>
/// Description of the attribute.
/// </summary>
public string Description { get; set; }

Check warning on line 18 in TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

/// <summary>
/// Arguments for the attribute.
/// </summary>
public IList<ArgumentDefinition> Arguments { get; set; }

Check warning on line 23 in TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable property 'Arguments' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

/// <summary>
/// Information about an argument for a mapping attribute.
/// </summary>
public class ArgumentDefinition
internal class ArgumentDefinition
{
/// <summary>
/// Name of the argument.
/// </summary>
public string Name { get; set; }

Check warning on line 34 in TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

/// <summary>
/// Type of the argument.
/// </summary>
public string Type { get; set; }

Check warning on line 39 in TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

/// <summary>
/// Default value or description of the argument.
/// </summary>
public string Value { get; set; }

Check warning on line 44 in TenJames.CompMap/TenJames.CompMap/AttributeDefinition.cs

View workflow job for this annotation

GitHub Actions / Build and Test

Non-nullable property 'Value' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

/// <summary>
/// Static class containing predefined attribute definitions.
/// </summary>
public static class AttributeDefinitions
internal static class AttributeDefinitions
{
private static readonly AttributeDefinition MapFrom = new()
{
Expand Down
238 changes: 0 additions & 238 deletions TenJames.CompMap/TenJames.CompMap/AttributeGenerator.cs

This file was deleted.

Loading