Skip to content

Commit

Permalink
#511 Add unit tests covering scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Dec 30, 2023
1 parent 2898de4 commit 131d562
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Catel.Fody.TestAssembly.Shared/Bugs/GH0511.cs
Original file line number Diff line number Diff line change
@@ -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}'");
}
}
}
}
25 changes: 25 additions & 0 deletions src/Catel.Fody.Tests.Shared/Repros/GH0511.cs
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}

0 comments on commit 131d562

Please sign in to comment.