public void BeginsLifetimeScope_WhenCurrentLifetimeScope_IsNull() { var command = new FakeCommandWithValidator(); var decorated = new Mock<IHandleCommand<FakeCommandWithValidator>>(MockBehavior.Strict); decorated.Setup(x => x.Handle(command)).Returns(Task.FromResult(0)); var decorator = new CommandLifetimeScopeDecorator<FakeCommandWithValidator>(Container, () => decorated.Object); Container.GetCurrentLifetimeScope().ShouldEqual(null); decorator.Handle(command); Container.GetCurrentLifetimeScope().ShouldEqual(null); decorated.Verify(x => x.Handle(command), Times.Once); }
public void BeginsLifetimeScope_WhenCurrentLifetimeScope_IsNull() { var command = new FakeCommandWithValidator(); var decorated = new Mock<IHandleCommand<FakeCommandWithValidator>>(MockBehavior.Strict); decorated.Setup(x => x.Handle(command)); var decorator = new CommandLifetimeScopeDecorator<FakeCommandWithValidator>(_fixture.Container, () => decorated.Object); Assert.Equal(null, _fixture.Container.GetCurrentLifetimeScope()); decorator.Handle(command); Assert.Equal(null, _fixture.Container.GetCurrentLifetimeScope()); decorated.Verify(x => x.Handle(command), Times.Once); }
public void BeginsLifetimeScope_WhenCurrentLifetimeScope_IsNull() { var command = new FakeCommandWithValidator(); var decorated = new Mock <IHandleCommand <FakeCommandWithValidator> >(MockBehavior.Strict); decorated.Setup(x => x.Handle(command)).Returns(Task.FromResult(0)); var decorator = new CommandLifetimeScopeDecorator <FakeCommandWithValidator>(_fixture.Container, () => decorated.Object); Assert.Equal(null, _fixture.Container.GetCurrentLifetimeScope()); decorator.Handle(command); Assert.Equal(null, _fixture.Container.GetCurrentLifetimeScope()); decorated.Verify(x => x.Handle(command), Times.Once); }
public void Handle_HasCurrentLifetimeScope_ShouldHandleCommand( [Frozen] Mock<IContainer> container, [Frozen] Mock<ICommandHandler<ICommand>> commandHandler, ICommand command, CommandLifetimeScopeDecorator<ICommand> decorator) { // Act decorator.Handle(command); // Assert commandHandler.Verify(h => h.Handle(command), Times.Once); container.Verify(c => c.BeginLifetimeScope(), Times.Never); }
public void Handle_HasNoCurrentLifetimeScope_ShouldBeginNewLifetimeScopeBeforeHandleCommand( [Frozen] Mock<IContainer> container, [Frozen] Mock<ICommandHandler<ICommand>> commandHandler, ICommand command, CommandLifetimeScopeDecorator<ICommand> decorator) { // Arrange var callOrder = 0; container.Setup(c => c.GetCurrentLifetimeScope()).Returns(null); container.Setup(c => c.BeginLifetimeScope()).Callback(() => callOrder++.Should().Be(0)); commandHandler.Setup(c => c.Handle(command)).Callback(() => callOrder++.Should().Be(1)); // Act decorator.Handle(command); // Assert container.Verify(c => c.BeginLifetimeScope(), Times.Once); commandHandler.Verify(h => h.Handle(command), Times.Once); }