Skip to content

Commit 74db58a

Browse files
winui
1 parent 35e4439 commit 74db58a

File tree

19 files changed

+2538
-2048
lines changed

19 files changed

+2538
-2048
lines changed

DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/DxTest/AsyncCommandGenerationTests.cs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using NUnit.Framework;
22
using System;
33
using System.Reflection;
4+
using System.Threading;
45
using System.Threading.Tasks;
56

67
namespace DevExpress.Mvvm.CodeGenerators.Tests {
@@ -28,7 +29,20 @@ partial class GenerateAsyncCommands {
2829
public Task AllowMultipleExecution() => Task.CompletedTask;
2930

3031
[GenerateCommand]
31-
public Task<int> GenericTask() => task;
32+
public Task<int> GenericTask() => task;
33+
34+
#if WINUI
35+
[GenerateCommand]
36+
public Task CancellationTokenWithNoArg(CancellationToken token) => Task.CompletedTask;
37+
//[GenerateCommand]
38+
//public Task CancellationTokenWithArg(CancellationToken token, int arg) => Task.CompletedTask;
39+
//[GenerateCommand]
40+
//public Task CancellationTokenWithNullableArg(CancellationToken token, int? arg) => Task.CompletedTask;
41+
//public Task CancellationTokenSomeMethod(CancellationToken token) => Task.CompletedTask;
42+
43+
//[GenerateCommand(Name = "CancellationTokenMyAsyncCommand", CanExecuteMethod = "CanDoIt")]
44+
//public Task CancellationTokenMethod(CancellationToken token, int arg) => Task.CompletedTask;
45+
#endif
3246
}
3347

3448
[TestFixture]
@@ -48,40 +62,44 @@ public void AsyncCommandImplementation() {
4862

4963
[Test]
5064
public void CallRequiredMethodForAsyncCommand() {
51-
var generated = new GenerateAsyncCommands();
52-
65+
var generated = new GenerateAsyncCommands();
66+
67+
#if !WINUI
5368
var method = GetFieldValue<Func<int, Task>, AsyncCommand<int>>(generated.MyAsyncCommand, "executeMethod");
69+
var canMethod = GetFieldValue<Func<int, bool>, AsyncCommand<int>>(generated.MyAsyncCommand, "canExecuteMethod");
70+
var canMethod2 = GetFieldValue<Func<int, bool>, AsyncCommand>(generated.GenericTaskCommand, "canExecuteMethod");
71+
5472
var expectedMethod = generated.GetType().GetMethod("Method");
5573
Assert.AreEqual(expectedMethod, method.Method);
56-
57-
var canMethod = GetFieldValue<Func<int, bool>, AsyncCommand<int>>(generated.MyAsyncCommand, "canExecuteMethod");
5874
var expectedCanMethod = generated.GetType().GetMethod("CanDoIt");
5975
Assert.AreEqual(expectedCanMethod, canMethod.Method);
76+
Assert.IsNull(canMethod2);
77+
#endif
6078

61-
#if !WINUI
6279
var allowMultipleExecution = generated.MyAsyncCommand.AllowMultipleExecution;
6380
var expectedAllowMultipleExecution = false;
6481
Assert.AreEqual(expectedAllowMultipleExecution, allowMultipleExecution);
6582

83+
allowMultipleExecution = generated.AllowMultipleExecutionCommand.AllowMultipleExecution;
84+
Assert.AreEqual(true, allowMultipleExecution);
85+
86+
#if !WINUI
6687
var useCommandManager = GetFieldValue<bool, AsyncCommand<int>>(generated.MyAsyncCommand, "useCommandManager");
6788
Assert.AreEqual(true, useCommandManager);
6889
useCommandManager = GetFieldValue<bool, AsyncCommand>(generated.AsyncCommandWithoutCommandManager, "useCommandManager");
6990
Assert.AreEqual(false, useCommandManager);
70-
71-
allowMultipleExecution = generated.AllowMultipleExecutionCommand.AllowMultipleExecution;
72-
Assert.AreEqual(true, allowMultipleExecution);
73-
#endif
74-
75-
var canExecuteMethod = GetFieldValue<Func<int, bool>, AsyncCommand>(generated.GenericTaskCommand, "canExecuteMethod");
76-
Assert.IsNull(canExecuteMethod);
77-
}
91+
#endif
92+
}
93+
#if !WINUI
7894
static TResult GetFieldValue<TResult, T>(T source, string fieldName) {
79-
var fieldInfo = source.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
95+
var fieldInfo = source.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
96+
?? source.GetType().BaseType?.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
8097
Assert.IsNotNull(fieldInfo);
8198

8299
return (TResult)fieldInfo.GetValue(source);
83100
}
84-
101+
#endif
102+
85103
[Test]
86104
public void ArgumentTypeForAsyncCommand() {
87105
var generated = new GenerateAsyncCommands();

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public void CommandImplementation() {
6464
Assert.IsNull(generated.GetType().GetProperty("With2ArgsCommand"));
6565
Assert.IsNull(generated.GetType().GetProperty("ReturnNoVoidCommand"));
6666
Assert.IsNull(generated.GetType().GetProperty("SomeMethodCommand"));
67-
}
68-
67+
}
68+
69+
#if !WINUI
6970
[Test]
7071
public void CallRequiredMethodForCommand() {
7172
var generated = new GenerateCommands();
@@ -82,7 +83,6 @@ public void CallRequiredMethodForCommand() {
8283
var expectedCanMethod = generated.GetType().GetMethod("CanDoIt");
8384
Assert.AreEqual(expectedCanMethod, canMethod.Method);
8485

85-
#if !WINUI
8686
var useCommandManager = GetFieldValue<bool, DelegateCommand<int>>(generated.Command, "useCommandManager");
8787
Assert.AreEqual(true, useCommandManager);
8888

@@ -91,8 +91,9 @@ public void CallRequiredMethodForCommand() {
9191

9292
var canExecuteMethod = GetFieldValue<Func<int, bool>, DelegateCommand>(generated.CommandWithoutCommandManager, "canExecuteMethod");
9393
Assert.IsNull(canExecuteMethod);
94-
#endif
94+
9595
}
96+
#endif
9697
static TResult GetFieldValue<TResult, T>(T source, string fieldName) {
9798
var fieldInfo = source.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
9899
Assert.IsNotNull(fieldInfo);

DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/DxTest/InterfacesTests.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using NUnit.Framework;
22
using System.ComponentModel;
3+
#if WINUI
4+
using ISupportServices = DevExpress.Mvvm.ISupportUIServices;
5+
using IServiceContainer = DevExpress.Mvvm.IUIServiceContainer;
6+
#endif
37

48
namespace DevExpress.Mvvm.CodeGenerators.Tests {
59
partial class SimpleClass { }
@@ -9,25 +13,32 @@ partial class ClassWithGenerator { }
913
[GenerateViewModel(ImplementINotifyPropertyChanging = false)]
1014
partial class NotImplementINPCing { }
1115
[GenerateViewModel(ImplementINotifyPropertyChanging = true)]
12-
partial class ImplementINPCing { }
13-
16+
partial class ImplementINPCing { }
17+
1418
#if !WINUI
1519
[GenerateViewModel(ImplementIDataErrorInfo = false)]
1620
partial class NotImplementIDEI { }
1721
[GenerateViewModel(ImplementIDataErrorInfo = true)]
1822
partial class ImplementIDEI { }
1923
#endif
20-
24+
25+
#if !WINUI
2126
[GenerateViewModel(ImplementISupportServices = false)]
2227
partial class NotImplementISS { }
2328
[GenerateViewModel(ImplementISupportServices = true)]
2429
partial class ImplementISS { }
25-
26-
[GenerateViewModel(ImplementINotifyPropertyChanging = true,
27-
#if !WINUI
28-
ImplementIDataErrorInfo = true,
30+
#else
31+
[GenerateViewModel(ImplementISupportUIServices = false)]
32+
partial class NotImplementISS { }
33+
[GenerateViewModel(ImplementISupportUIServices = true)]
34+
partial class ImplementISS { }
35+
#endif
36+
37+
#if !WINUI
38+
[GenerateViewModel(ImplementINotifyPropertyChanging = true, ImplementIDataErrorInfo = true, ImplementISupportServices = true)]
39+
#else
40+
[GenerateViewModel(ImplementINotifyPropertyChanging = true, ImplementISupportUIServices = true)]
2941
#endif
30-
ImplementISupportServices = true)]
3142
partial class FullImplemented : INotifyPropertyChanged, INotifyPropertyChanging, IDataErrorInfo, ISupportServices {
3243
public event PropertyChangedEventHandler PropertyChanged;
3344
public event PropertyChangingEventHandler PropertyChanging;

DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/DxTest/NullableAnnotationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System.Threading.Tasks;
22

3-
namespace DevExpress.Mvvm.CodeGenerators.Tests {
4-
[GenerateViewModel(ImplementINotifyPropertyChanging = true,
3+
namespace DevExpress.Mvvm.CodeGenerators.Tests {
54
#if !WINUI
6-
ImplementIDataErrorInfo = true,
5+
[GenerateViewModel(ImplementINotifyPropertyChanging = true, ImplementIDataErrorInfo = true, ImplementISupportServices = true)]
6+
#else
7+
[GenerateViewModel(ImplementINotifyPropertyChanging = true, ImplementISupportUIServices = true)]
78
#endif
8-
ImplementISupportServices = true)]
99
public partial class NullableAnnotation {
1010
#nullable enable
1111
public NullableAnnotation() {

DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/DxTest/PropertyGenerationTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace DevExpress.Mvvm.CodeGenerators.Tests {
55
class ViewModelParent {
66
public int a = 0;
77
public void OnParentViewModelChanged(object o) { a = 1; }
8-
}
8+
}
9+
#if !WINUI
910
[GenerateViewModel(ImplementISupportParentViewModel = true)]
1011
partial class WithInheritedParentViewModelMethod : ViewModelParent {
1112
}
@@ -14,6 +15,7 @@ partial class WithParentViewModelMethod {
1415
public int a = 0;
1516
void OnParentViewModelChanged(object o) { a = 1; }
1617
}
18+
#endif
1719
[GenerateViewModel(ImplementINotifyPropertyChanging = true)]
1820
partial class GenerateProperties {
1921
[GenerateProperty(IsVirtual = true)]
@@ -35,7 +37,8 @@ public void PropertyImplementation() {
3537

3638
Assert.IsNotNull(generated.GetType().GetProperty("Property"));
3739
Assert.IsNull(generated.GetType().GetProperty("NotProperty"));
38-
}
40+
}
41+
#if !WINUI
3942
[Test]
4043
public void ISupportParentViewModelTest() {
4144
var generatedWithParent = new WithInheritedParentViewModelMethod();
@@ -48,6 +51,7 @@ public void ISupportParentViewModelTest() {
4851
Assert.AreEqual(1, generated.a);
4952
Assert.Throws<System.InvalidOperationException>(() => generated.ParentViewModel = generated);
5053
}
54+
#endif
5155
[Test]
5256
public void DoNotGeneratePrismMembers() {
5357
var generated = new WithTwoMvvmAttribute();

DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/DxTest/SupportServicesTests.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
using NUnit.Framework;
2+
#if WINUI
3+
using ISupportServices = DevExpress.Mvvm.ISupportUIServices;
4+
using IServiceContainer = DevExpress.Mvvm.IUIServiceContainer;
5+
using ServiceContainer = DevExpress.Mvvm.UIServiceContainer;
6+
#endif
27

3-
namespace DevExpress.Mvvm.CodeGenerators.Tests {
8+
namespace DevExpress.Mvvm.CodeGenerators.Tests {
9+
#if !WINUI
410
[GenerateViewModel(ImplementISupportServices = true)]
5-
partial class ClassWithSupportServices {
6-
}
11+
#else
12+
[GenerateViewModel(ImplementISupportUIServices = true)]
13+
#endif
14+
partial class ClassWithSupportServices { }
715
public interface IService { }
816
public class TestService : IService { }
17+
#if !WINUI
918
[GenerateViewModel(ImplementISupportServices = true)]
19+
#else
20+
[GenerateViewModel(ImplementISupportUIServices = true)]
21+
#endif
1022
partial class GetServiceGenerate {
1123
public GetServiceGenerate(ServiceContainer serv) {
1224
serviceContainer = serv;
13-
}
25+
}
26+
#if !WINUI
1427
public IService GetService() {
1528
return GetService<IService>();
1629
}
30+
#else
31+
public IService GetUIService() {
32+
return GetUIService<IService>();
33+
}
34+
#endif
1735
}
1836

1937

@@ -28,13 +46,23 @@ public void CreateServiceContainerOnce() {
2846
}
2947
[Test]
3048
public void GenerateGetService() {
31-
var serv = new TestService();
49+
var serv = new TestService();
50+
#if !WINUI
3251
var serviceContainer = new ServiceContainer(null);
3352
serviceContainer.RegisterService(serv, false);
34-
var serviceImpl = new GetServiceGenerate(serviceContainer);
35-
53+
#else
54+
var serviceContainer = new ServiceContainer();
55+
serviceContainer.Register(serv);
56+
#endif
57+
var serviceImpl = new GetServiceGenerate(serviceContainer);
58+
59+
#if !WINUI
3660
Assert.IsNotNull(serviceImpl.GetType().GetMethod(nameof(GetServiceGenerate.GetService)));
3761
Assert.AreEqual(serv, serviceImpl.GetService());
62+
#else
63+
Assert.IsNotNull(serviceImpl.GetType().GetMethod(nameof(GetServiceGenerate.GetUIService)));
64+
Assert.AreEqual(serv, serviceImpl.GetUIService());
65+
#endif
3866
}
3967

4068
}

0 commit comments

Comments
 (0)