From 131d5628f688e76f17279e972cb90152e89034bc Mon Sep 17 00:00:00 2001 From: Geert van Horrik Date: Sat, 30 Dec 2023 13:34:42 +0100 Subject: [PATCH] #511 Add unit tests covering scenario --- .../Bugs/GH0511.cs | 32 +++++++++++++++++++ src/Catel.Fody.Tests.Shared/Repros/GH0511.cs | 25 +++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Catel.Fody.TestAssembly.Shared/Bugs/GH0511.cs create mode 100644 src/Catel.Fody.Tests.Shared/Repros/GH0511.cs diff --git a/src/Catel.Fody.TestAssembly.Shared/Bugs/GH0511.cs b/src/Catel.Fody.TestAssembly.Shared/Bugs/GH0511.cs new file mode 100644 index 0000000..6eba00e --- /dev/null +++ b/src/Catel.Fody.TestAssembly.Shared/Bugs/GH0511.cs @@ -0,0 +1,32 @@ +namespace Catel.Fody.TestAssembly.Bugs.GH0511 +{ + using Catel.Data; + using Catel.MVVM; + + public class AppSettingsModel : ModelBase + { + public string SelectedThemeName { get; set; } + } + + public class AppSettingsViewModel : ViewModelBase + { + public AppSettingsViewModel(AppSettingsModel appSettings) + { + AppSettings = appSettings; + } + + public string ExpectedValue { get; set; } + + [Model] + [Expose("SelectedThemeName")] + public AppSettingsModel AppSettings { get; set; } + + private void OnSelectedThemeNameChanged() + { + if (AppSettings.SelectedThemeName != ExpectedValue) + { + throw new System.Exception($"Unexpected value '{AppSettings.SelectedThemeName}'"); + } + } + } +} diff --git a/src/Catel.Fody.Tests.Shared/Repros/GH0511.cs b/src/Catel.Fody.Tests.Shared/Repros/GH0511.cs new file mode 100644 index 0000000..d83cff4 --- /dev/null +++ b/src/Catel.Fody.Tests.Shared/Repros/GH0511.cs @@ -0,0 +1,25 @@ +namespace Catel.Fody.Tests.Repros +{ + using System; + using Catel.Reflection; + using NUnit.Framework; + + [TestFixture] + public class GH0511TestFixture + { + [TestCase] + public void Raises_PropertyChanged_With_Updated_Value() + { + var modelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.Bugs.GH0511.AppSettingsModel"); + var model = Activator.CreateInstance(modelType); + + var viewModelType = AssemblyWeaver.Instance.Assembly.GetType("Catel.Fody.TestAssembly.Bugs.GH0511.AppSettingsViewModel"); + var viewModel = Activator.CreateInstance(viewModelType, model) as dynamic; + viewModel.ExpectedValue = "test"; + + PropertyHelper.SetPropertyValue(model, "SelectedThemeName", "test"); + + Assert.That(viewModel.AppSettings.SelectedThemeName, Is.EqualTo("test")); + } + } +}