PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/hereyes/ninject.extensions.interception
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
  1. namespace Ninject.Extensions.Interception
  2. {
  3. using FluentAssertions;
  4. using Ninject.Extensions.Interception.Fakes;
  5. using Xunit;
  6. public abstract class AutoNotifyPropertyDetectChangesInterceptorContext<TInterceptionModule>
  7. : AutoNotifyPropertyChangedContext<TInterceptionModule>
  8. where TInterceptionModule : InterceptionModule, new()
  9. {
  10. public AutoNotifyPropertyDetectChangesInterceptorContext()
  11. {
  12. ViewModel = Kernel.Get<ViewModel>();
  13. ViewModel.PropertyChanged += (o, e) =>
  14. {
  15. LastPropertyToChange = e.PropertyName;
  16. PropertyChanges.Add(LastPropertyToChange);
  17. };
  18. ComplexViewModel = Kernel.Get<ComplexViewModel>();
  19. ComplexViewModel.PropertyChanged += (o, e) =>
  20. {
  21. LastPropertyToChange = e.PropertyName;
  22. PropertyChanges.Add(LastPropertyToChange);
  23. };
  24. }
  25. public ViewModel ViewModel { get; set; }
  26. public ComplexViewModel ComplexViewModel { get; set; }
  27. [Fact]
  28. public void WhenValueAssignedIsTheSameAsTheCurrentValue_ItShouldNotNotify()
  29. {
  30. ViewModel.ZipCode = 0;
  31. LastPropertyToChange.Should().BeNull();
  32. }
  33. [Fact]
  34. public void WhenValueAssignedIsTheSameAsTheCurrentComplexValue_ItShouldNotNotify()
  35. {
  36. var value = new ComplexType();
  37. ComplexViewModel.Complex = value; // initialize
  38. LastPropertyToChange.Should().Be("Complex");
  39. LastPropertyToChange = null;
  40. var newValue = new ComplexType();
  41. ComplexViewModel.Complex = newValue; // test
  42. LastPropertyToChange.Should().BeNull();
  43. }
  44. [Fact]
  45. public void WhenValueAssignedIsNotTheSameAsTheCurrentComplexValue_ItShouldNotNotify()
  46. {
  47. var value = new ComplexType();
  48. ComplexViewModel.Complex = value; // initialize
  49. LastPropertyToChange.Should().Be("Complex");
  50. LastPropertyToChange = null;
  51. var newValue = new ComplexType {Name = "Foo"};
  52. ComplexViewModel.Complex = newValue; // test
  53. LastPropertyToChange.Should().Be("Complex");
  54. }
  55. [Fact]
  56. public void WhenPropertySubValueAssignedIsNotTheSameAsTheCurrentComplexValue_ItShouldNotNotify()
  57. {
  58. var value = new ComplexType();
  59. ComplexViewModel.Complex = value; // initialize
  60. LastPropertyToChange.Should().Be("Complex");
  61. LastPropertyToChange = null;
  62. var newValue = new ComplexType {Simple = new SimpleType {Id = 5}};
  63. ComplexViewModel.Complex = newValue; // test
  64. LastPropertyToChange.Should().Be("Complex");
  65. }
  66. }
  67. }