예제 #1
0
        public async Task the_assigned_room_can_be_changed()
        {
            // Given
            var reservationId = ReservationId.New;
            var reservation   = new Reservation(reservationId);
            var roomId1       = Room.RoomId.New;

            reservation.Apply(GetValidReservationCreatedEvent(reservationId));
            reservation.Apply(new RoomAssigned(reservationId, roomId1));

            var roomId2 = Room.RoomId.New;
            var handler = new AssignRoomHandler();

            // When
            var result = await handler.ExecuteCommandAsync(
                reservation,
                new AssignRoom(reservationId, roomId2),
                CancellationToken.None);

            // Then
            Assert.True(result.IsSuccess);
            var uncommittedEvents = reservation.UncommittedEvents.ToArray();
            var assignRoomEvent   = (RoomAssigned)uncommittedEvents.Single().AggregateEvent;

            Assert.Equal(roomId2, assignRoomEvent.RoomId);
        }
예제 #2
0
        public async Task cannot_assign_the_room_before_checkin_and_checkout_times_are_known()
        {
            // Given
            var reservationId = ReservationId.New;
            var reservation   = new Reservation(reservationId);
            var roomId        = Room.RoomId.New;

            var handler = new AssignRoomHandler();

            // When
            var result = await handler.ExecuteCommandAsync(reservation,
                                                           new AssignRoom(reservationId, roomId),
                                                           CancellationToken.None);

            // Then
            Assert.False(result.IsSuccess);
            Assert.Equal(
                $"unexpected state: {Reservation.State.Prospective}",
                ((FailedExecutionResult)result).Errors.Single());
        }