Skip to content

Commit 3aa28e8

Browse files
AddPrismMvvmSupport (#11)
* AddPrismMvvmSupport * refactoring #1 * refactoring #2 * change ref type * fix analyzer ref and project loaction * some refactorings * make ContextInfo immutable again * move specific attributes to specific classes * Add exceptions & summary Co-authored-by: Vitaly Tolstikov <[email protected]>
1 parent d3fffa2 commit 3aa28e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2262
-337
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</ItemGroup>
4949
<ItemGroup>
5050
<PackageReference Include="DevExpressMvvm" Version="20.2.3" />
51+
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
5152
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
5253
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" />
5354
<PackageReference Include="NUnit" Version="3.13.2" />

DevExpress.Mvvm.CodeGenerators.Tests/NetCoreTests/MemberNotNullTest.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,39 @@
33
using System.Diagnostics.CodeAnalysis;
44

55
namespace DevExpress.Mvvm.CodeGenerators.Tests {
6-
[GenerateViewModel]
7-
partial class WithMemberNotNullAttribute {
86
#nullable enable
7+
[Prism.GenerateViewModel]
8+
partial class WithMemberNotNullAttributeDx {
9+
[Prism.GenerateProperty]
10+
string withAttribute;
11+
12+
public WithMemberNotNullAttributeDx() {
13+
WithAttribute = string.Empty;
14+
}
15+
}
16+
[GenerateViewModel]
17+
partial class WithMemberNotNullAttributePrism {
918
[GenerateProperty]
1019
string withAttribute;
1120

12-
public WithMemberNotNullAttribute() {
21+
public WithMemberNotNullAttributePrism() {
1322
WithAttribute = string.Empty;
1423
}
15-
#nullable restore
1624
}
25+
#nullable restore
1726

1827
[TestFixture]
1928
public class MemberNotNullTest {
2029
[Test]
21-
public void CheckAttribute() {
22-
var withAttributePropertySetter = typeof(WithMemberNotNullAttribute).GetProperty("WithAttribute").SetMethod;
30+
public void CheckAttributeDx() {
31+
var withAttributePropertySetter = typeof(WithMemberNotNullAttributeDx).GetProperty("WithAttribute").SetMethod;
32+
var attributes = Attribute.GetCustomAttributes(withAttributePropertySetter);
33+
var expectedAttributes = new Attribute[] { new MemberNotNullAttribute("withAttribute") };
34+
Assert.AreEqual(expectedAttributes, attributes);
35+
}
36+
[Test]
37+
public void CheckAttributePrism() {
38+
var withAttributePropertySetter = typeof(WithMemberNotNullAttributePrism).GetProperty("WithAttribute").SetMethod;
2339
var attributes = Attribute.GetCustomAttributes(withAttributePropertySetter);
2440
var expectedAttributes = new Attribute[] { new MemberNotNullAttribute("withAttribute") };
2541
Assert.AreEqual(expectedAttributes, attributes);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="DevExpressMvvm" Version="20.2.3" />
19+
<PackageReference Include="Prism.Wpf" Version="8.1.97" />
1920
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
2021
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" />
2122
<PackageReference Include="NUnit" Version="3.13.2" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public void WithArg(int arg) { }
1212
[GenerateCommand]
1313
public void WithNullableArg(int? arg) { }
1414
public void SomeMethod() { }
15+
public void With2Args(int a, string str) { }
1516

1617
[GenerateCommand(Name = "Command", CanExecuteMethod = "CanDoIt")]
1718
public void Method(int arg) { }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using NUnit.Framework;
2+
using System.ComponentModel;
3+
4+
namespace DevExpress.Mvvm.CodeGenerators.Tests {
5+
class ViewModelParent {
6+
public int a = 0;
7+
public void OnParentViewModelChanged(object o) { a = 1; }
8+
}
9+
[GenerateViewModel(ImplementISupportParentViewModel = true)]
10+
partial class WithInheritedParentViewModelMethod : ViewModelParent {
11+
}
12+
[GenerateViewModel(ImplementISupportParentViewModel = true)]
13+
partial class WithParentViewModelMethod {
14+
public int a = 0;
15+
void OnParentViewModelChanged(object o) { a = 1; }
16+
}
17+
[GenerateViewModel(ImplementINotifyPropertyChanging = true)]
18+
partial class GenerateProperties {
19+
[GenerateProperty(IsVirtual = true)]
20+
int property;
21+
}
22+
[GenerateViewModel]
23+
partial class WithTwoMvvmAttribute {
24+
[Prism.GenerateProperty]
25+
int prismProperty;
26+
[Prism.GenerateCommand]
27+
void PrismMethod() { }
28+
}
29+
30+
[TestFixture]
31+
public class PropertyGenerationTests {
32+
[Test]
33+
public void PropertyImplementation() {
34+
var generated = new GenerateProperties();
35+
36+
Assert.IsNotNull(generated.GetType().GetProperty("Property"));
37+
Assert.IsNull(generated.GetType().GetProperty("NotProperty"));
38+
}
39+
[Test]
40+
public void ISupportParentViewModelTest() {
41+
var generatedWithParent = new WithInheritedParentViewModelMethod();
42+
var generated = new WithParentViewModelMethod();
43+
Assert.AreEqual(0, generatedWithParent.a);
44+
Assert.AreEqual(0, generated.a);
45+
generatedWithParent.ParentViewModel = new ViewModelParent();
46+
generated.ParentViewModel = new ViewModelParent();
47+
Assert.AreEqual(0, generatedWithParent.a);
48+
Assert.AreEqual(1, generated.a);
49+
Assert.Throws<System.InvalidOperationException>(() => generated.ParentViewModel = generated);
50+
}
51+
[Test]
52+
public void DoNotGeneratePrismMembers() {
53+
var generated = new WithTwoMvvmAttribute();
54+
Assert.IsNull(generated.GetType().GetProperty("PrismProperty"));
55+
Assert.IsNull(generated.GetType().GetProperty("PrismMethodCommand"));
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)