public async Task GetReservation_ShouldReturnReservation() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation1User3Room1NoClient, Reservations.Reservation2User4Room2NoClient }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(reservationsData); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var reservation = await service.GetReservation <ReservationViewModel>( Reservations.Reservation2User4Room2NoClient.Id); // Assert Assert.AreEqual(Reservations.Reservation2User4Room2NoClient.Id, reservation.Id); Assert.AreEqual(Reservations.Reservation2User4Room2NoClient.ReleaseDate, reservation.ReleaseDate); Assert.AreEqual(Reservations.Reservation2User4Room2NoClient.Price, reservation.Price); Assert.AreEqual(Reservations.Reservation2User4Room2NoClient.AllInclusive, reservation.AllInclusive); Assert.AreEqual(Reservations.Reservation2User4Room2NoClient.Breakfast, reservation.Breakfast); }
public async Task TestGetAllReservationsFromHotel() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options)); await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room { HotelId = 1 } }); await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room { HotelId = 1 } }); await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room { HotelId = 2 } }); await reservationRepository.SaveChangesAsync(); var reservationsService = new ReservationsService(reservationRepository); AutoMapperConfig.RegisterMappings(typeof(MyTestReservation).Assembly); var reservations = reservationsService.GetAll <MyTestReservation>(1); Assert.Equal(2, reservations.Count()); }
public void CountForUser_ReturnsCorrectUserReservations() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; Reservation reservation = new Reservation() { VehicleMake = "BMW", VehicleModel = "M5", LicenseNumber = "СА 1234 КР", PhoneNumber = "0897482124", ReservationDateTime = new DateTime(2020, 3, 21, 10, 30, 10), User = user, }; var reservationsService = new ReservationsService(dbContext); dbContext.Reservations.Add(reservation); dbContext.SaveChanges(); var result = reservationsService.CountForUser(user.UserName); Assert.Equal(1, result); } }
public void TestGetReservationsForGivenDay() { for (int i = 0; i < this.lanes.Count-5; i++) { var reservation = new Reservation() { CreatedAt = DateTime.Now, Name = "Gert", NumberOfPlayers = 4, PhoneNumber = 1234, PlayAt = DateTime.Now }; reservation.AddLane(this.lanes[i]); reservation.AddTimeSlot((from y in this.timeSlots select y).First<TimeSlot>()); this._session.Save(reservation); } var reservationService = new ReservationsService(); var request = new Reservations { Date = DateTime.Now }; ReservationsResponse response = reservationService.OnGet(request) as ReservationsResponse; Assert.That(response.ReservationList.Count, Is.EqualTo(5), "We expect that there are 5 reservations today"); foreach (var r in response.ReservationList) { Assert.That(r, Is.Not.Null); } }
public async Task AddReservation_ShouldNotAddReservationWithInvalidDate() { // Arange ApplicationDbContext context = InMemoryFactory.InitializeContext(); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var reservation1 = await service.AddReservation(Reservations.Reservation5User3Room1NoClient.Room.Id, Reservations.Reservation5User3Room1NoClient.AccommodationDate, Reservations.Reservation5User3Room1NoClient.ReleaseDate, Reservations.AllInClusive1, Reservations.Breakfast1, Reservations.Reservation5User3Room1NoClient.Clients, Reservations.Reservation5User3Room1NoClient.User); var reservation2 = await service.AddReservation(Reservations.Reservation6User3Room1NoClient.Room.Id, Reservations.Reservation6User3Room1NoClient.AccommodationDate, Reservations.Reservation6User3Room1NoClient.ReleaseDate, Reservations.AllInClusive1, Reservations.Breakfast1, Reservations.Reservation6User3Room1NoClient.Clients, Reservations.Reservation6User3Room1NoClient.User); // Assert Assert.Null(reservation1); Assert.Null(reservation2); }
public void CreateAsync_ReturnsCorrectReservationId() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { var user = new ApplicationUser { UserName = "******", Email = "*****@*****.**" }; dbContext.Users.Add(user); dbContext.SaveChanges(); CreateReservationServiceModel reservation = new CreateReservationServiceModel { VehicleMake = "BMW", VehicleModel = "M5", LicenseNumber = "СА 1234 КР", PhoneNumber = "0897482124", ReservationDateTime = new DateTime(2020, 3, 21, 10, 30, 10), Username = user.UserName, }; var reservationsService = new ReservationsService(dbContext); var result = reservationsService.CreateAsync(reservation); var reservationObj = dbContext.Reservations.FirstOrDefaultAsync(); Assert.Equal(reservationObj.Result.Id, result.Result); } }
public async Task AddReservation_ShouldNotAddReservation() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation3User4Room2NoClient }; List <Room> rooms = new() { Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms) .SeedAsync(reservationsData); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var reservation = await service.AddReservation(Reservations.Reservation4User4Room2NoClient.Room.Id, Reservations.Reservation4User4Room2NoClient.AccommodationDate, Reservations.Reservation4User4Room2NoClient.ReleaseDate, Reservations.AllInClusive1, Reservations.Breakfast1, Reservations.Reservation4User4Room2NoClient.Clients, Reservations.Reservation4User4Room2NoClient.User); // Assert Assert.Null(reservation); }
public ActionResult Index(string customerid, string paytype, int status = -1, int p = 1) { ReservationsSearchEntity search = new ReservationsSearchEntity(); search.CustomerID = customerid.ToLong(0); search.PayType = paytype; search.Status = status; int count = ReservationsService.GetReservationsCount(search); PagerInfo pager = new PagerInfo(); pager.PageIndex = p; pager.PageSize = PAGESIZE; pager.SumCount = count; pager.URL = "/Rev"; List <CustomerEntity> customers = CustomerService.GetCustomerList(); List <BaseDataEntity> paytypes = BaseDataService.GetBaseDataAll().Where(t => t.PCode == "P00").ToList(); ViewBag.Search = search; List <ReservationsEntity> mList = ReservationsService.GetReservationsByRule(search, pager); ViewBag.Reservations = mList; ViewBag.Pager = pager; ViewBag.Customers = customers; ViewBag.PayTypes = paytypes; return(View()); }
public async Task UpdateClientsForReservation_ShouldUpdateClientsForReservation() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation7User3Room1NoClient }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(reservationsData); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var allClients = await service.UpdateClientsForReservation( Reservations.Reservation7User3Room1NoClient.Id, new List <ClientData> { Users.Client2User, Users.Client3User, Users.Client4User }); // Assert Assert.AreEqual(3, allClients.Count()); }
public void RemoveAsync_ReturnsTrue() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { Reservation reservation = new Reservation() { VehicleMake = "BMW", VehicleModel = "M5", LicenseNumber = "СА 1234 КР", PhoneNumber = "0897482124", ReservationDateTime = new DateTime(2020, 3, 21, 10, 30, 10), }; var reservationsService = new ReservationsService(dbContext); dbContext.Reservations.Add(reservation); dbContext.SaveChanges(); var result = reservationsService.RemoveAsync(reservation.Id); Assert.True(result.Result); } }
public JsonResult Edit(long rid, int status) { var result = new { result = ReservationsService.EditReservationsStatus(rid, status) }; return(Json(result)); }
public async Task UpdateReservation_ShouldNotUpdateReservation() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation1User3Room1NoClient }; List <Setting> settings = new() { Settings.AllInclusive, Settings.Breakfast }; List <ApplicationUser> users = new() { Users.User3NotEmployee }; List <ClientData> clients = new() { new ClientData { Id = null, Email = "email", FullName = "name" } }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(settings) .SeedAsync(users); context.Reservations.RemoveRange(context.Reservations.ToList()); context.AddRange(reservationsData); context.SaveChanges(); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var result = await service.UpdateReservation(Reservations.Reservation1User3Room1NoClient.Id, DateTime.Today.AddDays(7), DateTime.Today.AddDays(9), Reservations.UpdateAllInClusive1, Reservations.UpdateBreakfast1, clients, Users.User1Employee); // Assert Assert.IsFalse(result); }
public void Exist_ReturnsFalse() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var dbContext = new ApplicationDbContext(options)) { var reservationsService = new ReservationsService(dbContext); var result = reservationsService.Exists("fsfsfsf"); Assert.False(result); } }
public async Task GetByUserAsync_ShouldReturnAllReservationsForUser(string clientId, int?reservationsPerPage, int skip) { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var reservationRepository = new EfDeletableEntityRepository <Reservation>(context); var reservationsService = new ReservationsService(reservationRepository); var seeder = new DbContextTestsSeeder(); await seeder.SeedReservationsAsync(context); var result = await reservationsService.GetByUserAsync(clientId, reservationsPerPage, skip); Assert.True(result.ToList().Count == 3, ErrorMessage); }
public void can_list_reservations() { //arrange IReservationsService service = new ReservationsService(_database); //get all reservations var reservations = Task.Run(async() => await service.GetReservations()); var results = reservations.Result; //assert Assert.IsNotNull(results); Assert.IsTrue(reservations.Result.Count == 1); }
public async Task CancelAsync_ShouldReturnCorrectResult() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var reservationRepository = new EfDeletableEntityRepository <Reservation>(context); var reservationsService = new ReservationsService(reservationRepository); var seeder = new DbContextTestsSeeder(); await seeder.SeedReservationsAsync(context); var result = await reservationsService.CancelAsync(1); Assert.True(result == 1, ErrorMessage); }
public async Task TestGetDeletedByIdReservationFromHotelWithDeletedUser() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options)); var reservationId = Guid.NewGuid().ToString(); await reservationRepository.AddAsync(new Reservation { Id = reservationId, Room = new Room { Number = "100", HotelId = 1, }, Creator = new ApplicationUser { Id = Guid.NewGuid().ToString(), IsDeleted = true, }, }); await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), Room = new Room { Number = "300", HotelId = 2, }, Creator = new ApplicationUser { Id = Guid.NewGuid().ToString(), IsDeleted = true, }, }); await reservationRepository.SaveChangesAsync(); var reservationsService = new ReservationsService(reservationRepository); AutoMapperConfig.RegisterMappings(typeof(MyTestReservation).Assembly); var reservation = await reservationsService.GetDeletedByIdAsync <MyTestReservation>(reservationId); Assert.Equal("100", reservation.RoomNumber); }
public async Task TestCreateReservation() { var reservations = new List <Reservation>(); var mockReservationRepo = new Mock <IDeletableEntityRepository <Reservation> >(); mockReservationRepo.Setup(x => x.All()).Returns(reservations.AsQueryable()); mockReservationRepo.Setup(x => x.AddAsync(It.IsAny <Reservation>())).Callback( (Reservation reservation) => reservations.Add(reservation)); var service = new ReservationsService(mockReservationRepo.Object); await service.CreateAsync("0888989844", Guid.NewGuid().ToString(), 1, DateTime.UtcNow, DateTime.UtcNow, 2, 0, "Petar", "Stoqnov", null, 10.00M, true, false, false); Assert.Single(reservations); }
public void refreshReservations() { ReservationsService reservationsService = new ReservationsService(); List <Reservation> reservations = reservationsService.getAll(); reservationsList.Items.Clear(); foreach (Reservation reservation in reservations) { ListViewItem item = new ListViewItem(reservation.Id.ToString()); item.SubItems.Add(reservation.customer.ToString()); item.SubItems.Add(reservation.book.ToString()); reservationsList.Items.Add(item); } }
public async Task TestEditReservation() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options)); var reservationId = Guid.NewGuid().ToString(); var guests = new List <Guest>(); var guestOne = new Guest { FirstName = "Petar", LastName = "Stoqnov", PhoneNumber = "0888888888", CreatedOn = DateTime.UtcNow, }; var guestTwo = new Guest { FirstName = "Dimitar", LastName = "Neykov", PhoneNumber = "0888888888", CreatedOn = DateTime.UtcNow.AddDays(-1), }; guests.Add(guestOne); guests.Add(guestTwo); await reservationRepository.AddAsync(new Reservation { Id = reservationId, ArrivalDate = DateTime.UtcNow, Guests = guests, }); await reservationRepository.SaveChangesAsync(); var reservationsService = new ReservationsService(reservationRepository); await reservationsService.UpdateAsync(Guid.NewGuid().ToString(), reservationId, 1, DateTime.UtcNow.AddDays(1), DateTime.UtcNow, 1, 1, "Georgi", "Petrov", "0888989844", null, 10.00M, true, false, false); var result = reservationRepository.All().FirstOrDefault(); Assert.Equal(DateTime.UtcNow.AddDays(1).Date, result.ArrivalDate.Date); }
public void can_add_reservation() { //arrange NewReservationItem newRes = new NewReservationItem { From = DateTime.Now, To = DateTime.Now.AddDays(10), LectureHallNumber = 101, LecturerId = 1 }; IReservationsService service = new ReservationsService(_database); //add a new reservation service.SaveReservation(newRes); var reservations = _database.Reservations; //assert Assert.IsTrue(reservations.Count == 2); }
private void cmbBoxBooks_SelectedIndexChanged(object sender, EventArgs e) { if (cmbBoxBooks.Items.Count == 0) { return; } ReservationsService reservationsService = new ReservationsService(); Book selectedBook = (Book)cmbBoxBooks.SelectedItem; List <Reservation> reservations = reservationsService.getByBook(selectedBook); reservedByList.Items.Clear(); foreach (Reservation reservation in reservations) { reservedByList.Items.Add(reservation.customer.ToString()); } }
public async Task AddReservation_ShouldAddReservation() { // Arange List <Setting> settings = new() { Settings.AllInclusive, Settings.Breakfast }; List <Room> rooms = new() { Rooms.Room1 }; List <ApplicationUser> users = new() { Users.User3NotEmployee }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(settings) .SeedAsync(users) .SeedAsync(rooms); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var reservation = await service.AddReservation(Reservations.Reservation1User3Room1NoClient.Room.Id, Reservations.Reservation1User3Room1NoClient.AccommodationDate, Reservations.Reservation1User3Room1NoClient.ReleaseDate, Reservations.AllInClusive1, Reservations.Breakfast1, Reservations.Reservation1User3Room1NoClient.Clients, Reservations.Reservation1User3Room1NoClient.User ); // Assert Assert.NotNull(reservation); Assert.AreEqual(1, context.Reservations.Count()); }
public async Task TestGetAllReservationsWithDinnerFromHotel() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options)); await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), HasDinner = true, Room = new Room { Number = "100", HotelId = 1, }, ReturnDate = DateTime.UtcNow.AddDays(5), ArrivalDate = DateTime.UtcNow.AddDays(-5), }); await reservationRepository.AddAsync(new Reservation { Id = Guid.NewGuid().ToString(), HasDinner = false, Room = new Room { Number = "200", HotelId = 1, }, ReturnDate = DateTime.UtcNow.AddDays(5), ArrivalDate = DateTime.UtcNow.AddDays(-5), }); await reservationRepository.SaveChangesAsync(); var reservationsService = new ReservationsService(reservationRepository); AutoMapperConfig.RegisterMappings(typeof(MyTestReservation).Assembly); var reservations = reservationsService.GetActiveReservationsWithDinner <MyTestReservation>(1); Assert.Single(reservations); }
public async Task TestDeleteReservationIsInDatabase() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options)); var reservationId = Guid.NewGuid().ToString(); await reservationRepository.AddAsync(new Reservation() { Id = reservationId }); await reservationRepository.SaveChangesAsync(); var reservationsService = new ReservationsService(reservationRepository); await reservationsService.DeleteAsync(reservationId, Guid.NewGuid().ToString()); Assert.Equal(1, reservationRepository.AllWithDeleted().Count()); }
/// <summary> /// 用户预约车辆试驾信息 /// </summary> /// <param name="userid"></param> /// <param name="carid"></param> /// <returns></returns> public JsonResult Reservation(string userid, string carid) { ReservationsEntity entity = new ReservationsEntity(); entity.CustomerID = Convert.ToInt64(userid); entity.CarID = Convert.ToInt32(carid); entity.RType = "SJ"; //SJ:销售试驾 2:ZL:租车预约 DZ:电桩预约 entity.Status = 0; //0未处理 1:已处理 bool result = ReservationsService.AddReservations(entity); ApiReservationsEntity apiE = new ApiReservationsEntity(); if (result) { apiE.code = "200"; apiE.codeinfo = "汽车试驾预约成功!稍后客服联系您!"; } else { apiE.code = "201"; apiE.codeinfo = "预约失败,请稍后再试!"; } return(Json(JsonHelper.ToJson(apiE))); }
public async Task CountAll_ShouldReturnTheCountOfAllReservations() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation1User3Room1NoClient, Reservations.Reservation2User4Room2NoClient, Reservations.Reservation3User4Room2NoClient }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(reservationsData); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var allReservationsCount = await service.CountAllReservations(); // Assert Assert.AreEqual(context.Reservations.Count(), allReservationsCount); }
// --------------------------------------------------------------------- /// <summary> /// /// </summary> /// <param name="r"></param> /// <returns></returns> public static DTOReservable BuildReservableDTO(Table r, Terminal t) { DTOReservable reservableDTO = new DTOReservable(); if (r != null) { reservableDTO.Id = r.Id; reservableDTO.Name = r.Name; reservableDTO.MaxGuests = r.MaxGuests; // create a 'shallow' dto location DTOLocation pl = new DTOLocation(); pl.Id = r.ParentLocation.Id; pl.Name = r.ParentLocation.Name; reservableDTO.ParentLocation = pl; // send back the current interest level if (r.Id != 0) { reservableDTO.CurrentInterestLevel = ReservationsService.GetTableInterestLevel(r.Id); } // table plan data reservableDTO.X = r.X; reservableDTO.Y = r.Y; reservableDTO.Width = r.Width; reservableDTO.Height = r.Height; reservableDTO.RotationAngle = r.RotationAngle; reservableDTO.Shape = r.Shape; reservableDTO.TableColor = r.Status(t); reservableDTO.Number = r.Number; } return(reservableDTO); }
public async Task GetForUserOnPage_ShouldReturnReservationsForUserOnPage() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation1User3Room1NoClient, Reservations.Reservation2User4Room2NoClient, Reservations.Reservation3User4Room2NoClient }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(reservationsData); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act var userReservations = await service.GetForUserOnPage <ReservationViewModel>( Users.User4NotEmployee.Id, 1, 2); // Assert Assert.AreEqual(2, userReservations.Count()); }
public async Task DeleteReservation_ShouldDeleteReservation() { // Arange List <Reservation> reservationsData = new() { Reservations.Reservation1User3Room1NoClient }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(reservationsData); SettingService settingService = new(context); var service = new ReservationsService(context, settingService); // Act bool result1 = await service.DeleteReservation(Reservations.Reservation1User3Room1NoClient.Id); bool result2 = await service.DeleteReservation("2"); // Assert Assert.IsTrue(result1); Assert.IsFalse(result2); }
public ReservationsController(ReservationsService service) { this.service = service; }