|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.ComponentModel.DataAnnotations; |
| 6 | +using CommunityToolkit.Mvvm.ComponentModel; |
| 7 | +using CommunityToolkit.Mvvm.Input; |
| 8 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 9 | + |
| 10 | +namespace CommunityToolkit.Mvvm.UnitTests; |
| 11 | + |
| 12 | +/// <summary> |
| 13 | +/// This class contains general unit tests for source generators, without a specific dependency on one. |
| 14 | +/// For instance, this can be used for tests that validate common generation helpers used by all generators. |
| 15 | +/// </summary> |
| 16 | +[TestClass] |
| 17 | +public partial class Test_SourceGenerators |
| 18 | +{ |
| 19 | + [TestMethod] |
| 20 | + public void Test_SourceGenerators_NestedTypesThatAreNotJustClasses() |
| 21 | + { |
| 22 | + // This test just needs to compile, mostly |
| 23 | + NestedStructType.NestedInterfaceType.MyViewModel model = new(); |
| 24 | + |
| 25 | + Assert.IsNull(model.Name); |
| 26 | + Assert.IsTrue(model.TestCommand is IRelayCommand); |
| 27 | + } |
| 28 | + |
| 29 | + public partial struct NestedStructType |
| 30 | + { |
| 31 | + public partial interface NestedInterfaceType |
| 32 | + { |
| 33 | + [ObservableRecipient] |
| 34 | + public partial class MyViewModel : ObservableValidator |
| 35 | + { |
| 36 | + [ObservableProperty] |
| 37 | + [Required] |
| 38 | + private string? name; |
| 39 | + |
| 40 | + [ICommand] |
| 41 | + private void Test() |
| 42 | + { |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + [TestMethod] |
| 49 | + public void Test_SourceGenerators_NestedTypesThatAreNotJustClassesAndWithGenerics() |
| 50 | + { |
| 51 | + // This test just needs to compile, mostly |
| 52 | + NestedStructTypeWithGenerics<int, float>.NestedInterfaceType<string>.MyViewModel model = new(); |
| 53 | + |
| 54 | + Assert.IsNull(model.Name); |
| 55 | + Assert.IsTrue(model.TestCommand is IRelayCommand); |
| 56 | + } |
| 57 | + |
| 58 | + public partial struct NestedStructTypeWithGenerics<T1, T2> |
| 59 | + where T2 : struct |
| 60 | + { |
| 61 | + public partial interface NestedInterfaceType<TFoo> |
| 62 | + { |
| 63 | + [INotifyPropertyChanged] |
| 64 | + public partial class MyViewModel |
| 65 | + { |
| 66 | + [ObservableProperty] |
| 67 | + private string? name; |
| 68 | + |
| 69 | + [ICommand] |
| 70 | + private void Test() |
| 71 | + { |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments