Ejemplo n.º 1
0
        public void ThrowExceptionIfInnerAdviceCannotBeBuild()
        {
            //Arrange
            var testInvocation = new TestInvocation();
            var sut            = new LazyAdvice <TestAdviceWithoutParameterlessConstructor>(() => null);

            //Act + Assert
            Expect.WillThrow <CannotInstantiateAdviceException>(() => sut.ApplyAdvice(testInvocation), e => e.Message.Contains(typeof(TestAdviceWithoutParameterlessConstructor).Name));
        }
Ejemplo n.º 2
0
        public void CreateAndCallProceedOfInnerAdvice()
        {
            //Arrange
            var testInvocation = new TestInvocation();
            var mockedAdvice   = new Mock <IAdvice>();
            var sut            = new LazyAdvice <IAdvice>(() => mockedAdvice.Object);

            //Act
            sut.ApplyAdvice(testInvocation);

            //Assert
            mockedAdvice.Verify(x => x.ApplyAdvice(testInvocation), Times.Once());
        }
Ejemplo n.º 3
0
        public void Add <TAdvice>(IPointcut pointcut)
            where TAdvice : class, IAdvice
        {
            //All advices are registered in the IOC container, so we can easily let the container create our advices

            //LazyAdvice: at the moment of registering the advices, the IOC container itself might not be build up completely.
            //The LazyAdvice allows us to delay the creation of the required advice until the moment
            //that the advice is actually needed (and the IOC container is completely builded).
            var advice = new LazyAdvice <TAdvice>(ResolveAdvice <TAdvice>);

            Add(advice, pointcut);
            _blockedTypes.Add(typeof(TAdvice));
        }