Skip to content

Commit d3fffa2

Browse files
authored
TestRefactoring (#10)
* TestRefactoring * AddSharedTests * remove_collector
1 parent 9a1dc0f commit d3fffa2

21 files changed

+161
-78
lines changed

DevExpress.Mvvm.CodeGenerators.Tests/FrameworkTests/FrameworkTests.csproj

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
<Analyzer Include="..\..\DevExpress.Mvvm.CodeGenerators\bin\DevExpress.Mvvm.CodeGenerators.dll" />
3737
</ItemGroup>
3838
<ItemGroup>
39-
<Reference Include="DevExpress.Mvvm.CodeGenerators">
40-
<HintPath>..\..\DevExpress.Mvvm.CodeGenerators\bin\DevExpress.Mvvm.CodeGenerators.dll</HintPath>
41-
</Reference>
4239
<Reference Include="System" />
4340
<Reference Include="System.ComponentModel.DataAnnotations" />
4441
<Reference Include="System.Core" />
@@ -57,26 +54,15 @@
5754
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
5855
</ItemGroup>
5956
<ItemGroup>
60-
<Compile Include="..\TestSource\SourceBuilderTests.cs" />
57+
<Compile Include="DataErrorInfoTests.cs" />
6158
<Compile Include="MemberNotNullTest.cs" />
62-
<Compile Include="..\TestSource\AsyncCommandGenerationTests.cs" />
63-
<Compile Include="..\TestSource\AttributeTransferTests.cs" />
64-
<Compile Include="..\TestSource\CommandGenerationTests.cs" />
65-
<Compile Include="..\TestSource\DataErrorInfoTests.cs" />
66-
<Compile Include="..\TestSource\DiagnosticTests.cs" />
67-
<Compile Include="..\TestSource\GenerationTests.cs" />
68-
<Compile Include="..\TestSource\Helper.cs" />
69-
<Compile Include="..\TestSource\InterfacesTests.cs" />
70-
<Compile Include="..\TestSource\NullableAnnotationTests.cs" />
71-
<Compile Include="..\TestSource\PropertyGenerationTests.cs" />
72-
<Compile Include="..\TestSource\SupportServicesTests.cs" />
73-
<Compile Include="..\TestSource\UsingRaiseMethodTests.cs" />
7459
</ItemGroup>
7560
<ItemGroup>
7661
<None Include="app.config" />
7762
</ItemGroup>
7863
<ItemGroup>
7964
<Folder Include="Properties\" />
8065
</ItemGroup>
66+
<Import Project="..\SharedTests\SharedTests.projitems" Label="Shared" />
8167
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8268
</Project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using NUnit.Framework;
2+
using System.ComponentModel;
3+
using System.ComponentModel.DataAnnotations;
4+
5+
namespace DevExpress.Mvvm.CodeGenerators.Tests {
6+
[GenerateViewModel(ImplementIDataErrorInfo = true)]
7+
partial class ClassWithDataErrorInfo {
8+
public const string MaxLengthAttributeErrorMessage = "ErrorMessage from MaxLengthAttribute";
9+
public const string MinLengthAttributeErrorMessage = "ErrorMessage from MinLengthAttribute";
10+
public const string RequiredAttributeErrorMessage = "ErrorMessage from RequiredAttribute";
11+
12+
[GenerateProperty]
13+
string withoutErrorInfo;
14+
15+
[GenerateProperty]
16+
[MaxLength(5, ErrorMessage = MaxLengthAttributeErrorMessage)]
17+
string withErrorMessage;
18+
19+
[GenerateProperty]
20+
[MinLength(5, ErrorMessage = MinLengthAttributeErrorMessage),
21+
Required(ErrorMessage = RequiredAttributeErrorMessage)]
22+
string withDoubleErrorMessage;
23+
}
24+
25+
[TestFixture]
26+
public class DataErrorInfoTests {
27+
[Test]
28+
public void ErrorMessage() {
29+
var generated = new ClassWithDataErrorInfo();
30+
31+
var errorMessage = ((IDataErrorInfo)generated)[nameof(generated.WithoutErrorInfo)];
32+
var expectedErrorMessage = string.Empty;
33+
Assert.AreEqual(expectedErrorMessage, errorMessage);
34+
35+
generated.WithErrorMessage = "1";
36+
errorMessage = ((IDataErrorInfo)generated)[nameof(generated.WithErrorMessage)];
37+
expectedErrorMessage = string.Empty;
38+
Assert.AreEqual(expectedErrorMessage, errorMessage);
39+
40+
generated.WithErrorMessage = "123456";
41+
errorMessage = ((IDataErrorInfo)generated)[nameof(generated.WithErrorMessage)];
42+
expectedErrorMessage = ClassWithDataErrorInfo.MaxLengthAttributeErrorMessage;
43+
Assert.AreEqual(expectedErrorMessage, errorMessage);
44+
45+
generated.WithDoubleErrorMessage = "";
46+
errorMessage = ((IDataErrorInfo)generated)[nameof(generated.WithDoubleErrorMessage)];
47+
expectedErrorMessage = string.Join(" ", ClassWithDataErrorInfo.MinLengthAttributeErrorMessage, ClassWithDataErrorInfo.RequiredAttributeErrorMessage);
48+
Assert.AreEqual(expectedErrorMessage, errorMessage);
49+
50+
generated.WithDoubleErrorMessage = "1";
51+
errorMessage = ((IDataErrorInfo)generated)[nameof(generated.WithDoubleErrorMessage)];
52+
expectedErrorMessage = ClassWithDataErrorInfo.MinLengthAttributeErrorMessage;
53+
Assert.AreEqual(expectedErrorMessage, errorMessage);
54+
}
55+
}
56+
}

DevExpress.Mvvm.CodeGenerators.Tests/NetCoreTests/NetCoreTests.csproj

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
<ItemGroup>
1414
<Analyzer Include="..\..\DevExpress.Mvvm.CodeGenerators\bin\DevExpress.Mvvm.CodeGenerators.dll" />
1515
</ItemGroup>
16-
<ItemGroup>
17-
<Reference Include="DevExpress.Mvvm.CodeGenerators">
18-
<HintPath>..\..\DevExpress.Mvvm.CodeGenerators\bin\DevExpress.Mvvm.CodeGenerators.dll</HintPath>
19-
</Reference>
20-
</ItemGroup>
2116

2217
<ItemGroup>
2318
<PackageReference Include="DevExpressMvvm" Version="20.2.3" />
@@ -28,19 +23,5 @@
2823
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
2924
</ItemGroup>
3025

31-
<ItemGroup>
32-
<Compile Include="..\TestSource\SourceBuilderTests.cs" />
33-
<Compile Include="..\TestSource\AsyncCommandGenerationTests.cs" />
34-
<Compile Include="..\TestSource\AttributeTransferTests.cs" />
35-
<Compile Include="..\TestSource\CommandGenerationTests.cs" />
36-
<Compile Include="..\TestSource\DataErrorInfoTests.cs" />
37-
<Compile Include="..\TestSource\DiagnosticTests.cs" />
38-
<Compile Include="..\TestSource\GenerationTests.cs" />
39-
<Compile Include="..\TestSource\Helper.cs" />
40-
<Compile Include="..\TestSource\InterfacesTests.cs" />
41-
<Compile Include="..\TestSource\NullableAnnotationTests.cs" />
42-
<Compile Include="..\TestSource\PropertyGenerationTests.cs" />
43-
<Compile Include="..\TestSource\SupportServicesTests.cs" />
44-
<Compile Include="..\TestSource\UsingRaiseMethodTests.cs" />
45-
</ItemGroup>
26+
<Import Project="..\SharedTests\SharedTests.projitems" Label="Shared" />
4627
</Project>

DevExpress.Mvvm.CodeGenerators.Tests/TestSource/CommandGenerationTests.cs renamed to DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/CommandGenerationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public void RaiseCanExecuteChanged() {
112112
generated.CommandWithoutCommandManager.CanExecuteChanged += (s, e) => throw new Exception();
113113
Assert.Throws<Exception>(generated.UpdateCommandWithoutManagerCommand);
114114
}
115-
#else
115+
#else
116116
[Test]
117117
public void NoUseCommandManagerPropertyInWinUI() {
118-
Assert.IsNull(typeof(GenerateCommandAttribute).GetProperty(AttributesGenerator.UseCommandManager));
118+
Assert.IsNull(typeof(GenerateCommandAttribute).GetProperty("UseCommandManager"));
119119
}
120120
#endif
121121

DevExpress.Mvvm.CodeGenerators.Tests/TestSource/Helper.cs renamed to DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/Helper.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,4 @@ public static void PropertyChangingEvent(INotifyPropertyChanging inpc, Action ac
6060
);
6161
}
6262
}
63-
64-
static class Helper {
65-
public static Compilation CreateCompilation(string source) =>
66-
CSharpCompilation.Create("MyCompilation",
67-
new[] { CSharpSyntaxTree.ParseText(source) },
68-
new[] {
69-
MetadataReference.CreateFromFile(typeof(System.Windows.Input.ICommand).Assembly.Location),
70-
MetadataReference.CreateFromFile(typeof(DelegateCommand).Assembly.Location),
71-
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
72-
MetadataReference.CreateFromFile(typeof(INotifyPropertyChanged).Assembly.Location),
73-
},
74-
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
75-
}
7663
}

DevExpress.Mvvm.CodeGenerators.Tests/TestSource/InterfacesTests.cs renamed to DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/InterfacesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void INPCingImplementation() {
7373
#if WINUI
7474
[Test]
7575
public void NoUseCommandManagerPropertyInWinUI() {
76-
Assert.IsNull(typeof(GenerateViewModelAttribute).GetProperty(AttributesGenerator.ImplementIDEI));
76+
Assert.IsNull(typeof(GenerateViewModelAttribute).GetProperty("ImplementIDataErrorInfo"));
7777
}
7878
#else
7979
[Test]

0 commit comments

Comments
 (0)