From 94e590994c3deb92920c3e1603eb966746198f0e Mon Sep 17 00:00:00 2001 From: Cezary Piatek Date: Sat, 22 Sep 2018 15:27:29 +0200 Subject: [PATCH] Fix formatting for implicit conversion --- .../ExplicitConversionTestCases.Designer.cs | 76 ++++++++++++++++--- .../ExplicitConversionTestCases.resx | 18 +++-- .../ExplicitConversionTests.cs | 6 ++ ...ExplicitConversionForInvalidAssigment.txt} | 0 ...itConversionForInvalidAssigment_FIXED.txt} | 0 ...02_ExplicitConversionForInvalidReturn.txt} | 0 ...licitConversionForInvalidReturn_FIXED.txt} | 0 ...003_ExplicitConversionForInvalidYield.txt} | 0 ...plicitConversionForInvalidYield_FIXED.txt} | 0 ...nversionForInvalidAssigmentInInitBlock.txt | 41 ++++++++++ ...onForInvalidAssigmentInInitBlock_FIXED.txt | 48 ++++++++++++ .../MappingGenerator.Test.csproj | 12 --- .../ExplicitConversionCodeFixProvider.cs | 8 +- 13 files changed, 176 insertions(+), 33 deletions(-) rename MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/{001_ExplicitConversionForInvalidAssigment.cs => 001_ExplicitConversionForInvalidAssigment.txt} (100%) rename MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/{001_ExplicitConversionForInvalidAssigment_FIXED.cs => 001_ExplicitConversionForInvalidAssigment_FIXED.txt} (100%) rename MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/{002_ExplicitConversionForInvalidReturn.cs => 002_ExplicitConversionForInvalidReturn.txt} (100%) rename MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/{002_ExplicitConversionForInvalidReturn_FIXED.cs => 002_ExplicitConversionForInvalidReturn_FIXED.txt} (100%) rename MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/{003_ExplicitConversionForInvalidYield.cs => 003_ExplicitConversionForInvalidYield.txt} (100%) rename MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/{003_ExplicitConversionForInvalidYield_FIXED.cs => 003_ExplicitConversionForInvalidYield_FIXED.txt} (100%) create mode 100644 MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock.txt create mode 100644 MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.Designer.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.Designer.cs index 3dc0d93..c220364 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.Designer.cs +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.Designer.cs @@ -158,10 +158,10 @@ internal static string _002_ExplicitConversionForInvalidReturn { /// /// public ReadOnlyCollection<AddressDTO> DoSomething(IList<AddressEntity> addresses) /// { - /// return addresses.Select(addresse => new AddressDTO() + /// return addresses.Select(address => new AddressDTO() /// { - /// FlatNo = addresse.FlatNo, - /// Bui [rest of string was truncated]";. + /// FlatNo = address.FlatNo, + /// Build [rest of string was truncated]";. /// internal static string _002_ExplicitConversionForInvalidReturn_FIXED { get { @@ -208,20 +208,74 @@ internal static string _003_ExplicitConversionForInvalidYield { /// /// public IEnumerable<AddressDTO> DoSomething(AddressEntity address) /// { - /// yield return address; + /// yield return new AddressDTO() + /// { + /// FlatNo = address.FlatNo, + /// BuildtingNo = address.BuildtingNo, + /// Street = address.Street, + /// ZipCode = address.ZipCo [rest of string was truncated]";. + /// + internal static string _003_ExplicitConversionForInvalidYield_FIXED { + get { + return ResourceManager.GetString("_003_ExplicitConversionForInvalidYield_FIXED", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to using System; + ///using System.Collections.Generic; + ///using System.Text; + /// + ///namespace MappingGenerator.Test.ExplicitConversions.TestCaseData + ///{ + /// public class TestMapper + /// { + /// public AddressDTO Address { get; set; } + /// + /// public UserDTO DoSomething() + /// { + /// var addressEntity = new AddressEntity(); + /// return new UserDTO{ + /// Address = addressEntity + /// } /// } /// } /// - /// public class AddressDTO + /// public class UserDTO{ + /// public AddressDTO Address {get; set;} [rest of string was truncated]";. + /// + internal static string _004_ExplicitConversionForInvalidAssigmentInInitBlock { + get { + return ResourceManager.GetString("_004_ExplicitConversionForInvalidAssigmentInInitBlock", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to using System; + ///using System.Collections.Generic; + ///using System.Text; + /// + ///namespace MappingGenerator.Test.ExplicitConversions.TestCaseData + ///{ + /// public class TestMapper /// { - /// public string FlatNo { get; set; } - /// public string BuildtingNo { get; set; } - /// public string Street { get; set; } - /// [rest of string was truncated]";. + /// public AddressDTO Address { get; set; } + /// + /// public UserDTO DoSomething() + /// { + /// var addressEntity = new AddressEntity(); + /// return new UserDTO{ + /// Address = addressEntity + /// } + /// } + /// } + /// + /// public class UserDTO{ + /// public AddressDTO Address {get; set;} [rest of string was truncated]";. /// - internal static string _003_ExplicitConversionForInvalidYield_FIXED { + internal static string _004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED { get { - return ResourceManager.GetString("_003_ExplicitConversionForInvalidYield_FIXED", resourceCulture); + return ResourceManager.GetString("_004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED", resourceCulture); } } } diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.resx b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.resx index 25f1872..e45bca4 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.resx +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTestCases.resx @@ -119,21 +119,27 @@ - TestCaseData\001_ExplicitConversionForInvalidAssigment.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + TestCaseData\001_ExplicitConversionForInvalidAssigment.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - TestCaseData\001_ExplicitConversionForInvalidAssigment_FIXED.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + TestCaseData\001_ExplicitConversionForInvalidAssigment_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - TestCaseData\002_ExplicitConversionForInvalidReturn.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + TestCaseData\002_ExplicitConversionForInvalidReturn.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - TestCaseData\002_ExplicitConversionForInvalidReturn_FIXED.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + TestCaseData\002_ExplicitConversionForInvalidReturn_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - TestCaseData\003_ExplicitConversionForInvalidYield.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + TestCaseData\003_ExplicitConversionForInvalidYield.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - TestCaseData\003_ExplicitConversionForInvalidYield_FIXED.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + TestCaseData\003_ExplicitConversionForInvalidYield_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + TestCaseData\004_ExplicitConversionForInvalidAssigmentInInitBlock.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + TestCaseData\004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 \ No newline at end of file diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTests.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTests.cs index 2a6ca81..5c232f3 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTests.cs +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/ExplicitConversionTests.cs @@ -30,6 +30,12 @@ public void should_be_able_to_generate_conversion_for_invalid_yield_statement() } + [Test] + public void should_be_able_to_generate_conversion_for_invalid_assignment_statement_in_init_block() + { + VerifyCSharpFix(ExplicitConversionTestCases._004_ExplicitConversionForInvalidAssigmentInInitBlock, ExplicitConversionTestCases._004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED, ExplicitConversionCodeFixProvider.CS0029, 0); + } + protected override CodeFixProvider GetCSharpCodeFixProvider() { return new ExplicitConversionCodeFixProvider(); diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment.txt similarity index 100% rename from MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment.cs rename to MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment_FIXED.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment_FIXED.txt similarity index 100% rename from MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment_FIXED.cs rename to MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/001_ExplicitConversionForInvalidAssigment_FIXED.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn.txt similarity index 100% rename from MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn.cs rename to MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn_FIXED.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn_FIXED.txt similarity index 100% rename from MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn_FIXED.cs rename to MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/002_ExplicitConversionForInvalidReturn_FIXED.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield.txt similarity index 100% rename from MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield.cs rename to MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield_FIXED.cs b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield_FIXED.txt similarity index 100% rename from MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield_FIXED.cs rename to MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/003_ExplicitConversionForInvalidYield_FIXED.txt diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock.txt b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock.txt new file mode 100644 index 0000000..b3aa87b --- /dev/null +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock.txt @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MappingGenerator.Test.ExplicitConversions.TestCaseData +{ + public class TestMapper + { + public AddressDTO Address { get; set; } + + public UserDTO DoSomething() + { + var addressEntity = new AddressEntity(); + return new UserDTO{ + Address = addressEntity + } + } + } + + public class UserDTO{ + public AddressDTO Address {get; set;} + } + + public class AddressDTO + { + public string FlatNo { get; set; } + public string BuildtingNo { get; set; } + public string Street { get; set; } + public string ZipCode { get; set; } + public string City { get; set; } + } + + public class AddressEntity + { + public string FlatNo { get; set; } + public string BuildtingNo { get; set; } + public string Street { get; set; } + public string ZipCode { get; set; } + public string City { get; set; } + } +} \ No newline at end of file diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt new file mode 100644 index 0000000..17fd3ab --- /dev/null +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ExplicitConversions/TestCaseData/004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace MappingGenerator.Test.ExplicitConversions.TestCaseData +{ + public class TestMapper + { + public AddressDTO Address { get; set; } + + public UserDTO DoSomething() + { + var addressEntity = new AddressEntity(); + return new UserDTO{ + Address = new AddressDTO() + { + FlatNo = addressEntity.FlatNo, + BuildtingNo = addressEntity.BuildtingNo, + Street = addressEntity.Street, + ZipCode = addressEntity.ZipCode, + City = addressEntity.City + } + } + } + } + + public class UserDTO{ + public AddressDTO Address {get; set;} + } + + public class AddressDTO + { + public string FlatNo { get; set; } + public string BuildtingNo { get; set; } + public string Street { get; set; } + public string ZipCode { get; set; } + public string City { get; set; } + } + + public class AddressEntity + { + public string FlatNo { get; set; } + public string BuildtingNo { get; set; } + public string Street { get; set; } + public string ZipCode { get; set; } + public string City { get; set; } + } +} \ No newline at end of file diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator.Test.csproj b/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator.Test.csproj index f78921c..7dfeca9 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator.Test.csproj +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/MappingGenerator.Test.csproj @@ -7,12 +7,6 @@ - - - - - - @@ -30,12 +24,6 @@ - - - - - - diff --git a/MappingGenerator/MappingGenerator/MappingGenerator/ExplicitConversionCodeFixProvider.cs b/MappingGenerator/MappingGenerator/MappingGenerator/ExplicitConversionCodeFixProvider.cs index 01eef54..2c07a6f 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator/ExplicitConversionCodeFixProvider.cs +++ b/MappingGenerator/MappingGenerator/MappingGenerator/ExplicitConversionCodeFixProvider.cs @@ -56,8 +56,8 @@ private async Task GenerateExplicitConversion(Document document, Assig { var mappingEngine = await CreateMappingEngine(document, assignmentExpression, cancellationToken); var sourceType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Right).Type; - var destimationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).Type; - var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right, sourceType, destimationType); + var destinationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).Type; + var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right.WithoutTrivia(), sourceType, destinationType); return await ReplaceNode(document, assignmentExpression, assignmentExpression.WithRight(mappingExpression), cancellationToken); } @@ -74,7 +74,7 @@ private async Task GenerateExplicitConversion(Document document, Retur { var mappingEngine = await CreateMappingEngine(document, returnStatement, cancellationToken); var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(returnStatement.Expression); - var mappingExpression = mappingEngine.MapExpression(returnStatement.Expression, returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType); + var mappingExpression = mappingEngine.MapExpression(returnStatement.Expression.WithoutTrivia(), returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType); return await ReplaceNode(document, returnStatement, returnStatement.WithExpression(mappingExpression), cancellationToken); } @@ -82,7 +82,7 @@ private async Task GenerateExplicitConversion(Document document, Yield { var mappingEngine = await CreateMappingEngine(document, yieldStatement, cancellationToken); var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(yieldStatement.Expression); - var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression, returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType); + var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression.WithoutTrivia(), returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType); return await ReplaceNode(document, yieldStatement, yieldStatement.WithExpression(mappingExpression), cancellationToken); }