PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Ninject.Extensions.Interception.Test/AutoNotifyPropertyMethodInterceptorContext.cs

https://github.com/hereyes/ninject.extensions.interception
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
  1. namespace Ninject.Extensions.Interception
  2. {
  3. using FluentAssertions;
  4. using Ninject.Extensions.Interception.Fakes;
  5. using Xunit;
  6. public abstract class AutoNotifyPropertyMethodInterceptorContext<TInterceptionModule>
  7. : AutoNotifyPropertyChangedContext<TInterceptionModule>
  8. where TInterceptionModule : InterceptionModule, new()
  9. {
  10. public AutoNotifyPropertyMethodInterceptorContext()
  11. {
  12. LastPropertyToChange = null;
  13. ViewModel = Kernel.Get<ViewModel>();
  14. ViewModel.PropertyChanged += ( o, e ) =>
  15. {
  16. LastPropertyToChange = e.PropertyName;
  17. PropertyChanges.Add( LastPropertyToChange );
  18. };
  19. }
  20. public ViewModel ViewModel { get; set; }
  21. [Fact]
  22. public void WhenValueChangesOnPropertyWithoutNotifyAttribute_ItShouldNotNotify()
  23. {
  24. ViewModel.Address = "123 Main Street";
  25. LastPropertyToChange.Should().BeNull();
  26. }
  27. [Fact]
  28. public void WhenValueChangesOnPropertyWithDependentProperties_ItShouldNotifyAllChanges()
  29. {
  30. ViewModel.ZipCode = 9700;
  31. PropertyChanges[0].Should().Be("ZipCode");
  32. PropertyChanges[1].Should().Be("City");
  33. PropertyChanges[2].Should().Be("State");
  34. }
  35. [Fact]
  36. public void WhenPropertyGetterIsCalled_ItShouldNotBeIntercepted()
  37. {
  38. int zip = ViewModel.ZipCode;
  39. zip.Should().Be(0);
  40. LastPropertyToChange.Should().BeNull();
  41. }
  42. }
  43. }