예제 #1
0
 public void CanReserveIsConsistentAccrossReplays(Capacity sut, Guid id)
 {
     var remaining = sut.Remaining;
     sut.Reserve(remaining, id);
     var result = sut.CanReserve(remaining, id);
     Assert.True(result);
 }
예제 #2
0
        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.Reserve(requestWithinCapacity.ReserveCapacity());

            repositoryMock
                .Setup(r => r.Read(command.Date.Date))
                .Returns(new[] { newCapacity });

            sut.Consume(requestWithinCapacity);

            repositoryMock.Verify(r => r.Write(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());
        }
예제 #3
0
 public void ReserveReturnsEquivalentInstanceWhenReplayed(Guid id, int quantity, Capacity sut)
 {
     var expected = sut.Reserve(quantity, id);
     var result = sut.Reserve(quantity, id);
     Assert.Equal(expected, result);
 }
예제 #4
0
 public void ReserveDoesNotThrowWhenQuantityIsLessThanRemaining(Capacity sut, Guid id)
 {
     var lesserQuantity = sut.Remaining - 1;
     Assert.DoesNotThrow(() =>
         sut.Reserve(lesserQuantity, id));
 }
예제 #5
0
 public void ReserveDoesNotThrowWhenQuantityIsEqualToRemaining(Capacity sut, Guid id)
 {
     Assert.DoesNotThrow(() =>
         sut.Reserve(sut.Remaining, id));
 }
예제 #6
0
 public void ReserveDoesNotHaveSideEffects(Guid id, int quantity, Capacity sut)
 {
     var result = sut.Reserve(quantity, id);
     Assert.NotEqual(result, sut);
 }
예제 #7
0
 public void ReserveThrowsWhenQuantityIsGreaterThanRemaining(Capacity sut, Guid id)
 {
     var greaterQuantity = sut.Remaining + 1;
     Assert.Throws<ArgumentOutOfRangeException>(() =>
         sut.Reserve(greaterQuantity, id));
 }
예제 #8
0
 public void ReserveReturnsInstanceWithWithoutDecrementingRemainingWhenIdAlreadyExists([Frozen]Guid[] ids, int quantity, Capacity sut)
 {
     var existingId = ids.First();
     var expectedRemaining = sut.Remaining;
     var result = sut.Reserve(quantity, existingId);
     Assert.Equal(expectedRemaining, result.Remaining);
 }
예제 #9
0
 public void ReserveReturnsInstanceWithCorrectlyDecrementedRemaining(Guid id, int quantity, Capacity sut)
 {
     var expected = sut.Remaining - quantity;
     var result = sut.Reserve(quantity, id);
     Assert.Equal(expected, result.Remaining);
 }