Exemplo n.º 1
0
        public void WrapInterfaceDoesImplementIWrapper(CastleDynamicProxyFactory sut, IEnumerable <IAlternateMethod> methodInvocations)
        {
            var result = sut.WrapInterface <ITestProxy>(new TestProxy(), methodInvocations);

            var resultAsWrapper = result as IWrapper <ITestProxy>;

            Assert.NotNull(resultAsWrapper);
        }
Exemplo n.º 2
0
        public void ImplementIWrapper(CastleDynamicProxyFactory sut, IDisposable instance, IEnumerable <IAlternateMethod> methodInvocations)
        {
            var result = sut.WrapInterface(instance, methodInvocations);

            var resultAsWrapper = result as IWrapper <IDisposable>;

            Assert.NotNull(resultAsWrapper);
            Assert.Equal(instance, resultAsWrapper.GetWrappedObject());
        }
Exemplo n.º 3
0
        public void WrapInterfaceCreatesWrappingProxy(ILogger logger, IMessageBroker messageBroker)
        {
            var timer = new ExecutionTimer(Stopwatch.StartNew());

            var sut = new CastleDynamicProxyFactory(logger, messageBroker, () => timer, () => RuntimePolicy.On);

            var overrideMeAlternate = new OverrideMeAlternateMethod <ITestProxy>();

            var methodInvocations = new List <IAlternateMethod> {
                overrideMeAlternate
            };

            var target = new TestProxy();
            var result = sut.WrapInterface <ITestProxy>(target, methodInvocations);

            result.OverrideMe();

            Assert.Equal(1, overrideMeAlternate.HitCount);
            Assert.Equal(1, result.HitCountOverrideMe);
            Assert.Equal(1, result.HitCountProtectedOverrideMe);
            Assert.Equal(1, target.HitCountOverrideMe);
            Assert.Equal(1, target.HitCountProtectedOverrideMe);
        }