Beispiel #1
0
        public async Task WhenNoReservations_ReturnForRentalDates()
        {
            var availableDates = await this.sut.Handle(new GetAvailableDatesQuery()
            {
                ApartmentId = this.data.Apartment.Id
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.All(
                availableDates,
                date => Assert.Contains(this.data.ForRentalDates, frd => DateTimeHelpers.AreSameDay(frd.Date, date)));
        }
Beispiel #2
0
 public async Task <IActionResult> Complete(long id)
 {
     return(await this.UpdateReservationAsync(id, ReservationStates.Completed, (args) =>
     {
         var endDate = args.ReservationStartDate.AddDays(args.NumberOfNightsRented);
         var today = DateTime.Now;
         if (!DateTimeHelpers.AreSameDay(today, endDate) && today < endDate)
         {
             return false;
         }
         if (args.ReservationState != ReservationStates.Accepted)
         {
             return false;
         }
         return true;
     }));
 }
        private async Task ThrowIfApartmentIsUnavailable(CreateReservationCommand request, CancellationToken cancellationToken)
        {
            var availableDates = await this.mediator.Send(new GetAvailableDatesQuery()
            {
                ApartmentId = request.ApartmentId
            }, cancellationToken);

            var currDay = request.StartDate;

            for (int i = 0; i < request.NumberOfNights; ++i)
            {
                if (!availableDates.Any(d => DateTimeHelpers.AreSameDay(d, currDay)))
                {
                    string formatedDay = DateTimeHelpers.FormatToYearMonthDayString(currDay);
                    throw new ApartmentUnavailableException($"{formatedDay} is unavailable!");
                }
                currDay = currDay.AddDays(1);
            }
        }
Beispiel #4
0
        public async Task WhenReserved_ReturnAvailable()
        {
            this.data.Context.Add(new Reservation()
            {
                ApartmentId          = this.data.Apartment.Id,
                GuestId              = this.data.Guest.UserId,
                ReservationStartDate = this.data.MinDate,
                NumberOfNightsRented = 1,
                ReservationState     = ReservationStates.Accepted
            });

            this.data.Context.SaveChanges();

            var availableDates = await this.sut.Handle(new GetAvailableDatesQuery()
            {
                ApartmentId = this.data.Apartment.Id
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.All(
                availableDates,
                date => Assert.Contains(this.data.ForRentalDates.Skip(1), frd => DateTimeHelpers.AreSameDay(frd.Date, date)));
        }
 public bool Equals(DateTime dateTime)
 {
     return(DateTimeHelpers.AreSameDay(this.Date, dateTime));
 }