예제 #1
0
        public void Interceptor_should_be_fired_on_Delete()
        {
            // Arrange
            var mockRepository = CreateSampleEntityRepositoryMock();

            this.Container.RegisterInstance <IRepository>(mockRepository.Object);

            TestOperationInterceptor interceptor = new TestOperationInterceptor();

            var mockInterceptorFactory = new Mock <IInterceptorFactory>();

            mockInterceptorFactory
            .Setup(f => f.CreateOperationInterceptor(typeof(TestOperationInterceptor)))
            .Returns(interceptor);

            this.Container.RegisterInstance <IInterceptorFactory>(mockInterceptorFactory.Object);

            var extendedRepository = this.Container.Resolve <IExtendedRepository>();

            // Act
            SampleEntity newEntity = new SampleEntity()
            {
                Id = 1
            };

            extendedRepository.Delete(newEntity);

            // Assert
            Assert.IsNotNull(interceptor.LastDeletingEntity);
            Assert.AreEqual(newEntity, interceptor.LastDeletingEntity);

            Assert.IsNotNull(interceptor.LastDeletedEntity);
            Assert.AreEqual(newEntity, interceptor.LastDeletedEntity);
        }
예제 #2
0
        public void Interceptor_scope_is_set_on_Insert()
        {
            // Arrange
            var mockRepository = CreateSampleEntityRepositoryMock();

            this.Container.RegisterInstance <IRepository>(mockRepository.Object);

            TestOperationInterceptor interceptor = new TestOperationInterceptor();

            var mockInterceptorFactory = new Mock <IInterceptorFactory>();

            mockInterceptorFactory
            .Setup(f => f.CreateOperationInterceptor(typeof(TestOperationInterceptor)))
            .Returns(interceptor);

            this.Container.RegisterInstance <IInterceptorFactory>(mockInterceptorFactory.Object);

            var extendedRepository = this.Container.Resolve <IExtendedRepository>();

            // Act
            SampleEntity newEntity = new SampleEntity();

            extendedRepository.Insert(newEntity);

            // Assert
            Assert.IsInstanceOfType(interceptor.PublicScope, typeof(TestScope));
        }