/src/Ninject.Extensions.Interception.Test/AutoNotifyPropertyDetectChangesInterceptorContext.cs
C# | 76 lines | 67 code | 9 blank | 0 comment | 0 complexity | 16a38c05253dec2721787a673579854d MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
- namespace Ninject.Extensions.Interception
- {
- using FluentAssertions;
- using Ninject.Extensions.Interception.Fakes;
- using Xunit;
-
- public abstract class AutoNotifyPropertyDetectChangesInterceptorContext<TInterceptionModule>
- : AutoNotifyPropertyChangedContext<TInterceptionModule>
- where TInterceptionModule : InterceptionModule, new()
- {
- public AutoNotifyPropertyDetectChangesInterceptorContext()
- {
- ViewModel = Kernel.Get<ViewModel>();
- ViewModel.PropertyChanged += (o, e) =>
- {
- LastPropertyToChange = e.PropertyName;
- PropertyChanges.Add(LastPropertyToChange);
- };
- ComplexViewModel = Kernel.Get<ComplexViewModel>();
- ComplexViewModel.PropertyChanged += (o, e) =>
- {
- LastPropertyToChange = e.PropertyName;
- PropertyChanges.Add(LastPropertyToChange);
- };
- }
- public ViewModel ViewModel { get; set; }
- public ComplexViewModel ComplexViewModel { get; set; }
- [Fact]
- public void WhenValueAssignedIsTheSameAsTheCurrentValue_ItShouldNotNotify()
- {
- ViewModel.ZipCode = 0;
- LastPropertyToChange.Should().BeNull();
- }
- [Fact]
- public void WhenValueAssignedIsTheSameAsTheCurrentComplexValue_ItShouldNotNotify()
- {
- var value = new ComplexType();
- ComplexViewModel.Complex = value; // initialize
- LastPropertyToChange.Should().Be("Complex");
- LastPropertyToChange = null;
- var newValue = new ComplexType();
- ComplexViewModel.Complex = newValue; // test
- LastPropertyToChange.Should().BeNull();
- }
- [Fact]
- public void WhenValueAssignedIsNotTheSameAsTheCurrentComplexValue_ItShouldNotNotify()
- {
- var value = new ComplexType();
- ComplexViewModel.Complex = value; // initialize
- LastPropertyToChange.Should().Be("Complex");
- LastPropertyToChange = null;
- var newValue = new ComplexType {Name = "Foo"};
- ComplexViewModel.Complex = newValue; // test
- LastPropertyToChange.Should().Be("Complex");
- }
- [Fact]
- public void WhenPropertySubValueAssignedIsNotTheSameAsTheCurrentComplexValue_ItShouldNotNotify()
- {
- var value = new ComplexType();
- ComplexViewModel.Complex = value; // initialize
- LastPropertyToChange.Should().Be("Complex");
- LastPropertyToChange = null;
- var newValue = new ComplexType {Simple = new SimpleType {Id = 5}};
- ComplexViewModel.Complex = newValue; // test
- LastPropertyToChange.Should().Be("Complex");
- }
- }
- }