public async Task AddAsync_ShouldAddEmployee() { // Arange List <ApplicationUser> userData = new() { Users.User1Employee, Users.User2Employee }; List <EmployeeData> employeeData = new() { Users.EmployeeUser1 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(userData) .SeedAsync(employeeData); var service = new UserService(context); // Act await service.AddAsync(Users.EmployeeUser2); // Assert Assert.AreEqual(employeeData.Count + 1, context.Users.Count()); }
public async Task GetSearchResults_ShouldReturnAllRoomsContainingTheCriteria() { List <Room> rooms = new() { Rooms.Room1FreeAtPresent1ReservationUser3, Rooms.Room1TakenAtPresent1ReservationUser4 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var result1 = await roomService.GetSearchResults <RoomViewModel>(true, new RoomType[] { RoomType.Penthouse }, 2); var result2 = await roomService.GetSearchResults <RoomViewModel>(false, new RoomType[] { RoomType.Apartment }, 2); //Assert Assert.NotNull(result1); Assert.NotNull(result2); Assert.AreEqual(Rooms.Room1FreeAtPresent1ReservationUser3.Id, result1.FirstOrDefault().Id); Assert.AreEqual(Rooms.Room1FreeAtPresent1ReservationUser3.Number, result1.FirstOrDefault().Number); Assert.AreEqual(Rooms.Room1FreeAtPresent1ReservationUser3.Type, result1.FirstOrDefault().Type); Assert.AreEqual(Rooms.Room1TakenAtPresent1ReservationUser4.Id, result2.FirstOrDefault().Id); Assert.AreEqual(Rooms.Room1TakenAtPresent1ReservationUser4.Number, result2.FirstOrDefault().Number); Assert.AreEqual(Rooms.Room1TakenAtPresent1ReservationUser4.Type, result2.FirstOrDefault().Type); }
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 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 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 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 async Task GetEmployeesSearchResults_ShouldFindExistingSearchedResult() { // Arange List <ApplicationUser> userData = new() { Users.UserForSearch }; List <EmployeeData> employeeData = new() { Users.EmployeeForSearch }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(userData) .SeedAsync(employeeData); var service = new UserService(context); // Act var result = await service.GetEmployeesSearchResults <EmployeeDataViewModel>(Users.searchParam); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); }
public async Task CountFreeRoomsAtPresent_ShouldCountAllFreeRooms() { //Arrange List <Room> rooms = new() { Rooms.Room1TakenAtPresent1ReservationUser4, Rooms.Room2TakenAtPresent, Rooms.Room1FreeAtPresent1ReservationUser3 }; List <ApplicationUser> users = new() { Users.User3NotEmployee }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(users) .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var result = await roomService.CountFreeRoomsAtPresent(); //Assert Assert.AreEqual(1, 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 async Task UpdateSetting_ShouldUpdateSetting() { // Arange ApplicationDbContext context = InMemoryFactory.InitializeContext(); var service = new SettingService(context); var initialCount = context.Settings.Count(); // Act await service.UpdateAsync("Key", "Value1", "string"); // Assert Assert.AreEqual(initialCount, context.Settings.Count()); }
public async Task DeleteAsync_ShouldDeleteUsers() { // Arange List <EmployeeData> employeesData = new() { Users.EmployeeUser1, Users.EmployeeUser2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(employeesData); var service = new UserService(context); // Act await service.DeleteAsync(employeesData.First().UserId); // Assert Assert.AreNotEqual(employeesData.First().DateOfResignation, null); }
public async Task AddRoom_ShouldAddARoom() { //Arange List <Room> rooms = new() { Rooms.Room1 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act await roomService.AddRoom(Rooms.Room2); //Assert Assert.AreEqual(rooms.Count + 1, context.Rooms.Count()); }
public async Task GetEmployeePageItems_ShouldReturnAllEmployeesOnPage() { // Arange List <EmployeeData> employeesData = new() { Users.EmployeeUser1, Users.EmployeeUser2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(employeesData); var service = new UserService(context); // Act var employees = await service.GetEmployeePageItems <EmployeeDataViewModel>(1, 2); // Assert Assert.NotNull(employees); Assert.AreEqual(employeesData.Count, employees.Count()); }
public async Task GetRoom_ShouldGetARoomById() { //Arrange List <Room> rooms = new() { Rooms.Room1 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var resultRoom = await roomService.GetRoom <RoomViewModel>(Rooms.Room1.Id); //Assert Assert.IsNotNull(resultRoom); Assert.AreEqual(Rooms.Room1.Id, resultRoom.Id); Assert.AreEqual(Rooms.Room1.Capacity, resultRoom.Capacity); }
public async Task GetUserPageItems_ShouldReturnAllUsersOnPage() { // Arange List <ApplicationUser> usersData = new() { Users.User1Employee, Users.User2Employee }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(usersData); var service = new UserService(context); // Act var users = await service.GetUserPageItems <UserDataViewModel>(1, 2); // Assert Assert.NotNull(users); Assert.AreEqual(usersData.Count, users.Count()); }
public async Task CreateClient_ShouldCreateClient() { // Arange List <ClientData> clientsData = new() { Users.Client1User, Users.Client2User }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(clientsData); var service = new UserService(context); var initialCount = context.ClientData.Count(); // Act await service.CreateClient(Users.searchParam, Users.searchParam, true); // Assert Assert.AreEqual(initialCount + 1, context.ClientData.Count()); }
public async Task IsAlreadyAdded_ShouldFindAddeUser() { // Arange List <ApplicationUser> usersData = new() { Users.UserForSearch }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(usersData); var service = new UserService(context); // Act var result = service.IsAlreadyAdded(Users.searchParam); // Assert Assert.IsTrue(result); }
public async Task DeleteRoom_ShouldRemoveARoom() { //Arrange List <Room> rooms = new() { Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act await roomService.DeleteRoom(Rooms.Room2.Id); //Assert Assert.AreEqual(0, context.Rooms.Count()); }
public async Task UpdateClient_ShouldUpdateClient() { // Arange List <ClientData> clientsData = new() { Users.ClientForSearch }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(clientsData); await context.SaveChangesAsync(); var service = new UserService(context); // Act var updatedClient = await service.UpdateClient(Users.ClientForSearch.Id, Users.searchParam2, Users.searchParam2, true); // Assert Assert.AreEqual(Users.searchParam2, updatedClient.Email); Assert.AreEqual(Users.searchParam2, updatedClient.FullName); }
public async Task GetAllByCapacity_ShouldGetAllRoomsByCapacity() { //Arange List <Room> rooms = new() { Rooms.Room1, Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var result = await roomService.GetAllByCapacity <RoomViewModel>(4); //Arrange Assert.AreEqual(1, result.Count()); }
public async Task DeleteClient_ShouldRemoveClient() { // Arange List <ClientData> clientsData = new() { Users.Client1User, Users.Client2User }; List <ApplicationUser> usersData = new() { Users.User1Employee, Users.User2Employee }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(clientsData) .SeedAsync(usersData); var service = new UserService(context); var initialCount = context.ClientData.Count(); // Act await service.DeleteClient(clientsData.First().Id); // Assert Assert.AreEqual(initialCount - 1, context.ClientData.Count()); }
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 UpdateAsync_ShouldUpdateEmployeeData() { // Arange List <EmployeeData> employeeData = new() { Users.EmployeeUser1 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(employeeData); var service = new UserService(context); // Act await service.UpdateAsync(Users.EmployeeUser1); // Assert Assert.AreEqual(employeeData.Count(), context.EmployeeData.Count()); Assert.AreEqual(employeeData.First().UserId, context.EmployeeData.First().UserId); }
public async Task CountAllEmployees_ShouldCountAllemployees() { // Arange List <EmployeeData> employeeData = new() { Users.EmployeeUser1, Users.EmployeeUser2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(employeeData); var service = new UserService(context); // Act var result = service.CountAllEmployees(); // Assert Assert.AreEqual(employeeData.Count(), result); }
public async Task CountAllRooms_ShouldCountAllRoomsInDb() { //Arange List <Room> rooms = new() { Rooms.Room1, Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var count = roomService.CountAllRooms(); //Arrange Assert.AreEqual(rooms.Count(), count); }
public async Task GetMaxPrice_ShouldReturnTheHighestAdultPrice() { //Arange List <Room> rooms = new() { Rooms.Room1, Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var maxPrice = roomService.GetMaxPrice(); //Arrange Assert.AreEqual(rooms[1].AdultPrice, maxPrice.Result); }
public async Task GetMaxCapacity_ShouldReturnTheMaxCapacity() { //Arange List <Room> rooms = new() { Rooms.Room1, Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var maxCapacity = roomService.GetMaxCapacity(); //Arrange Assert.AreEqual(Rooms.Room2.Capacity, maxCapacity.Result); }
public async Task GetAllEmployees_ShouldReturnAllEmployees() { // Arange List <EmployeeData> employeeData = new() { Users.EmployeeUser1 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(employeeData); var service = new UserService(context); // Act var result = await service.GetAllEmployees <EmployeeDataViewModel>(); // Assert Assert.AreEqual(employeeData.Count(), result.Count()); Assert.AreEqual(employeeData.First().UCN, context.EmployeeData.First().UCN); }
public async Task CountAllUsers_ShouldCountAllUsers() { // Arange List <ApplicationUser> usersData = new() { Users.User3NotEmployee, Users.User4NotEmployee }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(usersData); var service = new UserService(context); // Act var result = service.CountAllUsers(); // Assert Assert.AreEqual(usersData.Count(), result); }
public async Task GetAll_ShouldGetAllRooms() { //Arrange List <Room> rooms = new() { Rooms.Room1, Rooms.Room2 }; ApplicationDbContext context = await InMemoryFactory.InitializeContext() .SeedAsync(rooms); var roomService = new RoomServices(context); //Act var resultList = await roomService.GetAll <RoomViewModel>(); // Assert.IsNotNull(resultList); Assert.AreEqual(rooms.Count, resultList.Count()); }