public void MakeBooking_CheckSavingPromoCode() { BookingEntity saveOutput = null; var repo = new Mock <IRepository <BookingEntity> >(); repo.Setup(x => x.GetAll()).Returns((new List <BookingEntity>()).AsQueryable()); repo.Setup(x => x.Save(It.IsAny <BookingEntity>())).Callback <BookingEntity>(x => saveOutput = x); var costEvaluationServiceMock = new Mock <ICostEvaluationService>(); costEvaluationServiceMock.Setup(x => x.EvaluateBookingCost(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>())) .Returns(new BookingCostDto { TotalCost = 100, PromoCode = new PromoCodeInfoDto { Id = 100500 } }); var bookingService = new BookingService(repo.Object, null, costEvaluationServiceMock.Object, null, _dateService); var bookingInfo = new MakeBookingInfoDto { Date = DateTime.UtcNow.Date, From = 13, To = 15 }; bookingService.MakeBooking(bookingInfo, new CurrentUser { Phone = "1" }); Assert.AreEqual(100500, saveOutput.PromoCodeId); }
public void MakeBooking_CheckSaving() { BookingEntity saveOutput = null; var repo = new Mock <IRepository <BookingEntity> >(); repo.Setup(x => x.GetAll()).Returns((new List <BookingEntity>()).AsQueryable()); repo.Setup(x => x.Save(It.IsAny <BookingEntity>())).Callback <BookingEntity>(x => saveOutput = x); var bookingService = new BookingService(repo.Object, null, _costEvaluationService, null, _dateService); var bookingInfo = new MakeBookingInfoDto { Date = DateTime.UtcNow.Date, From = 13, To = 15 }; bookingService.MakeBooking(bookingInfo, new CurrentUser { Phone = "1", UserId = "SomeUser" }); Assert.AreEqual(DateTime.UtcNow.Date.AddHours(13), saveOutput.From); Assert.AreEqual(DateTime.UtcNow.Date.AddHours(16), saveOutput.To); Assert.AreEqual(BookingStatusEnum.Unpaid, saveOutput.Status); Assert.IsNotNull(saveOutput.Guid); Assert.AreEqual(100, saveOutput.Cost); Assert.AreEqual("SomeUser", saveOutput.UserId); Assert.AreEqual(null, saveOutput.PromoCodeId); }
public BookingCostDto Cost(MakeBookingInfoDto makeBookingInfo) { Validate(); DateTime from = makeBookingInfo.GetFromDateTime(); DateTime to = makeBookingInfo.GetToDateTime(); return(_costEvaluationService.EvaluateBookingCost(from, to, makeBookingInfo.PromoCode)); }
public int Make(MakeBookingInfoDto makeBookingInfo) { Validate(); int bookingId = _bookingService.MakeBooking(makeBookingInfo, GetUser()); _logger.LogInformation($"Date: {makeBookingInfo.Date}; From: {makeBookingInfo.From}; To: {makeBookingInfo.To}"); return(bookingId); }
public void MakeBooking_PhoneNotConfirmed() { var bookingService = new BookingService(CreateRepo(), null, _costEvaluationService, null, _dateService); var bookingInfo = new MakeBookingInfoDto { Date = DateTime.UtcNow.Date.AddDays(1), From = 10, To = 20 }; bookingService.MakeBooking(bookingInfo, new CurrentUser()); }
private void TestOccupation(params BookingEntity[] bookings) { var bookingService = new BookingService(CreateRepo(bookings), null, _costEvaluationService, null, _dateService); var bookingInfo = new MakeBookingInfoDto { Date = DateTime.UtcNow.Date, From = 10, To = 20 }; bookingService.MakeBooking(bookingInfo, new CurrentUser { Phone = "1" }); }
public int MakeBooking(MakeBookingInfoDto makeBookingInfo, CurrentUser user) { DateTime from = makeBookingInfo.GetFromDateTime(); DateTime to = makeBookingInfo.GetToDateTime(); if (!user.PhoneConfirmed) { throw new ServiceException("User does not have such permissions"); } if (from < _dateService.NowUtc.Date) { throw new ServiceException($"Booking is invalid for this action \r\n ____ from less than date now. From='{from}' Date='{_dateService.NowUtc.Date}'"); } if (GetBookingsForPeriod(from, to).Any()) { string bookingIds = GetBookingsForPeriod(from, to).Select(x => x.Id.ToString()) .Aggregate((s1, s2) => s1 + "," + s2); throw new ServiceException($"Booking is invalid for this action \r\n ____ has bookings for period. From='{from}' To='{to}' Ids='{bookingIds}'"); } // TODO: Implement checking schedule BookingCostDto bookingCost = _costEvaluationService.EvaluateBookingCost(from, to, makeBookingInfo.PromoCode); var booking = new BookingEntity { From = from, To = to, Status = BookingStatusEnum.Unpaid, Guid = Guid.NewGuid(), Cost = bookingCost.TotalCost, PromoCodeId = bookingCost.PromoCode?.Id, UserId = user.UserId }; _bookingRepository.Save(booking); return(booking.Id); }
public void MakeBooking_BookingStartsEarlier() { var dateServiceMock = new Mock <IDateService>(); dateServiceMock.Setup(x => x.NowUtc).Returns(DateTime.UtcNow.Date.AddDays(1)); _dateService = dateServiceMock.Object; var bookingService = new BookingService(CreateRepo(), null, _costEvaluationService, null, _dateService); var bookingInfo = new MakeBookingInfoDto { Date = DateTime.UtcNow.Date, From = 0, To = 20 }; bookingService.MakeBooking(bookingInfo, new CurrentUser { Phone = "1" }); }
public void MakeBooking_Normal() { var bookingService = new BookingService( CreateRepo( new BookingEntity { From = Dth(10), To = Dth(13) }, new BookingEntity { From = Dth(16), To = Dth(20) }), null, _costEvaluationService, null, _dateService); var bookingInfo = new MakeBookingInfoDto { Date = DateTime.UtcNow.Date, From = 13, To = 15 }; bookingService.MakeBooking(bookingInfo, new CurrentUser { Phone = "1", UserId = "SomeUser" }); }