PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/hereyes/ninject.extensions.interception
C# | 51 lines | 45 code | 6 blank | 0 comment | 0 complexity | 1960f8dca58428e075fb209585049460 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 Ninject.Extensions.Interception.Interceptors;
  7. using Xunit;
  8. public abstract class InterceptionSyntaxContext<TInterceptionModule> : InterceptionTestContext<TInterceptionModule>
  9. where TInterceptionModule : InterceptionModule, new()
  10. {
  11. protected override StandardKernel CreateDefaultInterceptionKernel()
  12. {
  13. StandardKernel kernel = base.CreateDefaultInterceptionKernel();
  14. kernel.Bind<ViewModel>().ToSelf().Intercept().With<FlagInterceptor>();
  15. return kernel;
  16. }
  17. [Fact]
  18. public void Doo()
  19. {
  20. FlagInterceptor.Reset();
  21. using (StandardKernel kernel = this.CreateDefaultInterceptionKernel())
  22. {
  23. var mock = kernel.Get<ViewModel>();
  24. mock.Address = "|ad";
  25. FlagInterceptor.WasCalled.Should().BeTrue();
  26. }
  27. }
  28. [Fact]
  29. public void CanAttachMultipleInterceptors()
  30. {
  31. FlagInterceptor.Reset();
  32. CountInterceptor.Reset();
  33. using (StandardKernel kernel = this.CreateDefaultInterceptionKernel())
  34. {
  35. var binding = kernel.Bind<FooImpl>().ToSelf();
  36. binding.Intercept().With<FlagInterceptor>();
  37. binding.Intercept().With<CountInterceptor>();
  38. var foo = kernel.Get<FooImpl>();
  39. foo.Foo();
  40. FlagInterceptor.WasCalled.Should().BeTrue();
  41. CountInterceptor.Count.Should().Be(1);
  42. }
  43. }
  44. }
  45. }