PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/hereyes/ninject.extensions.interception
C# | 52 lines | 42 code | 10 blank | 0 comment | 0 complexity | 29a095f5d3309787e201e418cf911b71 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. #if !SILVERLIGHT
  2. namespace Ninject.Extensions.Interception
  3. {
  4. using FluentAssertions;
  5. using Ninject.Extensions.Interception.Fakes;
  6. using Ninject.Extensions.Interception.Infrastructure.Language;
  7. using Xunit;
  8. public class PropertyInterceptionContextLinfFu : PropertyInterceptionContext<LinFuModule>
  9. {
  10. [Fact]
  11. public void PropertySetInterceptedBefore()
  12. {
  13. using (StandardKernel kernel = CreateDefaultInterceptionKernel())
  14. {
  15. kernel.InterceptBeforeSet<Mock>(
  16. o => o.MyProperty,
  17. i => i.Request.Arguments[0] = "intercepted");
  18. var obj = kernel.Get<Mock>();
  19. obj.MyProperty.Should().Be("start");
  20. obj.MyProperty = "end";
  21. obj.MyProperty.Should().Be("intercepted");
  22. }
  23. }
  24. [Fact]
  25. public void PropertySetInterceptedAfter()
  26. {
  27. string testString = "empty";
  28. using (StandardKernel kernel = CreateDefaultInterceptionKernel())
  29. {
  30. kernel.InterceptAfterSet<Mock>(
  31. o => o.MyProperty,
  32. i => testString = ((Mock)i.Request.Target).MyProperty);
  33. var obj = kernel.Get<Mock>();
  34. obj.MyProperty.Should().Be("start");
  35. obj.MyProperty = "end";
  36. obj.MyProperty.Should().Be("end");
  37. testString.Should().Be("end");
  38. }
  39. }
  40. }
  41. }
  42. #endif