public void ReserveReturnsEquivalentInstanceWhenReplayed( CapacityReservedEvent @event, Capacity sut) { var expected = sut.Apply(@event); var actual = sut.Apply(@event); Assert.Equal(expected, actual); }
public void ApplyThrowsOnUnknownMessage( Capacity sut, IMessage unknownMessage) { Assert.Throws <ArgumentException>(() => sut.Apply(unknownMessage)); }
public void ReserveDoesNotHaveSideEffects( RequestReservationCommand request, CapacityReservedEvent @event, Capacity sut) { var actual = sut.Apply(@event); Assert.NotEqual(actual, sut); }
public void ReserveDoesNotThrowWhenQuantityIsEqualToRemaining( Capacity sut, RequestReservationCommand command) { var request = command.WithQuantity(sut.Remaining); var @event = request.ReserveCapacity(); Assert.DoesNotThrow(() => sut.Apply(@event)); }
public void ReserveReturnsInstanceWithWithoutDecrementingRemainingWhenRequestWasAlreadyAccepted( RequestReservationCommand request, CapacityReservedEvent @event, Capacity sut) { var expected = sut.Apply(@event); var actual = expected.Apply(@event); Assert.Equal(expected, actual); }
public void ReserveThrowsWhenQuantityIsGreaterThanRemaining( Capacity sut, RequestReservationCommand command) { var greaterQuantity = sut.Remaining + 1; var request = command.WithQuantity(greaterQuantity); var @event = request.ReserveCapacity(); Assert.Throws <ArgumentOutOfRangeException>(() => sut.Apply(@event)); }
public void ReserveDoesNotThrowWhenQuantityIsLessThanRemaining( Capacity sut, RequestReservationCommand command) { var lesserQuantity = sut.Remaining - 1; var request = command.WithQuantity(lesserQuantity); var @event = request.ReserveCapacity(); Assert.DoesNotThrow(() => sut.Apply(@event)); }
public void ReserveReturnsInstanceWithCorrectlyDecrementedRemaining( int quantity, Capacity sut, RequestReservationCommand command) { var expected = sut.Remaining - quantity; var @event = command.WithQuantity(quantity).ReserveCapacity(); Capacity actual = sut.Apply(@event); Assert.Equal(expected, actual.Remaining); }
public void CanReserveIsConsistentAccrossReplays( Capacity initial, RequestReservationCommand command) { var remaining = initial.Remaining; var request = command.WithQuantity(remaining); var @event = request.ReserveCapacity(); var sut = initial.Apply(@event); var result = sut.CanApply(@event); Assert.True(result); }
public void ConsumeDoesNotForwardReplayedEvent( [Frozen]Mock<ICapacityRepository> repositoryMock, [Frozen]Mock<IChannel<CapacityReservedEvent>> capacityChannelMock, [Frozen]Mock<IChannel<SoldOutEvent>> soldOutChannelMock, CapacityGate sut, RequestReservationCommand command, Capacity originalCapacity) { var requestWithinCapacity = command.WithQuantity(originalCapacity.Remaining - 1); var newCapacity = originalCapacity.Apply(requestWithinCapacity.ReserveCapacity()); repositoryMock .Setup(r => r.Read(command.Date.Date)) .Returns(newCapacity.ToMaybe()); sut.Consume(requestWithinCapacity); repositoryMock.Verify(r => r.Append(requestWithinCapacity.Date.Date, It.IsAny<CapacityReservedEvent>()), Times.Never()); capacityChannelMock.Verify(r => r.Send(It.IsAny<CapacityReservedEvent>()), Times.Never()); soldOutChannelMock.Verify(r => r.Send(It.IsAny<SoldOutEvent>()), Times.Never()); }
public void ConsumeDoesNotForwardReplayedEvent( [Frozen] Mock <ICapacityRepository> repositoryMock, [Frozen] Mock <IChannel <CapacityReservedEvent> > capacityChannelMock, [Frozen] Mock <IChannel <SoldOutEvent> > soldOutChannelMock, CapacityGate sut, RequestReservationCommand command, Capacity originalCapacity) { var requestWithinCapacity = command.WithQuantity(originalCapacity.Remaining - 1); var newCapacity = originalCapacity.Apply(requestWithinCapacity.ReserveCapacity()); repositoryMock .Setup(r => r.Read(command.Date.Date)) .Returns(newCapacity.ToMaybe()); sut.Execute(requestWithinCapacity); repositoryMock.Verify(r => r.Append(requestWithinCapacity.Date.Date, It.IsAny <CapacityReservedEvent>()), Times.Never()); capacityChannelMock.Verify(r => r.Send(It.IsAny <CapacityReservedEvent>()), Times.Never()); soldOutChannelMock.Verify(r => r.Send(It.IsAny <SoldOutEvent>()), Times.Never()); }