public async Task EditAsync_WithIncorrectProperty_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = HotelDbContextInMemoryFactory.InitializeContext(); var reservationStatusRepository = new EfDeletableEntityRepository <ReservationStatus>(context); var reservationStatusesService = this.GetReservationStatusesService(reservationStatusRepository, context); var seeder = new ReservationStatusesServiceTestsSeeder(); await seeder.SeedReservationStatusAsync(context); var reservationStatus = context.ReservationStatuses.First(); var model = new EditReservationStatusViewModel { Id = reservationStatus.Id, Name = null, }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await reservationStatusesService.EditAsync(model); }); }
public async Task AddRoomTypeAsync_WithIncorrectProperty_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = HotelDbContextInMemoryFactory.InitializeContext(); var seeder = new RoomTypesServiceTestsSeeder(); await seeder.SeedRoomTypeAsync(context); var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context); var roomTypesService = this.GetRoomTypesService(roomTypeRepository, context); var roomTypeModel = new RoomType { Name = null, Price = 100, CapacityAdults = 1, CapacityKids = 0, Image = "test1.jpg", Description = null, }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await roomTypesService.AddRoomTypeAsync(roomTypeModel); }); }
public async Task GetAllRoomTypesAsyn_ShouldReturnCorrectCount() { // Arrange MapperInitializer.InitializeMapper(); var context = HotelDbContextInMemoryFactory.InitializeContext(); var seeder = new RoomTypesServiceTestsSeeder(); await seeder.SeedRoomTypeAsync(context); var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context); var roomTypesService = this.GetRoomTypesService(roomTypeRepository, context); // Act var actualResult = roomTypesService.GetAllRoomTypes <DetailsRoomTypeViewModel>().ToList(); var expectedResult = new DetailsRoomTypeViewModel[] { new DetailsRoomTypeViewModel { Id = roomTypeRepository.All().First().Id, Name = roomTypeRepository.All().First().Name, CapacityAdults = roomTypeRepository.All().First().CapacityAdults, CapacityKids = roomTypeRepository.All().First().CapacityKids, Image = roomTypeRepository.All().First().Image, Description = roomTypeRepository.All().First().Description, }, }; Assert.Equal(expectedResult.Length, actualResult.Count()); }
public async Task GetRoomTypeByNamec_WithExistentName_ShouldReturnCorrectResult() { var errorMessagePrefix = "RoomTypesService GetRoomTypeByName() method does not work properly."; // Arrange MapperInitializer.InitializeMapper(); var context = HotelDbContextInMemoryFactory.InitializeContext(); var seeder = new RoomTypesServiceTestsSeeder(); await seeder.SeedRoomTypesAsync(context); var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context); var roomTypesService = this.GetRoomTypesService(roomTypeRepository, context); var roomTypeName = roomTypeRepository.All().First().Name; // Act var actualResult = roomTypesService.GetRoomTypeByName(roomTypeName); var expectedResult = await roomTypeRepository .All() .SingleOrDefaultAsync(x => x.Name == roomTypeName); // Assert Assert.True(expectedResult.Id == actualResult.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedResult.Price == actualResult.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedResult.CapacityAdults == actualResult.CapacityAdults, errorMessagePrefix + " " + "Capacity Adults is not returned properly."); Assert.True(expectedResult.CapacityKids == actualResult.CapacityKids, errorMessagePrefix + " " + "Capacity Kids is not returned properly."); Assert.True(expectedResult.Image == actualResult.Image, errorMessagePrefix + " " + "Image is not returned properly."); Assert.True(expectedResult.Description == actualResult.Description, errorMessagePrefix + " " + "Description is not returned properly."); }
public async Task AddRoomTypeAsync_WithCorrectData_ShouldSuccessfullyCreate() { var errorMessagePrefix = "RoomTypeService AddRoomTypeAsync() method does not work properly."; MapperInitializer.InitializeMapper(); var context = HotelDbContextInMemoryFactory.InitializeContext(); var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context); var roomTypesService = this.GetRoomTypesService(roomTypeRepository, context); var roomTypeModel = new RoomType { Name = "Test-1", Price = 100, CapacityAdults = 1, CapacityKids = 0, Image = "test1.jpg", Description = "Description1", }; // Act await roomTypesService.AddRoomTypeAsync(roomTypeModel); var actualResult = roomTypeRepository.All().First(); var expectedResult = roomTypeModel; // Assert Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedResult.Price == actualResult.Price, errorMessagePrefix + " " + "Price is not returned properly."); Assert.True(expectedResult.CapacityAdults == actualResult.CapacityAdults, errorMessagePrefix + " " + "Capacity Adults is not returned properly."); Assert.True(expectedResult.CapacityKids == actualResult.CapacityKids, errorMessagePrefix + " " + "Capacity Kids is not returned properly."); Assert.True(expectedResult.Image == actualResult.Image, errorMessagePrefix + " " + "Image is not returned properly."); Assert.True(expectedResult.Description == actualResult.Description, errorMessagePrefix + " " + "Description is not returned properly."); }