/src/Ninject.Extensions.Interception.Test/InterceptionSyntaxContext.cs
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
- namespace Ninject.Extensions.Interception
- {
- using FluentAssertions;
- using Ninject.Extensions.Interception.Fakes;
- using Ninject.Extensions.Interception.Infrastructure.Language;
- using Ninject.Extensions.Interception.Interceptors;
- using Xunit;
-
- public abstract class InterceptionSyntaxContext<TInterceptionModule> : InterceptionTestContext<TInterceptionModule>
- where TInterceptionModule : InterceptionModule, new()
- {
- protected override StandardKernel CreateDefaultInterceptionKernel()
- {
- StandardKernel kernel = base.CreateDefaultInterceptionKernel();
- kernel.Bind<ViewModel>().ToSelf().Intercept().With<FlagInterceptor>();
- return kernel;
- }
- [Fact]
- public void Doo()
- {
- FlagInterceptor.Reset();
- using (StandardKernel kernel = this.CreateDefaultInterceptionKernel())
- {
- var mock = kernel.Get<ViewModel>();
- mock.Address = "|ad";
- FlagInterceptor.WasCalled.Should().BeTrue();
- }
- }
- [Fact]
- public void CanAttachMultipleInterceptors()
- {
- FlagInterceptor.Reset();
- CountInterceptor.Reset();
- using (StandardKernel kernel = this.CreateDefaultInterceptionKernel())
- {
- var binding = kernel.Bind<FooImpl>().ToSelf();
- binding.Intercept().With<FlagInterceptor>();
- binding.Intercept().With<CountInterceptor>();
- var foo = kernel.Get<FooImpl>();
- foo.Foo();
- FlagInterceptor.WasCalled.Should().BeTrue();
- CountInterceptor.Count.Should().Be(1);
- }
- }
- }
- }