public void DisposeCalledForMultipleDisposableServicesCreatedByActivator()
        {
            var interceptorActivator = new DefaultGrpcInterceptorActivator <DisposableGrpcInterceptor>(Mock.Of <IServiceProvider>());
            var interceptor1         = (DisposableGrpcInterceptor)interceptorActivator.Create();
            var interceptor2         = (DisposableGrpcInterceptor)interceptorActivator.Create();
            var interceptor3         = (DisposableGrpcInterceptor)interceptorActivator.Create();

            interceptorActivator.Release(interceptor3);
            interceptorActivator.Release(interceptor2);
            interceptorActivator.Release(interceptor1);

            Assert.True(interceptor1.Disposed);
            Assert.True(interceptor2.Disposed);
            Assert.True(interceptor3.Disposed);
        }
Ejemplo n.º 2
0
        public void DisposeNotCalledForUndisposableServicesCreatedByActivator()
        {
            var interceptorActivator = new DefaultGrpcInterceptorActivator <GrpcInterceptor>(Mock.Of <IServiceProvider>());
            var interceptor          = (GrpcInterceptor)interceptorActivator.Create();

            interceptorActivator.Release(interceptor);

            Assert.False(interceptor.Disposed);
        }
Ejemplo n.º 3
0
        public void Release_MultipleDisposableCreatedByActivator_DisposeCalled()
        {
            // Arrange
            var interceptorRegistration = CreateRegistration <DisposableGrpcInterceptor>();

            var interceptorActivator = new DefaultGrpcInterceptorActivator <DisposableGrpcInterceptor>();
            var interceptorHandle1   = interceptorActivator.Create(Mock.Of <IServiceProvider>(), interceptorRegistration);
            var interceptorHandle2   = interceptorActivator.Create(Mock.Of <IServiceProvider>(), interceptorRegistration);
            var interceptorHandle3   = interceptorActivator.Create(Mock.Of <IServiceProvider>(), interceptorRegistration);

            // Act
            interceptorActivator.Release(interceptorHandle3);
            interceptorActivator.Release(interceptorHandle2);
            interceptorActivator.Release(interceptorHandle1);

            // Assert
            Assert.True(((DisposableGrpcInterceptor)interceptorHandle1.Instance).Disposed);
            Assert.True(((DisposableGrpcInterceptor)interceptorHandle2.Instance).Disposed);
            Assert.True(((DisposableGrpcInterceptor)interceptorHandle3.Instance).Disposed);
        }
Ejemplo n.º 4
0
        public void Release_NonDisposableCreatedByActivator_DisposeNotCalled()
        {
            // Arrange
            var interceptorActivator = new DefaultGrpcInterceptorActivator <GrpcInterceptor>();
            var interceptorHandle    = interceptorActivator.Create(Mock.Of <IServiceProvider>(), CreateRegistration <GrpcInterceptor>());
            var interceptorInstance  = (GrpcInterceptor)interceptorHandle.Instance;

            // Act
            interceptorActivator.Release(interceptorHandle);

            // Assert
            Assert.False(interceptorInstance.Disposed);
        }
Ejemplo n.º 5
0
        public void DisposeNotCalledForServicesResolvedFromServiceProvider()
        {
            var mockServiceProvider = new Mock <IServiceProvider>();

            mockServiceProvider
            .Setup(sp => sp.GetService(typeof(DisposableGrpcInterceptor)))
            .Returns(() =>
            {
                return(new DisposableGrpcInterceptor());
            });

            var interceptorActivator = new DefaultGrpcInterceptorActivator <DisposableGrpcInterceptor>(mockServiceProvider.Object);
            var interceptor          = (DisposableGrpcInterceptor)interceptorActivator.Create();

            interceptorActivator.Release(interceptor);

            Assert.False(interceptor.Disposed);
        }
Ejemplo n.º 6
0
        public void Release_ResolvedFromServiceProvider_DisposeNotCalled()
        {
            // Arrange
            var mockServiceProvider = new Mock <IServiceProvider>();

            mockServiceProvider
            .Setup(sp => sp.GetService(typeof(DisposableGrpcInterceptor)))
            .Returns(() =>
            {
                return(new DisposableGrpcInterceptor());
            });

            var interceptorActivator = new DefaultGrpcInterceptorActivator <DisposableGrpcInterceptor>();
            var interceptorHandle    = interceptorActivator.Create(mockServiceProvider.Object, CreateRegistration <DisposableGrpcInterceptor>());
            var interceptorInstance  = (DisposableGrpcInterceptor)interceptorHandle.Instance;

            // Act
            interceptorActivator.Release(interceptorHandle);

            // Assert
            Assert.False(interceptorInstance.Disposed);
        }