// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel.DataAnnotations;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#pragma warning disable MVVMTK0032
namespace CommunityToolkit.Mvvm.UnitTests;
///
/// This class contains general unit tests for source generators, without a specific dependency on one.
/// For instance, this can be used for tests that validate common generation helpers used by all generators.
///
[TestClass]
public partial class Test_SourceGenerators
{
[TestMethod]
public void Test_SourceGenerators_NestedTypesThatAreNotJustClasses()
{
// This test just needs to compile, mostly
NestedStructType.NestedInterfaceType.NestedRecord.MyViewModel model = new();
Assert.IsNull(model.Name);
Assert.IsTrue(model.TestCommand is IRelayCommand);
}
public partial struct NestedStructType
{
public partial interface NestedInterfaceType
{
public partial record NestedRecord
{
[ObservableRecipient]
public partial class MyViewModel : ObservableValidator
{
[ObservableProperty]
[Required]
private string? name;
[RelayCommand]
private void Test()
{
}
}
}
}
}
[TestMethod]
public void Test_SourceGenerators_NestedTypesThatAreNotJustClassesAndWithGenerics()
{
// This test just needs to compile, mostly
NestedStructTypeWithGenerics.NestedInterfaceType.NestedRecord.MyViewModel model = new();
Assert.IsNull(model.Name);
Assert.IsTrue(model.TestCommand is IRelayCommand);
}
public partial struct NestedStructTypeWithGenerics
where T2 : struct
{
public partial interface NestedInterfaceType
{
public partial record NestedRecord
{
[INotifyPropertyChanged]
public partial class MyViewModel
{
[ObservableProperty]
private string? name;
[RelayCommand]
private void Test()
{
}
}
}
}
}
}