Example #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);
 }
        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());
        }
Example #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);
 }
Example #4
0
 public void ReserveDoesNotThrowWhenQuantityIsLessThanRemaining(Capacity sut, Guid id)
 {
     var lesserQuantity = sut.Remaining - 1;
     Assert.DoesNotThrow(() =>
         sut.Reserve(lesserQuantity, id));
 }
Example #5
0
 public void ReserveDoesNotThrowWhenQuantityIsEqualToRemaining(Capacity sut, Guid id)
 {
     Assert.DoesNotThrow(() =>
         sut.Reserve(sut.Remaining, id));
 }
Example #6
0
 public void ReserveDoesNotHaveSideEffects(Guid id, int quantity, Capacity sut)
 {
     var result = sut.Reserve(quantity, id);
     Assert.NotEqual(result, sut);
 }
Example #7
0
 public void ReserveThrowsWhenQuantityIsGreaterThanRemaining(Capacity sut, Guid id)
 {
     var greaterQuantity = sut.Remaining + 1;
     Assert.Throws<ArgumentOutOfRangeException>(() =>
         sut.Reserve(greaterQuantity, id));
 }
Example #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);
 }
Example #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);
 }