Fixes issue #6. Move usings inside namespace declaration.
This commit is contained in:
parent
9e662c7e90
commit
e474ab86d0
|
@ -10,13 +10,12 @@ namespace MapTo.Sources
|
||||||
using var builder = new SourceBuilder()
|
using var builder = new SourceBuilder()
|
||||||
.WriteLine(GeneratedFilesHeader)
|
.WriteLine(GeneratedFilesHeader)
|
||||||
.WriteNullableContextOptionIf(model.Options.SupportNullableReferenceTypes)
|
.WriteNullableContextOptionIf(model.Options.SupportNullableReferenceTypes)
|
||||||
.WriteLine()
|
|
||||||
.WriteUsings(model.Usings)
|
|
||||||
.WriteLine()
|
|
||||||
|
|
||||||
// Namespace declaration
|
// Namespace declaration
|
||||||
.WriteLine($"namespace {model.Namespace}")
|
.WriteLine($"namespace {model.Namespace}")
|
||||||
.WriteOpeningBracket()
|
.WriteOpeningBracket()
|
||||||
|
.WriteUsings(model.Usings)
|
||||||
|
.WriteLine()
|
||||||
|
|
||||||
// Class declaration
|
// Class declaration
|
||||||
.WriteLine($"partial class {model.ClassName}")
|
.WriteLine($"partial class {model.ClassName}")
|
||||||
|
|
|
@ -122,12 +122,11 @@ namespace Test
|
||||||
|
|
||||||
const string expectedResult = @"
|
const string expectedResult = @"
|
||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
|
||||||
using MapTo;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
|
using MapTo;
|
||||||
|
using System;
|
||||||
|
|
||||||
partial class Foo
|
partial class Foo
|
||||||
{
|
{
|
||||||
public Foo(Baz baz)
|
public Foo(Baz baz)
|
||||||
|
@ -199,12 +198,11 @@ namespace Test
|
||||||
|
|
||||||
const string expectedResult = @"
|
const string expectedResult = @"
|
||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
|
||||||
using MapTo;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Test
|
namespace Test
|
||||||
{
|
{
|
||||||
|
using MapTo;
|
||||||
|
using System;
|
||||||
|
|
||||||
partial class Foo
|
partial class Foo
|
||||||
{
|
{
|
||||||
public Foo(Baz baz)
|
public Foo(Baz baz)
|
||||||
|
@ -262,12 +260,11 @@ namespace Test
|
||||||
|
|
||||||
const string expectedResult = @"
|
const string expectedResult = @"
|
||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
|
||||||
using Bazaar;
|
|
||||||
using MapTo;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Test
|
namespace Test
|
||||||
|
{
|
||||||
|
using Bazaar;
|
||||||
|
using MapTo;
|
||||||
|
using System;
|
||||||
";
|
";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
@ -529,13 +526,15 @@ private protected ManagerViewModel(MappingContext context, Manager manager) : ba
|
||||||
var sources = GetEmployeeManagerSourceText();
|
var sources = GetEmployeeManagerSourceText();
|
||||||
|
|
||||||
const string expectedResult = @"
|
const string expectedResult = @"
|
||||||
using System;
|
// <auto-generated />
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Test.Data.Models;
|
|
||||||
|
|
||||||
namespace Test.ViewModels
|
namespace Test.ViewModels
|
||||||
{
|
{
|
||||||
|
using MapTo;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Test.Data.Models;
|
||||||
|
|
||||||
partial class ManagerViewModel
|
partial class ManagerViewModel
|
||||||
{
|
{
|
||||||
public ManagerViewModel(Manager manager)
|
public ManagerViewModel(Manager manager)
|
||||||
|
@ -568,14 +567,15 @@ namespace Test.ViewModels
|
||||||
var sources = GetEmployeeManagerSourceText(useDifferentViewModelNamespace: true);
|
var sources = GetEmployeeManagerSourceText(useDifferentViewModelNamespace: true);
|
||||||
|
|
||||||
const string expectedResult = @"
|
const string expectedResult = @"
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Test.Data.Models;
|
|
||||||
using Test.ViewModels;
|
|
||||||
|
|
||||||
namespace Test.ViewModels2
|
namespace Test.ViewModels2
|
||||||
{
|
{
|
||||||
|
using MapTo;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Test.Data.Models;
|
||||||
|
using Test.ViewModels;
|
||||||
|
|
||||||
partial class ManagerViewModel
|
partial class ManagerViewModel
|
||||||
{
|
{
|
||||||
public ManagerViewModel(Manager manager)
|
public ManagerViewModel(Manager manager)
|
||||||
|
|
|
@ -96,6 +96,37 @@ namespace Test.Data.Models
|
||||||
diagnostics.ShouldNotBeSuccessful(DiagnosticsFactory.MissingConstructorArgument(constructorSyntax));
|
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 => @"
|
private static string NestedSourceClass => @"
|
||||||
namespace Test.Data.Models
|
namespace Test.Data.Models
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue