コード例 #1
0
        public void InterceptWithInstanceAndPredicate_InterceptingATransient_ResultsInATransientProxy()
        {
            // Arrange
            var container = new Container();

            var interceptor = new FakeInterceptor();

            container.Register <ICommand, FakeCommand>();

            container.InterceptWith(interceptor, IsACommandPredicate);

            // Act
            var command1 = container.GetInstance <ICommand>();
            var command2 = container.GetInstance <ICommand>();

            // Assert
            Assert.IsFalse(object.ReferenceEquals(command1, command2), "The proxy is expected to " +
                           "be transient, since the interceptee is transient.");
        }
コード例 #2
0
        public void InterceptWithFuncAndPredicate_InterceptingASingleton_ResultsInATransientProxy()
        {
            // Arrange
            var container = new Container();

            var interceptor = new FakeInterceptor();

            container.Register <ICommand, FakeCommand>(Lifestyle.Singleton);

            container.InterceptWith(() => interceptor, IsACommandPredicate);

            // Act
            var command1 = container.GetInstance <ICommand>();
            var command2 = container.GetInstance <ICommand>();

            // Assert
            Assert.IsFalse(object.ReferenceEquals(command1, command2), "The proxy is expected to " +
                           "be transient, since the interceptor is created using a Func<T>, and there is no way to " +
                           "determine whether the delegate always returns the same or a new instance.");
        }
コード例 #3
0
        public void InterceptWithInstanceAndPredicate_InterceptingASingleton_ResultsInASingletonProxy()
        {
            // Arrange
            var container = ContainerFactory.New();

            var interceptor = new FakeInterceptor();

            container.Register <ICommand, FakeCommand>(Lifestyle.Singleton);

            container.InterceptWith(interceptor, IsACommandPredicate);

            // Act
            var command1 = container.GetInstance <ICommand>();
            var command2 = container.GetInstance <ICommand>();

            // Assert
            Assert.IsTrue(object.ReferenceEquals(command1, command2), "The proxy is expected to " +
                          "be singleton, because both the interceptee and the interceptor are singletons, which " +
                          "makes it useless to create a new (expensive) proxy for them on each request.");
        }
コード例 #4
0
        public void InterceptWithFuncAndPredicate_InterceptingASingleton_ResultsInATransientProxy()
        {
            // Arrange
            var container = new Container();

            var interceptor = new FakeInterceptor();

            container.Register<ICommand, FakeCommand>(Lifestyle.Singleton);

            container.InterceptWith(() => interceptor, IsACommandPredicate);

            // Act
            var command1 = container.GetInstance<ICommand>();
            var command2 = container.GetInstance<ICommand>();

            // Assert
            Assert.IsFalse(object.ReferenceEquals(command1, command2), "The proxy is expected to " +
                "be transient, since the interceptor is created using a Func<T>, and there is no way to " +
                "determine whether the delegate always returns the same or a new instance.");
        }
コード例 #5
0
        public void InterceptWithInstanceAndPredicate_InterceptingASingleton_ResultsInASingletonProxy()
        {
            // Arrange
            var container = ContainerFactory.New();

            var interceptor = new FakeInterceptor();

            container.Register<ICommand, FakeCommand>(Lifestyle.Singleton);

            container.InterceptWith(interceptor, IsACommandPredicate);

            // Act
            var command1 = container.GetInstance<ICommand>();
            var command2 = container.GetInstance<ICommand>();

            // Assert
            Assert.IsTrue(object.ReferenceEquals(command1, command2), "The proxy is expected to " +
                "be singleton, because both the interceptee and the interceptor are singletons, which " +
                "makes it useless to create a new (expensive) proxy for them on each request.");
        }
コード例 #6
0
        public void InterceptWithInstanceAndPredicate_InterceptingATransient_ResultsInATransientProxy()
        {
            // Arrange
            var container = new Container();

            var interceptor = new FakeInterceptor();

            container.Register<ICommand, FakeCommand>();

            container.InterceptWith(interceptor, IsACommandPredicate);

            // Act
            var command1 = container.GetInstance<ICommand>();
            var command2 = container.GetInstance<ICommand>();

            // Assert
            Assert.IsFalse(object.ReferenceEquals(command1, command2), "The proxy is expected to " +
                "be transient, since the interceptee is transient.");
        }
 public void Setup()
 {
     _statsDClient = new Mock<IVeStatsDClient>();
     _interceptor = new FakeInterceptor<StatsDTiming>(_statsDClient.Object);
 }
 public void Setup()
 {
     _statsDClient = new Mock <IVeStatsDClient>();
     _interceptor  = new FakeInterceptor <StatsDTiming>(_statsDClient.Object);
 }