Ejemplo n.º 1
0
        public void ConsumeAcceptsRequestWithinDefaultCapacityWhenRepositoryReturnsNoCapacity(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<ReservationAcceptedEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command)
        {
            repositoryStub
                .Setup(r => r.Read(command.Date.Date))
                .Returns(Maybe.Empty<Capacity>());

            sut.Consume(command.WithQuantity(Capacity.Default.Remaining));

            channelMock.Verify(c => c.Send(It.IsAny<ReservationAcceptedEvent>()));
        }
Ejemplo n.º 2
0
        public void ConsumeDoesNotSendReservedEventWhenCapacityIsExceeded(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<CapacityReservedEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryStub
                .Setup(r => r.Read(command.Date.Date))
                .Returns(capacity.ToMaybe());

            sut.Consume(command.WithQuantity(capacity.Remaining + 1));

            channelMock.Verify(c => c.Send(It.IsAny<CapacityReservedEvent>()), Times.Never());
        }
Ejemplo n.º 3
0
        public void ConsumeDoesNotSendRejectEventWhenRequestIsWithinCapacity(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<ReservationRejectedEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryStub
                .Setup(r => r.Read(command.Date.Date))
                .Returns(new[] { capacity });

            sut.Consume(command.WithQuantity(capacity.Remaining));

            channelMock.Verify(c => c.Send(It.IsAny<ReservationRejectedEvent>()), Times.Never());
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
0
        public void ConsumeSendsSoldOutEventWhenSoldOut(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<SoldOutEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryStub
                .Setup(r => r.Read(command.Date.Date))
                .Returns(capacity.ToMaybe());

            sut.Consume(command.WithQuantity(capacity.Remaining));

            var expected = command.Date.Date;
            channelMock.Verify(c => c.Send(It.Is<SoldOutEvent>(e => e.Date == expected)));
        }
Ejemplo n.º 6
0
        public void ConsumeSendsRejectEventWhenRequestExceedsCapacity(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<ReservationRejectedEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryStub
                .Setup(r => r.Read(command.Date.Date))
                .Returns(capacity.ToMaybe());

            var requestExceedingCapacity = command.WithQuantity(capacity.Remaining + 1);
            sut.Consume(requestExceedingCapacity);

            var expected = requestExceedingCapacity.Reject().Id;
            channelMock.Verify(c => c.Send(It.Is<ReservationRejectedEvent>(e => e.Id == expected)));
        }
Ejemplo n.º 7
0
        public void ConsumeRequestWithEnoughCapacitySendsCorrectEvent(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<ReservationAcceptedEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryStub
                .Setup(r => r.Read(It.IsAny<DateTime>()))
                .Returns(capacity.ToMaybe());

            sut.Consume(command);

            var expected = command.Accept().Id;
            channelMock.Verify(c => c.Send(It.Is<ReservationAcceptedEvent>(e => e.Id == expected)));
        }
Ejemplo n.º 8
0
        public void ConsumeDoesNotWriteEventToRepositoryWhenCapacityIsExceeded(
            [Frozen]Mock<ICapacityRepository> repositoryMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryMock
                .Setup(r => r.Read(command.Date.Date))
                .Returns(capacity.ToMaybe());

            sut.Consume(command.WithQuantity(capacity.Remaining + 1));

            repositoryMock.Verify(r => r.Append(command.Date.Date, It.IsAny<CapacityReservedEvent>()), Times.Never());
        }
Ejemplo n.º 9
0
        public void ConsumeDoesNotSendSoldOutWhenNotSoldOut(
            [Frozen]Mock<ICapacityRepository> repositoryStub,
            [Frozen]Mock<IChannel<SoldOutEvent>> channelMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryStub
                .Setup(r => r.Read(command.Date.Date))
                .Returns(capacity.ToMaybe());

            sut.Execute(command.WithQuantity(capacity.Remaining - 1));

            channelMock.Verify(r => r.Send(It.IsAny<SoldOutEvent>()), Times.Never());
        }
 public void EnvelopReturnsCorrectBody(RequestReservationCommand sut)
 {
     var actual = sut.Envelop();
     Assert.Equal(sut, actual.Body);
 }
 public void NameIsCorrect([Frozen]string expected, RequestReservationCommand sut)
 {
     Assert.Equal<string>(expected, sut.Name);
 }
 public void QuantityIsCorrect([Frozen]int expected, RequestReservationCommand sut)
 {
     Assert.Equal<int>(expected, sut.Quantity);
 }
 public void IdIsUnique(RequestReservationCommand sut, RequestReservationCommand other)
 {
     Assert.NotEqual(sut.Id, other.Id);
 }
 public void IdIsStable(RequestReservationCommand sut)
 {
     Assert.Equal(sut.Id, sut.Id);
 }
 public void EnvelopReturnsCorrectVersion(RequestReservationCommand sut)
 {
     var actual = sut.Envelop();
     Assert.Equal("1", actual.Version);
 }
Ejemplo n.º 16
0
        public void ConsumeWritesEventToRepositoryWhenCapacityIsAvailable(
            [Frozen]Mock<ICapacityRepository> repositoryMock,
            CapacityGate sut,
            RequestReservationCommand command,
            Capacity capacity)
        {
            repositoryMock
                .Setup(r => r.Read(command.Date.Date))
                .Returns(capacity.ToMaybe());

            var requestWithinCapacity = command.WithQuantity(capacity.Remaining - 1);
            sut.Consume(requestWithinCapacity);

            var expected = requestWithinCapacity.ReserveCapacity().Id;
            repositoryMock.Verify(r => r.Append(requestWithinCapacity.Date.Date, It.Is<CapacityReservedEvent>(e => e.Id == expected)));
        }
        public void WithQuantityReturnsCorrectResult(RequestReservationCommand sut,
            int newQuantity)
        {
            RequestReservationCommand actual = sut.WithQuantity(newQuantity);

            sut.AsSource().OfLikeness<RequestReservationCommand>()
                .With(d => d.Quantity).EqualsWhen((s, d) => d.Quantity == newQuantity)
                .Without(d => d.Id)
                .ShouldEqual(actual);
        }
        public void RejectReturnsCorrectResult(RequestReservationCommand sut)
        {
            ReservationRejectedEvent actual = sut.Reject();

            sut.AsSource().OfLikeness<ReservationRejectedEvent>().ShouldEqual(actual);
        }
 public void DateIsCorrect([Frozen]DateTime expected, RequestReservationCommand sut)
 {
     Assert.Equal<DateTime>(expected, sut.Date);
 }
        public void ReserveCapacityReturnsCorrectResult(RequestReservationCommand sut)
        {
            CapacityReservedEvent actual = sut.ReserveCapacity();

            sut.AsSource().OfLikeness<CapacityReservedEvent>()
                .ShouldEqual(actual);
        }
 public void SutIsMessage(RequestReservationCommand sut)
 {
     Assert.IsAssignableFrom<IMessage>(sut);
 }