Exemple #1
0
 private AttributeDefinition()
 {
     Type                 = typeof(NoAttribute);
     AttributeValue       = new NoAttribute();
     _attributeNameGetter = language => language.Attributes.None;
     Xml = null;
 }
        public void ShouldLogToNullWhenAttributeMissing()
        {
            NoAttribute instance = new NoAttribute();

            IInvocation invocation = Substitute.For <IInvocation>();

            invocation.Request.Target.Returns(instance);
            MethodInfo method = typeof(NoAttribute).GetMethod("DoSomething");

            invocation.Request.Method.Returns(method);
            invocation.When(i => i.Proceed()).Do(i => instance.DoSomething());

            ILogger logger = Substitute.For <ILogger>();
            IKernel kernel = new StandardKernel();

            kernel.Bind <ILogger>().ToConstant(logger);
            invocation.Request.Kernel.Returns(kernel);

            LogInterceptor interceptor = new LogInterceptor();

            interceptor.Intercept(invocation);

            logger.Received().Trace("null", "Entering {0}.{1}", typeof(NoAttribute), "DoSomething");
            logger.Received().Trace("null", "Exiting {0}.{1}", typeof(NoAttribute), "DoSomething");
        }
        public void HasAttribute_DoesNotHaveAttribute_Throws()
        {
            var underTest = new NoAttribute();

            Assert.ThrowsException <TypeArgumentException>(() =>
                                                           underTest.Require(nameof(underTest)).HasAttribute(typeof(SerializableAttribute)));
        }
        public void ShouldNotCreateTransactionIfMissingAttribute()
        {
            NoAttribute instance = new NoAttribute();

            IInvocation invocation = Substitute.For<IInvocation>();
            invocation.Request.Target.Returns(instance);
            MethodInfo method = typeof(NoAttribute).GetMethod("DoSomething");
            invocation.Request.Method.Returns(method);
            invocation.When(i => i.Proceed()).Do(i => instance.DoSomething());

            TransactionInterceptor interceptor = new TransactionInterceptor();
            interceptor.Intercept(invocation);

            Assert.IsFalse(instance.HadTransaction, "There should be no active transaction.");
        }
Exemple #5
0
        public void ShouldNotCreateTransactionIfMissingAttribute()
        {
            NoAttribute instance = new NoAttribute();

            IInvocation invocation = Substitute.For <IInvocation>();

            invocation.Request.Target.Returns(instance);
            MethodInfo method = typeof(NoAttribute).GetMethod("DoSomething");

            invocation.Request.Method.Returns(method);
            invocation.When(i => i.Proceed()).Do(i => instance.DoSomething());

            TransactionInterceptor interceptor = new TransactionInterceptor();

            interceptor.Intercept(invocation);

            Assert.IsFalse(instance.HadTransaction, "There should be no active transaction.");
        }
        public void ShouldLogToNullWhenAttributeMissing()
        {
            NoAttribute instance = new NoAttribute();

            IInvocation invocation = Substitute.For<IInvocation>();
            invocation.Request.Target.Returns(instance);
            MethodInfo method = typeof(NoAttribute).GetMethod("DoSomething");
            invocation.Request.Method.Returns(method);
            invocation.When(i => i.Proceed()).Do(i => instance.DoSomething());

            ILogger logger = Substitute.For<ILogger>();
            IKernel kernel = new StandardKernel();
            kernel.Bind<ILogger>().ToConstant(logger);
            invocation.Request.Kernel.Returns(kernel);

            LogInterceptor interceptor = new LogInterceptor();
            interceptor.Intercept(invocation);

            logger.Received().Trace("null", "Entering {0}.{1}", typeof(NoAttribute), "DoSomething");
            logger.Received().Trace("null", "Exiting {0}.{1}", typeof(NoAttribute), "DoSomething");
        }