public void WhenDisposingScopeFromDeepestRequestThenScopesAreDisposed() { // Arrange Mock <ICommand> command = new Mock <ICommand>(); HandlerRequest request = new CommandHandlerRequest(this.defaultConfig, command.Object); HandlerRequest innerRequest = new CommandHandlerRequest(this.defaultConfig, command.Object, request); Mock <IDependencyResolver> resolver = new Mock <IDependencyResolver>(MockBehavior.Strict); int disposedCount = 0; resolver .Setup(r => r.BeginScope()) .Returns(() => CreateVerifiableScopeMock(() => disposedCount++)); resolver .Setup(r => r.Dispose()); this.defaultConfig.DependencyResolver = resolver.Object; request.GetDependencyScope(); innerRequest.GetDependencyScope(false); // Act & Assert Assert.Equal(0, disposedCount); innerRequest.Dispose(); Assert.Equal(1, disposedCount); request.Dispose(); Assert.Equal(2, disposedCount); }
public void WhenDisposingThenScopeIsDisposed() { // Arrange Mock <ICommand> command = new Mock <ICommand>(); HandlerRequest request = new CommandHandlerRequest(this.defaultConfig, command.Object); Mock <IDependencyScope> scope = new Mock <IDependencyScope>(MockBehavior.Strict); scope.Setup(s => s.Dispose()); Mock <IDependencyResolver> resolver = new Mock <IDependencyResolver>(MockBehavior.Strict); resolver .Setup(r => r.BeginScope()) .Returns(scope.Object); resolver .Setup(r => r.Dispose()); this.defaultConfig.DependencyResolver = resolver.Object; request.GetDependencyScope(); // Act request.Dispose(); // Assert scope.Verify(s => s.Dispose(), Times.Once()); }