예제 #1
0
        public void ReserveReturnsEquivalentInstanceWhenReplayed(
            CapacityReservedEvent @event,
            Capacity sut)
        {
            var expected = sut.Apply(@event);
            var actual   = sut.Apply(@event);

            Assert.Equal(expected, actual);
        }
예제 #2
0
 public void ApplyThrowsOnUnknownMessage(
     Capacity sut,
     IMessage unknownMessage)
 {
     Assert.Throws <ArgumentException>(() =>
                                       sut.Apply(unknownMessage));
 }
예제 #3
0
        public void ReserveDoesNotHaveSideEffects(
            RequestReservationCommand request,
            CapacityReservedEvent @event,
            Capacity sut)
        {
            var actual = sut.Apply(@event);

            Assert.NotEqual(actual, sut);
        }
예제 #4
0
        public void ReserveDoesNotThrowWhenQuantityIsEqualToRemaining(
            Capacity sut,
            RequestReservationCommand command)
        {
            var request = command.WithQuantity(sut.Remaining);
            var @event  = request.ReserveCapacity();

            Assert.DoesNotThrow(() =>
                                sut.Apply(@event));
        }
예제 #5
0
        public void ReserveReturnsInstanceWithWithoutDecrementingRemainingWhenRequestWasAlreadyAccepted(
            RequestReservationCommand request,
            CapacityReservedEvent @event,
            Capacity sut)
        {
            var expected = sut.Apply(@event);
            var actual   = expected.Apply(@event);

            Assert.Equal(expected, actual);
        }
예제 #6
0
        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));
        }
예제 #7
0
        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));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
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.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());
        }
예제 #11
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.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());
        }