PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/hereyes/ninject.extensions.interception
C# | 49 lines | 40 code | 9 blank | 0 comment | 0 complexity | cfc1106a02d722910aa1b7982f6bc7ec 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 Ninject.Extensions.Interception.Infrastructure.Language;
  6. using Xunit;
  7. public class PropertyInterceptionContextDynamicProxy2 : PropertyInterceptionContext<DynamicProxyModule>
  8. {
  9. [Fact]
  10. public void PropertySetInterceptedBefore()
  11. {
  12. using (var kernel = CreateDefaultInterceptionKernel())
  13. {
  14. kernel.InterceptBeforeSet<Mock>(
  15. o => o.MyProperty,
  16. i => i.Request.Arguments[0] = "intercepted");
  17. var obj = kernel.Get<Mock>();
  18. obj.Should().NotBeNull();
  19. obj.MyProperty = "end";
  20. obj.MyProperty.Should().Be("intercepted");
  21. }
  22. }
  23. [Fact]
  24. public void PropertySetInterceptedAfter()
  25. {
  26. string testString = "empty";
  27. using (var kernel = CreateDefaultInterceptionKernel())
  28. {
  29. kernel.InterceptAfterSet<Mock>(
  30. o => o.MyProperty,
  31. i => testString = ((Mock)i.Request.Target).MyProperty);
  32. var obj = kernel.Get<Mock>();
  33. obj.MyProperty.Should().Be("start");
  34. obj.MyProperty = "end";
  35. obj.MyProperty.Should().Be("end");
  36. testString.Should().Be("end");
  37. }
  38. }
  39. }
  40. }