diff --git a/src/MapTo/Sources/MapClassSource.cs b/src/MapTo/Sources/MapClassSource.cs
index 58ed9a1..b76b213 100644
--- a/src/MapTo/Sources/MapClassSource.cs
+++ b/src/MapTo/Sources/MapClassSource.cs
@@ -10,13 +10,12 @@ namespace MapTo.Sources
using var builder = new SourceBuilder()
.WriteLine(GeneratedFilesHeader)
.WriteNullableContextOptionIf(model.Options.SupportNullableReferenceTypes)
- .WriteLine()
- .WriteUsings(model.Usings)
- .WriteLine()
// Namespace declaration
.WriteLine($"namespace {model.Namespace}")
.WriteOpeningBracket()
+ .WriteUsings(model.Usings)
+ .WriteLine()
// Class declaration
.WriteLine($"partial class {model.ClassName}")
diff --git a/test/MapTo.Tests/MapToTests.cs b/test/MapTo.Tests/MapToTests.cs
index b3d39f5..c5e3d2f 100644
--- a/test/MapTo.Tests/MapToTests.cs
+++ b/test/MapTo.Tests/MapToTests.cs
@@ -122,12 +122,11 @@ namespace Test
const string expectedResult = @"
//
-
-using MapTo;
-using System;
-
namespace Test
{
+ using MapTo;
+ using System;
+
partial class Foo
{
public Foo(Baz baz)
@@ -199,12 +198,11 @@ namespace Test
const string expectedResult = @"
//
-
-using MapTo;
-using System;
-
namespace Test
{
+ using MapTo;
+ using System;
+
partial class Foo
{
public Foo(Baz baz)
@@ -262,12 +260,11 @@ namespace Test
const string expectedResult = @"
//
-
-using Bazaar;
-using MapTo;
-using System;
-
namespace Test
+{
+ using Bazaar;
+ using MapTo;
+ using System;
";
// Act
@@ -529,13 +526,15 @@ private protected ManagerViewModel(MappingContext context, Manager manager) : ba
var sources = GetEmployeeManagerSourceText();
const string expectedResult = @"
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Test.Data.Models;
-
+//
namespace Test.ViewModels
{
+ using MapTo;
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Test.Data.Models;
+
partial class ManagerViewModel
{
public ManagerViewModel(Manager manager)
@@ -568,14 +567,15 @@ namespace Test.ViewModels
var sources = GetEmployeeManagerSourceText(useDifferentViewModelNamespace: true);
const string expectedResult = @"
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Test.Data.Models;
-using Test.ViewModels;
-
namespace Test.ViewModels2
{
+ using MapTo;
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Test.Data.Models;
+ using Test.ViewModels;
+
partial class ManagerViewModel
{
public ManagerViewModel(Manager manager)
diff --git a/test/MapTo.Tests/MappedClassesTests.cs b/test/MapTo.Tests/MappedClassesTests.cs
index a425c54..84d6a24 100644
--- a/test/MapTo.Tests/MappedClassesTests.cs
+++ b/test/MapTo.Tests/MappedClassesTests.cs
@@ -96,6 +96,37 @@ namespace Test.Data.Models
diagnostics.ShouldNotBeSuccessful(DiagnosticsFactory.MissingConstructorArgument(constructorSyntax));
}
+ [Fact]
+ public void When_PropertyNameIsTheSameAsClassName_Should_MapAccordingly()
+ {
+ // Arrange
+ var source = @"
+namespace Sale
+{
+ public class Sale { public Sale Prop1 { get; set; } }
+}
+
+namespace SaleModel
+{
+ using MapTo;
+ using Sale;
+
+ [MapFrom(typeof(Sale))]
+ public partial class SaleModel
+ {
+ [MapProperty(SourcePropertyName = nameof(global::Sale.Sale.Prop1))]
+ public Sale Sale { get; set; }
+ }
+}
+".Trim();
+
+ // Act
+ var (compilation, diagnostics) = CSharpGenerator.GetOutputCompilation(source, analyzerConfigOptions: DefaultAnalyzerOptions);
+
+ // Assert
+ diagnostics.ShouldBeSuccessful();
+ }
+
private static string NestedSourceClass => @"
namespace Test.Data.Models
{