diff --git a/MapTo.sln b/MapTo.sln
index 0c203d5..fcf4ba0 100644
--- a/MapTo.sln
+++ b/MapTo.sln
@@ -2,12 +2,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapTo", "src\MapTo\MapTo.csproj", "{4DB371AC-48D0-4F01-8EF3-7707D06EF0A7}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapToTests", "test\MapTo.Tests\MapTo.Tests.csproj", "{797DA57B-AC7E-468B-8799-44C5A574C0E3}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleApp", "test\TestConsoleApp\TestConsoleApp.csproj", "{5BE2551A-9EF9-42FA-B6D1-5B5E6A90CC85}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapTo.Integration.Tests", "test\MapTo.Integration.Tests\MapTo.Integration.Tests.csproj", "{23B46FDF-6A1E-4287-88C9-C8C5D7EECB8C}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/src/MapTo/MapTo.csproj b/src/MapTo/MapTo.csproj
index 00097fc..d503876 100644
--- a/src/MapTo/MapTo.csproj
+++ b/src/MapTo/MapTo.csproj
@@ -4,7 +4,6 @@
netstandard2.0
enable
9
-
MapTo
An object to object mapping generator using Roslyn source generator.
true
@@ -36,6 +35,9 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
+
+ 3.6.65-alpha
+
diff --git a/src/MapTo/Nuget.Config b/src/MapTo/Nuget.Config
new file mode 100644
index 0000000..973a518
--- /dev/null
+++ b/src/MapTo/Nuget.Config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/test/MapTo.Integration.Tests/CyclicReferenceTests.cs b/test/MapTo.Integration.Tests/CyclicReferenceTests.cs
deleted file mode 100644
index 189d16f..0000000
--- a/test/MapTo.Integration.Tests/CyclicReferenceTests.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-using System.Linq;
-using MapTo.Integration.Tests.Data.Models;
-using MapTo.Integration.Tests.Data.ViewModels;
-using Shouldly;
-using Xunit;
-
-namespace MapTo.Integration.Tests
-{
- public class CyclicReferenceTests
- {
- [Fact]
- public void VerifySelfReference()
- {
- // Arrange
- var manager = new Manager { Id = 1, EmployeeCode = "M001", Level = 100 };
- manager.Manager = manager;
-
- // Act
- var result = manager.ToManagerViewModel();
-
- // Assert
- result.Id.ShouldBe(manager.Id);
- result.EmployeeCode.ShouldBe(manager.EmployeeCode);
- result.Level.ShouldBe(manager.Level);
- result.Manager.ShouldBeSameAs(result);
- }
-
- [Fact]
- public void VerifyNestedReference()
- {
- // Arrange
- var manager1 = new Manager { Id = 100, EmployeeCode = "M001", Level = 100 };
- var manager2 = new Manager { Id = 102, EmployeeCode = "M002", Level = 100 };
-
- var employee1 = new Employee { Id = 200, EmployeeCode = "E001"};
- var employee2 = new Employee { Id = 201, EmployeeCode = "E002"};
-
- employee1.Manager = manager1;
- employee2.Manager = manager2;
-
- manager2.Manager = manager1;
-
- // Act
- var manager1ViewModel = manager1.ToManagerViewModel();
-
- // Assert
- manager1ViewModel.Id.ShouldBe(manager1.Id);
- manager1ViewModel.Manager.ShouldBeNull();
- manager1ViewModel.Employees.Count.ShouldBe(2);
- manager1ViewModel.Employees[0].Id.ShouldBe(employee1.Id);
- manager1ViewModel.Employees[0].Manager.ShouldBeSameAs(manager1ViewModel);
- manager1ViewModel.Employees[1].Id.ShouldBe(manager2.Id);
- manager1ViewModel.Employees[1].Manager.ShouldBeSameAs(manager1ViewModel);
- }
-
- [Fact]
- public void VerifyNestedSelfReference()
- {
- // Arrange
- var manager1 = new Manager { Id = 100, EmployeeCode = "M001", Level = 100 };
- var manager3 = new Manager { Id = 101, EmployeeCode = "M003", Level = 100 };
- var manager2 = new Manager { Id = 102, EmployeeCode = "M002", Level = 100 };
-
- var employee1 = new Employee { Id = 200, EmployeeCode = "E001"};
- var employee2 = new Employee { Id = 201, EmployeeCode = "E002"};
- var employee3 = new Employee { Id = 202, EmployeeCode = "E003"};
-
- employee1.Manager = manager1;
- employee2.Manager = manager2;
- employee3.Manager = manager3;
-
- manager2.Manager = manager1;
- manager3.Manager = manager2;
-
- // Act
- var manager3ViewModel = manager3.ToManagerViewModel();
-
- // Assert
- manager3ViewModel.Manager.ShouldNotBeNull();
- manager3ViewModel.Manager.Id.ShouldBe(manager2.Id);
- manager3ViewModel.Manager.Manager.Id.ShouldBe(manager1.Id);
- manager3ViewModel.Employees.All(e => ReferenceEquals(e.Manager, manager3ViewModel)).ShouldBeTrue();
- }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Integration.Tests/Data/Models/Employee.cs b/test/MapTo.Integration.Tests/Data/Models/Employee.cs
deleted file mode 100644
index 2944fc5..0000000
--- a/test/MapTo.Integration.Tests/Data/Models/Employee.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-namespace MapTo.Integration.Tests.Data.Models
-{
- public class Employee
- {
- private Manager _manager;
-
- public int Id { get; set; }
-
- public string EmployeeCode { get; set; }
-
- public Manager Manager
- {
- get => _manager;
- set
- {
- if (value == null)
- {
- _manager.Employees.Remove(this);
- }
- else
- {
- value.Employees.Add(this);
- }
-
- _manager = value;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Integration.Tests/Data/Models/Manager.cs b/test/MapTo.Integration.Tests/Data/Models/Manager.cs
deleted file mode 100644
index ffafe25..0000000
--- a/test/MapTo.Integration.Tests/Data/Models/Manager.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using System.Collections.Generic;
-
-namespace MapTo.Integration.Tests.Data.Models
-{
- public class Manager : Employee
- {
- public int Level { get; set; }
-
- public List Employees { get; set; } = new();
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Integration.Tests/Data/ViewModels/EmployeeViewModel.cs b/test/MapTo.Integration.Tests/Data/ViewModels/EmployeeViewModel.cs
deleted file mode 100644
index 8ebaf88..0000000
--- a/test/MapTo.Integration.Tests/Data/ViewModels/EmployeeViewModel.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using MapTo.Integration.Tests.Data.Models;
-
-namespace MapTo.Integration.Tests.Data.ViewModels
-{
- [MapFrom(typeof(Employee))]
- public partial class EmployeeViewModel
- {
- public int Id { get; set; }
-
- public string EmployeeCode { get; set; }
-
- public ManagerViewModel Manager { get; set; }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Integration.Tests/Data/ViewModels/ManagerViewModel.cs b/test/MapTo.Integration.Tests/Data/ViewModels/ManagerViewModel.cs
deleted file mode 100644
index d085c24..0000000
--- a/test/MapTo.Integration.Tests/Data/ViewModels/ManagerViewModel.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using System.Collections.Generic;
-using MapTo.Integration.Tests.Data.Models;
-
-namespace MapTo.Integration.Tests.Data.ViewModels
-{
- [MapFrom(typeof(Manager))]
- public partial class ManagerViewModel : EmployeeViewModel
- {
- public int Level { get; set; }
-
- public List Employees { get; set; } = new();
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Integration.Tests/MapTo.Integration.Tests.csproj b/test/MapTo.Integration.Tests/MapTo.Integration.Tests.csproj
deleted file mode 100644
index f928846..0000000
--- a/test/MapTo.Integration.Tests/MapTo.Integration.Tests.csproj
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
- net5.0
- false
-
-
-
-
-
-
-
-
-
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
- runtime; build; native; contentfiles; analyzers; buildtransitive
- all
-
-
-
-
diff --git a/test/MapTo.Tests/Common.cs b/test/MapTo.Tests/Common.cs
deleted file mode 100644
index f9113c9..0000000
--- a/test/MapTo.Tests/Common.cs
+++ /dev/null
@@ -1,252 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using MapTo.Extensions;
-using MapTo.Sources;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Shouldly;
-
-namespace MapTo.Tests
-{
- internal static class Common
- {
- internal const int Indent1 = 4;
- internal const int Indent2 = Indent1 * 2;
- internal const int Indent3 = Indent1 * 3;
- internal static readonly Location IgnoreLocation = Location.None;
-
- internal static readonly Dictionary DefaultAnalyzerOptions = new()
- {
- [GeneratorExecutionContextExtensions.GetBuildPropertyName(nameof(SourceGenerationOptions.GenerateXmlDocument))] = "false"
- };
-
- internal static string GetSourceText(SourceGeneratorOptions? options = null)
- {
- const string ns = "Test";
- options ??= new SourceGeneratorOptions();
- var hasDifferentSourceNamespace = options.SourceClassNamespace != ns;
- var builder = new SourceBuilder();
-
- builder.WriteLine("//");
- builder.WriteLine("// Test source code.");
- builder.WriteLine("//");
- builder.WriteLine();
-
- options.Usings?.ForEach(s => builder.WriteLine($"using {s};"));
-
- if (options.UseMapToNamespace)
- {
- builder.WriteLine($"using {Constants.RootNamespace};");
- }
-
- builder
- .WriteLine($"using {options.SourceClassNamespace};")
- .WriteLine()
- .WriteLine();
-
- builder
- .WriteLine($"namespace {ns}")
- .WriteOpeningBracket();
-
- if (hasDifferentSourceNamespace && options.UseMapToNamespace)
- {
- builder
- .WriteLine($"using {options.SourceClassNamespace};")
- .WriteLine()
- .WriteLine();
- }
-
- builder
- .WriteLine(options.UseMapToNamespace ? "[MapFrom(typeof(Baz))]" : "[MapTo.MapFrom(typeof(Baz))]")
- .WriteLine("public partial class Foo")
- .WriteOpeningBracket();
-
- for (var i = 1; i <= options.ClassPropertiesCount; i++)
- {
- builder.WriteLine(i % 2 == 0 ? $"public int Prop{i} {{ get; set; }}" : $"public int Prop{i} {{ get; }}");
- }
-
- options.PropertyBuilder?.Invoke(builder);
-
- builder
- .WriteClosingBracket()
- .WriteClosingBracket()
- .WriteLine()
- .WriteLine();
-
- builder
- .WriteLine($"namespace {options.SourceClassNamespace}")
- .WriteOpeningBracket()
- .WriteLine("public class Baz")
- .WriteOpeningBracket();
-
- for (var i = 1; i <= options.SourceClassPropertiesCount; i++)
- {
- builder.WriteLine(i % 2 == 0 ? $"public int Prop{i} {{ get; set; }}" : $"public int Prop{i} {{ get; }}");
- }
-
- options.SourcePropertyBuilder?.Invoke(builder);
-
- builder
- .WriteClosingBracket()
- .WriteClosingBracket();
-
- return builder.ToString();
- }
-
- internal static string[] GetEmployeeManagerSourceText(
- Func? employeeClassSource = null,
- Func? managerClassSource = null,
- Func? employeeViewModelSource = null,
- Func? managerViewModelSource = null,
- bool useDifferentViewModelNamespace = false)
- {
- return new[]
- {
- employeeClassSource?.Invoke() ?? DefaultEmployeeClassSource(),
- managerClassSource?.Invoke() ?? DefaultManagerClassSource(),
- employeeViewModelSource?.Invoke() ??
- DefaultEmployeeViewModelSource(useDifferentViewModelNamespace),
- managerViewModelSource?.Invoke() ?? DefaultManagerViewModelSource(useDifferentViewModelNamespace)
- };
-
- static string DefaultEmployeeClassSource() =>
- @"
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Test.Data.Models
-{
- public class Employee
- {
- public int Id { get; set; }
-
- public string EmployeeCode { get; set; }
-
- public Manager Manager { get; set; }
- }
-}".Trim();
-
- static string DefaultManagerClassSource() =>
- @"using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Test.Data.Models
-{
- public class Manager: Employee
- {
- public int Level { get; set; }
-
- public IEnumerable Employees { get; set; } = Array.Empty();
- }
-}
-".Trim();
-
- static string DefaultEmployeeViewModelSource(bool useDifferentNamespace) => useDifferentNamespace
- ? @"
-using MapTo;
-using Test.Data.Models;
-using Test.ViewModels2;
-
-namespace Test.ViewModels
-{
- [MapFrom(typeof(Employee))]
- public partial class EmployeeViewModel
- {
- public int Id { get; set; }
-
- public string EmployeeCode { get; set; }
-
- public ManagerViewModel Manager { get; set; }
- }
-}
-".Trim()
- : @"
-using MapTo;
-using Test.Data.Models;
-
-namespace Test.ViewModels
-{
- [MapFrom(typeof(Employee))]
- public partial class EmployeeViewModel
- {
- public int Id { get; set; }
-
- public string EmployeeCode { get; set; }
-
- public ManagerViewModel Manager { get; set; }
- }
-}
-".Trim();
-
- static string DefaultManagerViewModelSource(bool useDifferentNamespace) => useDifferentNamespace
- ? @"
-using System;
-using System.Collections.Generic;
-using MapTo;
-using Test.Data.Models;
-using Test.ViewModels;
-
-namespace Test.ViewModels2
-{
- [MapFrom(typeof(Manager))]
- public partial class ManagerViewModel : EmployeeViewModel
- {
- public int Level { get; set; }
-
- public IEnumerable Employees { get; set; } = Array.Empty();
- }
-}
-".Trim()
- : @"
-using System;
-using System.Collections.Generic;
-using MapTo;
-using Test.Data.Models;
-
-namespace Test.ViewModels
-{
- [MapFrom(typeof(Manager))]
- public partial class ManagerViewModel : EmployeeViewModel
- {
- public int Level { get; set; }
-
- public IEnumerable Employees { get; set; } = Array.Empty();
- }
-}".Trim();
- }
-
- internal static PropertyDeclarationSyntax GetPropertyDeclarationSyntax(SyntaxTree syntaxTree, string targetPropertyName, string targetClass = "Foo")
- {
- return syntaxTree.GetRoot()
- .DescendantNodes()
- .OfType()
- .Single(c => c.Identifier.ValueText == targetClass)
- .DescendantNodes()
- .OfType()
- .Single(p => p.Identifier.ValueText == targetPropertyName);
- }
-
- internal static IPropertySymbol GetSourcePropertySymbol(string propertyName, Compilation compilation, string targetClass = "Foo")
- {
- var syntaxTree = compilation.SyntaxTrees.First();
- var propSyntax = GetPropertyDeclarationSyntax(syntaxTree, propertyName, targetClass);
-
- var semanticModel = compilation.GetSemanticModel(syntaxTree);
- return semanticModel.GetDeclaredSymbol(propSyntax).ShouldNotBeNull();
- }
-
- internal record SourceGeneratorOptions(
- bool UseMapToNamespace = false,
- string SourceClassNamespace = "Test.Models",
- int ClassPropertiesCount = 3,
- int SourceClassPropertiesCount = 3,
- Action? PropertyBuilder = null,
- Action? SourcePropertyBuilder = null,
- IEnumerable? Usings = null);
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/CompilerServices/IsExternalInit.cs b/test/MapTo.Tests/CompilerServices/IsExternalInit.cs
deleted file mode 100644
index e750e2f..0000000
--- a/test/MapTo.Tests/CompilerServices/IsExternalInit.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-// ReSharper disable UnusedType.Global
-// ReSharper disable CheckNamespace
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.ComponentModel;
-
-namespace System.Runtime.CompilerServices
-{
- ///
- /// Reserved to be used by the compiler for tracking metadata.
- /// This class should not be used by developers in source code.
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal static class IsExternalInit { }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/Extensions/RoslynExtensions.cs b/test/MapTo.Tests/Extensions/RoslynExtensions.cs
deleted file mode 100644
index ea3394e..0000000
--- a/test/MapTo.Tests/Extensions/RoslynExtensions.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-using System.Linq;
-using System.Text;
-using Microsoft.CodeAnalysis;
-
-namespace MapTo.Tests.Extensions
-{
- internal static class RoslynExtensions
- {
- internal static SyntaxTree? GetGeneratedSyntaxTree(this Compilation compilation, string className) =>
- compilation.SyntaxTrees.SingleOrDefault(s => s.FilePath.EndsWith($"{className}.g.cs"));
-
- internal static string PrintSyntaxTree(this Compilation compilation)
- {
- var builder = new StringBuilder();
-
- return string.Join(
- Environment.NewLine,
- compilation.SyntaxTrees
- .Reverse()
- .Select((s, i) =>
- {
- builder
- .Clear()
- .AppendLine("----------------------------------------")
- .AppendFormat("File Path: \"{0}\"", s.FilePath).AppendLine()
- .AppendFormat("Index: \"{0}\"", i).AppendLine()
- .AppendLine();
-
- var lines = s.ToString().Split(Environment.NewLine);
- var lineNumber = 0;
- foreach (var line in lines)
- {
- builder.AppendFormat("{0:00}: {1}", lineNumber, line).AppendLine();
- lineNumber++;
- }
-
- return builder.ToString();
- }));
- }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs b/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs
deleted file mode 100644
index 1ad43d4..0000000
--- a/test/MapTo.Tests/Extensions/ShouldlyExtensions.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Linq;
-using System.Text;
-using Microsoft.CodeAnalysis;
-using Shouldly;
-using Xunit;
-
-namespace MapTo.Tests.Extensions
-{
- internal static class ShouldlyExtensions
- {
- internal static void ShouldContainSource(this IEnumerable syntaxTree, string typeName, string expectedSource, string? customMessage = null)
- {
- var syntax = syntaxTree
- .Select(s => s.ToString().Trim())
- .SingleOrDefault(s => s.Contains(typeName));
-
- syntax.ShouldNotBeNullOrWhiteSpace();
- syntax.ShouldBe(expectedSource, customMessage);
- }
-
- internal static void ShouldContainPartialSource(this IEnumerable syntaxTree, string typeName, string expectedSource, string? customMessage = null)
- {
- var syntax = syntaxTree
- .Select(s => s.ToString().Trim())
- .SingleOrDefault(s => s.Contains(typeName));
-
- syntax.ShouldNotBeNullOrWhiteSpace();
- syntax.ShouldContainWithoutWhitespace(expectedSource, customMessage);
- }
-
- internal static void ShouldContainPartialSource(this SyntaxTree syntaxTree, string expectedSource, string? customMessage = null)
- {
- var syntax = syntaxTree.ToString();
- syntax.ShouldNotBeNullOrWhiteSpace();
- syntax.ShouldContainWithoutWhitespace(expectedSource, customMessage);
- }
-
- internal static void ShouldBeSuccessful(this IEnumerable diagnostics, Compilation? compilation = null, IEnumerable? ignoreDiagnosticsIds = null)
- {
- var actual = diagnostics
- .Where(d => (ignoreDiagnosticsIds is null || ignoreDiagnosticsIds.All(i => !d.Id.StartsWith(i) )) && (d.Severity is DiagnosticSeverity.Warning or DiagnosticSeverity.Error))
- .Select(c => $"{c.Severity}: {c.Location.GetLineSpan()} - {c.GetMessage()}").ToArray();
-
- if (!actual.Any())
- {
- return;
- }
-
- var builder = new StringBuilder();
- builder.AppendLine("Failed");
-
- foreach (var d in actual)
- {
- builder.AppendFormat("- {0}", d).AppendLine();
- }
-
- if (compilation is not null)
- {
- builder.AppendLine("Generated Sources:");
- builder.AppendLine(compilation.PrintSyntaxTree());
- }
-
- Assert.False(true, builder.ToString());
- }
-
- internal static void ShouldNotBeSuccessful(this ImmutableArray diagnostics, Diagnostic expectedError)
- {
- var actualDiagnostics = diagnostics.SingleOrDefault(d => d.Id == expectedError.Id);
- var compilationDiagnostics = actualDiagnostics == null ? diagnostics : diagnostics.Except(new[] { actualDiagnostics });
-
- compilationDiagnostics.ShouldBeSuccessful();
-
- Assert.NotNull(actualDiagnostics);
- Assert.Equal(expectedError.Id, actualDiagnostics?.Id);
- Assert.Equal(expectedError.Descriptor.Id, actualDiagnostics?.Descriptor.Id);
- Assert.Equal(expectedError.Descriptor.Description, actualDiagnostics?.Descriptor.Description);
- Assert.Equal(expectedError.Descriptor.Title, actualDiagnostics?.Descriptor.Title);
-
- if (expectedError.Location != Location.None)
- {
- Assert.Equal(expectedError.Location, actualDiagnostics?.Location);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/IgnorePropertyAttributeTests.cs b/test/MapTo.Tests/IgnorePropertyAttributeTests.cs
deleted file mode 100644
index a1dddb6..0000000
--- a/test/MapTo.Tests/IgnorePropertyAttributeTests.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System.Linq;
-using MapTo.Extensions;
-using MapTo.Sources;
-using MapTo.Tests.Extensions;
-using MapTo.Tests.Infrastructure;
-using Shouldly;
-using Xunit;
-using static MapTo.Tests.Common;
-
-namespace MapTo.Tests
-{
- public class IgnorePropertyAttributeTests
- {
- [Fact]
- public void VerifyIgnorePropertyAttribute()
- {
- // Arrange
- const string source = "";
- var expectedAttribute = $@"
-{Constants.GeneratedFilesHeader}
-using System;
-
-namespace MapTo
-{{
- [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
- public sealed class IgnorePropertyAttribute : Attribute {{ }}
-}}
-".Trim();
-
- // Act
- var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source, analyzerConfigOptions: DefaultAnalyzerOptions);
-
- // Assert
- diagnostics.ShouldBeSuccessful();
- compilation.SyntaxTrees.ShouldContainSource(IgnorePropertyAttributeSource.AttributeName, expectedAttribute);
- }
-
- [Fact]
- public void When_IgnorePropertyAttributeIsSpecified_Should_NotGenerateMappingsForThatProperty()
- {
- // Arrange
- var source = GetSourceText(new SourceGeneratorOptions(
- true,
- PropertyBuilder: builder =>
- {
- builder
- .WriteLine("[IgnoreProperty]")
- .WriteLine("public int Prop4 { get; set; }");
- },
- SourcePropertyBuilder: builder => builder.WriteLine("public int Prop4 { get; set; }")));
-
- var expectedResult = @"
- partial class Foo
- {
- public Foo(Test.Models.Baz baz)
- : this(new MappingContext(), baz) { }
-
- private protected Foo(MappingContext context, Test.Models.Baz baz)
- {
- if (context == null) throw new ArgumentNullException(nameof(context));
- if (baz == null) throw new ArgumentNullException(nameof(baz));
-
- context.Register(baz, this);
-
- Prop1 = baz.Prop1;
- Prop2 = baz.Prop2;
- Prop3 = baz.Prop3;
- }
-".Trim();
-
- // Act
- var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source, analyzerConfigOptions: DefaultAnalyzerOptions);
-
- // Assert
- diagnostics.ShouldBeSuccessful();
- compilation.SyntaxTrees.Last().ShouldContainPartialSource(expectedResult);
- }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/Infrastructure/CSharpGenerator.cs b/test/MapTo.Tests/Infrastructure/CSharpGenerator.cs
deleted file mode 100644
index da1ec81..0000000
--- a/test/MapTo.Tests/Infrastructure/CSharpGenerator.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Linq;
-using MapTo.Tests.Extensions;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-
-namespace MapTo.Tests.Infrastructure
-{
- internal static class CSharpGenerator
- {
- internal static (Compilation compilation, ImmutableArray diagnostics) GetOutputCompilation(
- string source,
- bool assertCompilation = false,
- IDictionary? analyzerConfigOptions = null,
- NullableContextOptions nullableContextOptions = NullableContextOptions.Disable,
- LanguageVersion languageVersion = LanguageVersion.CSharp7_3) =>
- GetOutputCompilation(
- new[] { source },
- assertCompilation,
- analyzerConfigOptions,
- nullableContextOptions,
- languageVersion);
-
- internal static (Compilation compilation, ImmutableArray diagnostics) GetOutputCompilation(
- IEnumerable sources,
- bool assertCompilation = false,
- IDictionary? analyzerConfigOptions = null,
- NullableContextOptions nullableContextOptions = NullableContextOptions.Disable,
- LanguageVersion languageVersion = LanguageVersion.CSharp7_3)
- {
- var references = AppDomain.CurrentDomain.GetAssemblies()
- .Where(a => !a.IsDynamic && !string.IsNullOrWhiteSpace(a.Location))
- .Select(a => MetadataReference.CreateFromFile(a.Location))
- .ToList();
-
- var compilation = CSharpCompilation.Create(
- $"{typeof(CSharpGenerator).Assembly.GetName().Name}.Dynamic",
- sources.Select((source, index) => CSharpSyntaxTree.ParseText(source, path: $"Test{index:00}.g.cs", options: new CSharpParseOptions(languageVersion))),
- references,
- new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, nullableContextOptions: nullableContextOptions));
-
- if (assertCompilation)
- {
- // NB: fail tests when the injected program isn't valid _before_ running generators
- compilation.GetDiagnostics().ShouldBeSuccessful();
- }
-
- var driver = CSharpGeneratorDriver.Create(
- new[] { new MapToGenerator() },
- optionsProvider: new TestAnalyzerConfigOptionsProvider(analyzerConfigOptions),
- parseOptions: new CSharpParseOptions(languageVersion)
- );
-
- driver.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out var generateDiagnostics);
-
- generateDiagnostics.ShouldBeSuccessful(ignoreDiagnosticsIds: new[] { "MT" });
- outputCompilation.GetDiagnostics().ShouldBeSuccessful(outputCompilation);
-
- return (outputCompilation, generateDiagnostics);
- }
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/Infrastructure/TestAnalyzerConfigOptions.cs b/test/MapTo.Tests/Infrastructure/TestAnalyzerConfigOptions.cs
deleted file mode 100644
index 462d71d..0000000
--- a/test/MapTo.Tests/Infrastructure/TestAnalyzerConfigOptions.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Diagnostics.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-
-namespace MapTo.Tests.Infrastructure
-{
- internal sealed class TestAnalyzerConfigOptions : AnalyzerConfigOptions
- {
- private readonly ImmutableDictionary _backing;
-
- public TestAnalyzerConfigOptions(IDictionary? properties)
- {
- _backing = properties?.ToImmutableDictionary(KeyComparer) ?? ImmutableDictionary.Create(KeyComparer);
- }
-
- public override bool TryGetValue(string key, out string? value) => _backing.TryGetValue(key, out value);
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/Infrastructure/TestAnalyzerConfigOptionsProvider.cs b/test/MapTo.Tests/Infrastructure/TestAnalyzerConfigOptionsProvider.cs
deleted file mode 100644
index 914901d..0000000
--- a/test/MapTo.Tests/Infrastructure/TestAnalyzerConfigOptionsProvider.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-
-namespace MapTo.Tests.Infrastructure
-{
- internal sealed class TestAnalyzerConfigOptionsProvider : AnalyzerConfigOptionsProvider
- {
- public TestAnalyzerConfigOptionsProvider(IDictionary? options)
- {
- GlobalOptions = new TestAnalyzerConfigOptions(options);
- }
-
- ///
- public override AnalyzerConfigOptions GlobalOptions { get; }
-
- ///
- public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) => throw new NotImplementedException();
-
- ///
- public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) => throw new NotImplementedException();
- }
-}
\ No newline at end of file
diff --git a/test/MapTo.Tests/MapPropertyTests.cs b/test/MapTo.Tests/MapPropertyTests.cs
deleted file mode 100644
index 54af284..0000000
--- a/test/MapTo.Tests/MapPropertyTests.cs
+++ /dev/null
@@ -1,202 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using MapTo.Sources;
-using MapTo.Tests.Extensions;
-using MapTo.Tests.Infrastructure;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Xunit;
-using static MapTo.Tests.Common;
-
-namespace MapTo.Tests
-{
- public class MapPropertyTests
- {
- [Theory]
- [InlineData(NullableContextOptions.Disable)]
- [InlineData(NullableContextOptions.Enable)]
- public void VerifyMapPropertyAttribute(NullableContextOptions nullableContextOptions)
- {
- // Arrange
- const string source = "";
- var nullableSyntax = nullableContextOptions == NullableContextOptions.Enable ? "?" : string.Empty;
- var languageVersion = nullableContextOptions == NullableContextOptions.Enable ? LanguageVersion.CSharp8 : LanguageVersion.CSharp7_3;
- var expectedInterface = $@"
-{Constants.GeneratedFilesHeader}
-{(nullableContextOptions == NullableContextOptions.Enable ? $"#nullable enable{Environment.NewLine}" : string.Empty)}
-using System;
-
-namespace MapTo
-{{
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = true)]
- public sealed class MapPropertyAttribute : Attribute
- {{
- public string{nullableSyntax} SourcePropertyName {{ get; set; }}
- }}
-}}
-".Trim();
-
- // Act
- var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source, analyzerConfigOptions: DefaultAnalyzerOptions, nullableContextOptions: nullableContextOptions, languageVersion: languageVersion);
-
-
- // Assert
- diagnostics.ShouldBeSuccessful();
- compilation.SyntaxTrees.ShouldContainSource(MapPropertyAttributeSource.AttributeName, expectedInterface);
- }
-
- [Fact]
- public void When_MapPropertyFound_Should_UseItToMapToSourceProperty()
- {
- // Arrange
- var source = GetSourceText(new SourceGeneratorOptions(
- true,
- PropertyBuilder: builder =>
- {
- builder
- .WriteLine("[MapProperty(SourcePropertyName = nameof(Baz.Prop3))]")
- .WriteLine("public int Prop4 { get; set; }");
- },
- SourcePropertyBuilder: builder => builder.WriteLine("public int Prop4 { get; set; }")));
-
- var expectedResult = @"
- partial class Foo
- {
- public Foo(Test.Models.Baz baz)
- : this(new MappingContext(), baz) { }
-
- private protected Foo(MappingContext context, Test.Models.Baz baz)
- {
- if (context == null) throw new ArgumentNullException(nameof(context));
- if (baz == null) throw new ArgumentNullException(nameof(baz));
-
- context.Register(baz, this);
-
- Prop1 = baz.Prop1;
- Prop2 = baz.Prop2;
- Prop3 = baz.Prop3;
- Prop4 = baz.Prop3;
- }
-".Trim();
-
- // Act
- var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source, analyzerConfigOptions: DefaultAnalyzerOptions);
-
- // Assert
- diagnostics.ShouldBeSuccessful();
- compilation.SyntaxTrees.Last().ShouldContainPartialSource(expectedResult);
- }
-
- [Theory]
- [MemberData(nameof(MapPropertyWithImplicitConversionFoundData))]
- public void When_MapPropertyWithImplicitConversionFound_Should_UseItToMapToSourceProperty(string source, string expectedResult, LanguageVersion languageVersion)
- {
- // Arrange
- source = source.Trim();
-
- // Act
- var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source, analyzerConfigOptions: DefaultAnalyzerOptions, languageVersion: languageVersion);
-
- // Assert
- diagnostics.ShouldBeSuccessful();
- compilation.SyntaxTrees.Last().ShouldContainPartialSource(expectedResult);
- }
-
- public static IEnumerable