Beispiel #1
0
        public async Task occupy_room_succeeds_if_room_was_not_occupied()
        {
            // Given
            var irrelevantRoomId        = Room.RoomId.New;
            var irrelevantReservationId = ReservationId.New;
            var irrelevantRange         = new Range(
                DateTime.UtcNow.AddDays(-3),
                DateTime.UtcNow.AddDays(3));

            var room    = new Room(irrelevantRoomId);
            var handler = new OccupyRoomHandler();

            // When
            var result = await handler.ExecuteCommandAsync(
                room,
                new OccupyRoom(irrelevantRoomId, irrelevantReservationId, irrelevantRange),
                CancellationToken.None);

            // Then
            Assert.True(result.IsSuccess);

            var uncommittedEvents = room.UncommittedEvents.ToArray();

            Assert.Single(uncommittedEvents);

            Assert.IsType <RoomOccupied>(uncommittedEvents[0].AggregateEvent);
            var roomOccupiedEvent = (RoomOccupied)uncommittedEvents[0].AggregateEvent;

            Assert.Equal(irrelevantRange.Start, roomOccupiedEvent.StartDateUtc);
            Assert.Equal(irrelevantRange.End, roomOccupiedEvent.EndDateUtc);
        }
Beispiel #2
0
        public async Task occupy_room_fails_if_room_was_already_occupied(
            string requestedDateRangeStartDate,
            string requestedDateRangeEndDate,
            string alreadyOccupiedDateRangeStartDate,
            string alreadyOccupiedDateRangeEndDate)
        {
            // Given
            var irrelevantRoomId = Room.RoomId.New;
            var irrelevantPreviousReservationId = ReservationId.New;
            var irrelevantNewReservationId      = ReservationId.New;

            var requestedDateRange = new Range(
                DateTime.ParseExact(requestedDateRangeStartDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                DateTime.ParseExact(requestedDateRangeEndDate, "yyyy-MM-dd", CultureInfo.InvariantCulture));

            var irrelevantPreviousOccupiedEvent = new RoomOccupied(
                irrelevantPreviousReservationId,
                DateTime.ParseExact(alreadyOccupiedDateRangeStartDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                DateTime.ParseExact(alreadyOccupiedDateRangeEndDate, "yyyy-MM-dd", CultureInfo.InvariantCulture));

            var room    = new Room(irrelevantRoomId);
            var handler = new OccupyRoomHandler();

            room.Apply(irrelevantPreviousOccupiedEvent);

            // When
            var result = await handler.ExecuteCommandAsync(
                room,
                new OccupyRoom(irrelevantRoomId, irrelevantNewReservationId, requestedDateRange),
                CancellationToken.None);

            // Then
            Assert.False(result.IsSuccess);
            Assert.Empty(room.UncommittedEvents);

            Assert.Equal(
                $"Room already occupied",
                ((FailedExecutionResult)result).Errors.Single());
        }