public async Task TestOnNew()
    {
        var cmd = new Commands.BookRoom(
            Auto.Create <string>(),
            Auto.Create <string>(),
            LocalDate.FromDateTime(DateTime.Today),
            LocalDate.FromDateTime(DateTime.Today.AddDays(2)),
            Auto.Create <decimal>()
            );

        var expected = new Change[] {
            new(new RoomBooked(cmd.BookingId, cmd.RoomId, cmd.CheckIn, cmd.CheckOut, cmd.Price), "RoomBooked")
        };

        var result = await Service.Handle(cmd, default);

        result.Success.Should().BeTrue();
        result.Changes.Should().BeEquivalentTo(expected);

        var evt = await EventStore.ReadEvents(
            GetStreamName(new BookingId(cmd.BookingId)),
            StreamReadPosition.Start,
            1,
            CancellationToken.None
            );

        evt[0].Payload.Should().BeEquivalentTo(result.Changes !.First().Event);
    }
    public async Task TestOnExisting()
    {
        var cmd = new Commands.BookRoom(
            Auto.Create <string>(),
            Auto.Create <string>(),
            LocalDate.FromDateTime(DateTime.Today),
            LocalDate.FromDateTime(DateTime.Today.AddDays(2)),
            Auto.Create <decimal>()
            );

        await Service.Handle(cmd, default);

        var secondCmd = new Commands.RecordPayment(cmd.BookingId, Auto.Create <string>(), cmd.Price);

        var expected = new Change[] {
            new(
                new BookingPaymentRegistered(secondCmd.BookingId, secondCmd.PaymentId, secondCmd.Amount),
                "PaymentRegistered"
                ),
            new(new BookingFullyPaid(secondCmd.BookingId), "BookingFullyPaid")
        };

        var result = await Service.Handle(secondCmd, default);

        result.Success.Should().BeTrue();
        result.Changes.Should().BeEquivalentTo(expected);

        var evt = await EventStore.ReadEvents(
            GetStreamName(new BookingId(cmd.BookingId)),
            StreamReadPosition.Start,
            100,
            CancellationToken.None
            );

        evt.Skip(1)
        .Select(x => x.Payload)
        .Should()
        .BeEquivalentTo(expected.Select(x => x.Event));
    }
Example #3
0
        public async Task StoreInitial()
        {
            var cmd = new Commands.BookRoom(
                Auto.Create <string>(),
                Auto.Create <string>(),
                LocalDate.FromDateTime(DateTime.Today),
                LocalDate.FromDateTime(DateTime.Today.AddDays(2)),
                Auto.Create <decimal>()
                );

            var expected = new object[] {
                new BookingEvents.RoomBooked(
                    cmd.BookingId,
                    cmd.RoomId,
                    cmd.CheckIn,
                    cmd.CheckOut,
                    cmd.Price
                    )
            };

            var result = await Service.Handle(cmd, default);

            result.Changes.Should().BeEquivalentTo(expected);
        }