/src/Ninject.Extensions.Interception.Test/AutoNotifyPropertyMethodInterceptorContext.cs
C# | 51 lines | 43 code | 8 blank | 0 comment | 0 complexity | c2958f80a991d3953a2cae5e3541514e 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 AutoNotifyPropertyMethodInterceptorContext<TInterceptionModule>
- : AutoNotifyPropertyChangedContext<TInterceptionModule>
- where TInterceptionModule : InterceptionModule, new()
- {
- public AutoNotifyPropertyMethodInterceptorContext()
- {
- LastPropertyToChange = null;
- ViewModel = Kernel.Get<ViewModel>();
- ViewModel.PropertyChanged += ( o, e ) =>
- {
- LastPropertyToChange = e.PropertyName;
- PropertyChanges.Add( LastPropertyToChange );
- };
- }
- public ViewModel ViewModel { get; set; }
- [Fact]
- public void WhenValueChangesOnPropertyWithoutNotifyAttribute_ItShouldNotNotify()
- {
- ViewModel.Address = "123 Main Street";
- LastPropertyToChange.Should().BeNull();
- }
- [Fact]
- public void WhenValueChangesOnPropertyWithDependentProperties_ItShouldNotifyAllChanges()
- {
- ViewModel.ZipCode = 9700;
- PropertyChanges[0].Should().Be("ZipCode");
- PropertyChanges[1].Should().Be("City");
- PropertyChanges[2].Should().Be("State");
- }
- [Fact]
- public void WhenPropertyGetterIsCalled_ItShouldNotBeIntercepted()
- {
- int zip = ViewModel.ZipCode;
- zip.Should().Be(0);
- LastPropertyToChange.Should().BeNull();
- }
- }
- }