Skip to content

Commit 414c837

Browse files
committed
Add unit test for base viewmodel in separate assembly
1 parent b52b427 commit 414c837

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 CommunityToolkit.Mvvm.ComponentModel;
6+
7+
namespace CommunityToolkit.Mvvm.ExternalAssembly;
8+
9+
/// <summary>
10+
/// Test viewmodel for https://github.com/CommunityToolkit/dotnet/issues/222.
11+
/// </summary>
12+
[ObservableObject]
13+
public partial class ModelWithObservableObjectAttribute
14+
{
15+
[ObservableProperty]
16+
private string? _myProperty;
17+
}

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Runtime.CompilerServices;
1212
using System.Threading.Tasks;
1313
using CommunityToolkit.Mvvm.ComponentModel;
14+
using CommunityToolkit.Mvvm.ExternalAssembly;
1415
using CommunityToolkit.Mvvm.Input;
1516
using CommunityToolkit.Mvvm.Messaging;
1617
using CommunityToolkit.Mvvm.Messaging.Messages;
@@ -569,6 +570,27 @@ public void Test_ObservableProperty_WithinGenericTypeWithMultipleTypeParameters(
569570
CollectionAssert.AreEqual(new[] { nameof(model.Value), nameof(model.TValue), nameof(model.UValue), nameof(model.List) }, propertyNames);
570571
}
571572

573+
// See https://github.com/CommunityToolkit/dotnet/issues/222
574+
[TestMethod]
575+
public void Test_ObservableProperty_WithBaseViewModelWithObservableObjectAttributeInAnotherAssembly()
576+
{
577+
ModelWithObservablePropertyAndBaseClassInAnotherAssembly model = new();
578+
579+
List<string?> propertyNames = new();
580+
581+
model.PropertyChanged += (s, e) => propertyNames.Add(e.PropertyName);
582+
583+
Assert.AreEqual(model.OtherProperty, "Ok");
584+
585+
model.MyProperty = "A";
586+
model.OtherProperty = "B";
587+
588+
Assert.AreEqual(model.MyProperty, "A");
589+
Assert.AreEqual(model.OtherProperty, "B");
590+
591+
CollectionAssert.AreEqual(new[] { nameof(model.MyProperty), nameof(model.OtherProperty) }, propertyNames);
592+
}
593+
572594
public abstract partial class BaseViewModel : ObservableObject
573595
{
574596
public string? Content { get; set; }
@@ -913,6 +935,17 @@ public class Bar<T>
913935
}
914936
#endif
915937

938+
partial class ModelWithObservablePropertyAndBaseClassInAnotherAssembly : ModelWithObservableObjectAttribute
939+
{
940+
[ObservableProperty]
941+
private string? _otherProperty;
942+
943+
public ModelWithObservablePropertyAndBaseClassInAnotherAssembly()
944+
{
945+
OtherProperty = "Ok";
946+
}
947+
}
948+
916949
interface IValueHolder
917950
{
918951
public bool Value { get; }

0 commit comments

Comments
 (0)