-
Notifications
You must be signed in to change notification settings - Fork 12
Microsoft Mvvm Toolkit support #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
VitalyTVA
wants to merge
21
commits into
22.1.1
Choose a base branch
from
22.1.2_MvvmToolkit
base: 22.1.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
53dcf3b
MvvmToolkit - GenerationUnitTests
VitalyTVA ff220bc
MvvmToolkit - diagnostics tests
VitalyTVA fad0b61
Reove duplicated code
VitalyTVA ff4a1fe
MvvmToolkit PropertyGenerationTests
VitalyTVA ccb8d8a
UpdateRaiseMtehod tests for MvvmToolkit + support OnPropertyChang[ed|…
VitalyTVA e920075
fix FirstOrDefaultError
VitalyTVA 4ee3787
MvvmToolkit - support only OnPropertyChang[ed|ing] methods
VitalyTVA a5e555b
fix simple warnings
VitalyTVA 36096ed
fix excessive interface generation in child classes if interface impl…
VitalyTVA b241253
MvvmToolkit interfaces and nullability tests
VitalyTVA 11ef1cc
Toolkit command generation tests
VitalyTVA 744366a
Toolkit attribute transfer tests
VitalyTVA c95cc6f
Toolit async commands generation
VitalyTVA 14939d2
GetParents instead for cycle
VitalyTVA ef7ed65
MvvmToolkit Broadcast option
VitalyTVA a6ad9a6
refactoring - remove duplicated code from tests
VitalyTVA 1ef30b7
MvvmToolkit Validate=true option support
VitalyTVA b0d8946
Update readme
VitalyTVA 5c13f68
Update readme - list supported mvvm frameworks
VitalyTVA bc8e09c
Fix typo in readme
VitalyTVA 93b0a0a
Code review fixes
VitalyTVA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
64 changes: 0 additions & 64 deletions
64
DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/MvvmLightTest/Helper.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/MvvmToolkit/AsyncCommandGenerationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using DevExpress.Mvvm.CodeGenerators.MvvmToolkit; | ||
using Microsoft.Toolkit.Mvvm.Input; | ||
|
||
namespace MvvmToolkit.Mvvm.Tests { | ||
[GenerateViewModel] | ||
partial class GenerateAsyncCommands { | ||
readonly Task<int> task = new(() => 1); | ||
[GenerateCommand] | ||
public Task WithNoArg() => Task.CompletedTask; | ||
[GenerateCommand] | ||
public Task WithArg(int arg) => Task.CompletedTask; | ||
[GenerateCommand] | ||
public Task WithNullableArg(int? arg) => Task.CompletedTask; | ||
public Task SomeMethod() => Task.CompletedTask; | ||
|
||
[GenerateCommand(Name = "MyAsyncCommand", CanExecuteMethod = "CanDoIt")] | ||
public Task Method(int arg) => Task.CompletedTask; | ||
public bool CanDoIt(int arg) => arg > 0; | ||
|
||
[GenerateCommand] | ||
public Task<int> GenericTask() => task; | ||
} | ||
|
||
[TestFixture] | ||
public class AsyncCommandGenerationTests { | ||
[Test] | ||
public void CallRequiredMethodForAsyncCommand() { | ||
var generated = new GenerateAsyncCommands(); | ||
|
||
var method = GetFieldValue<Action<int>, RelayCommand<int>>(generated.MyAsyncCommand, "execute"); | ||
StringAssert.Contains("MyAsyncCommand", method.Method.Name); | ||
|
||
var canMethod = GetFieldValue<Predicate<int>, RelayCommand<int>>(generated.MyAsyncCommand, "canExecute"); | ||
var expectedCanMethod = generated.GetType().GetMethod("CanDoIt").Name; | ||
Assert.AreEqual(expectedCanMethod, canMethod.Method.Name); | ||
|
||
var canExecuteMethod = GetFieldValue<Predicate<int>, RelayCommand>(generated.GenericTaskCommand, "canExecute"); | ||
Assert.IsNull(canExecuteMethod); | ||
} | ||
|
||
static TResult GetFieldValue<TResult, T>(T source, string fieldName) { | ||
var fieldInfo = source.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance); | ||
Assert.IsNotNull(fieldInfo); | ||
|
||
return (TResult)fieldInfo.GetValue(source); | ||
} | ||
[Test] | ||
public void AsyncCommandImplementation() { | ||
var generated = new GenerateAsyncCommands(); | ||
|
||
Assert.IsNotNull(generated.GetType().GetProperty("WithNoArgCommand")); | ||
Assert.IsNotNull(generated.GetType().GetProperty("WithArgCommand")); | ||
Assert.IsNotNull(generated.GetType().GetProperty("WithNullableArgCommand")); | ||
|
||
Assert.IsNull(generated.GetType().GetProperty("With2ArgsCommand")); | ||
Assert.IsNull(generated.GetType().GetProperty("ReturnNoTaskCommand")); | ||
Assert.IsNull(generated.GetType().GetProperty("SomeMethodCommand")); | ||
} | ||
|
||
[Test] | ||
public void ArgumentTypeForAsyncCommand() { | ||
var generated = new GenerateAsyncCommands(); | ||
|
||
var noArgumentType = generated.WithNoArgCommand.GetType(); | ||
Assert.IsEmpty(noArgumentType.GetGenericArguments()); | ||
var expectedType = typeof(RelayCommand); | ||
Assert.AreEqual(expectedType, noArgumentType); | ||
|
||
var intArgumentType = generated.WithArgCommand.GetType().GetGenericArguments()[0]; | ||
var intExpectedType = typeof(int); | ||
Assert.AreEqual(intExpectedType, intArgumentType); | ||
|
||
var nullableIntArgumentType = generated.WithNullableArgCommand.GetType().GetGenericArguments()[0]; | ||
var nullableIntExpectedType = typeof(int?); | ||
Assert.AreEqual(nullableIntExpectedType, nullableIntArgumentType); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
DevExpress.Mvvm.CodeGenerators.Tests/SharedTests/MvvmToolkit/AttributeTransferTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using DevExpress.Mvvm.CodeGenerators.Tests.Included; | ||
using NUnit.Framework; | ||
using System; | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
using DevExpress.Mvvm.CodeGenerators.MvvmToolkit; | ||
|
||
namespace MvvmToolkit.Mvvm.Tests { | ||
class MyCustomAttribute : Attribute { | ||
public MyCustomAttribute(int value, string str, bool condition, TestEnum testEnum) { } | ||
} | ||
namespace Included { | ||
enum TestEnum { | ||
Num = 1, | ||
String = 2 | ||
} | ||
} | ||
[GenerateViewModel] | ||
partial class AttributeTransfer { | ||
const int number = 1; | ||
|
||
[GenerateProperty] | ||
int noAttribute; | ||
|
||
[GenerateProperty, System.ComponentModel.DataAnnotations.Range(0, 1)] | ||
[Required, MyCustom(number, | ||
"Some string", | ||
true, TestEnum.Num)] | ||
int withMultipleAttributes; | ||
} | ||
|
||
[TestFixture] | ||
public class AttributeTransferTests { | ||
[Test] | ||
public void AttributeTransfer() { | ||
var noAttributeProperty = typeof(AttributeTransfer).GetProperty("NoAttribute"); | ||
var attributes = Attribute.GetCustomAttributes(noAttributeProperty); | ||
var expectedAttributes = new Attribute[] { }; | ||
Assert.AreEqual(expectedAttributes, attributes); | ||
|
||
var withMultipleAttributesProperty = typeof(AttributeTransfer).GetProperty("WithMultipleAttributes"); | ||
attributes = Attribute.GetCustomAttributes(withMultipleAttributesProperty); | ||
expectedAttributes = new Attribute[] { | ||
new System.ComponentModel.DataAnnotations.RangeAttribute(0, 1), | ||
new RequiredAttribute(), | ||
new MyCustomAttribute(1, "Some string", true, TestEnum.Num) | ||
}; | ||
Assert.AreEqual(expectedAttributes, attributes); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.