public async Task EditAsync_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 roomType = context.RoomTypes.First(); var model = new EditRoomTypeViewModel { Id = roomType.Id, Name = null, Price = 100, CapacityAdults = 1, CapacityKids = 0, Image = null, Description = "Description1", }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await roomTypesService.EditAsync(model); }); }
public async Task <IActionResult> Edit(EditRoomTypeViewModel roomTypeEditView) { var roomType = await this.roomTypesService.GetRoomTypeByIdAsync(roomTypeEditView.Id); if (roomTypeEditView.RoomImage != null) { var newImageUrl = await this.cloudinaryService.UploadPhotoAsync( roomTypeEditView.RoomImage, $"Room - {roomTypeEditView.Name}", "Hotel_room_types_photos"); roomTypeEditView.Image = newImageUrl; var fileType = roomTypeEditView.RoomImage.ContentType.Split('/')[1]; if (!this.IsImageTypeValid(fileType)) { return(this.View()); } } else { roomTypeEditView.Image = roomType.Image; } await this.roomTypesService.EditAsync(roomTypeEditView); return(this.Redirect($"/Administration/RoomTypes/All")); }
public async Task EditAsync_WithNonExistentId_ShouldThrowArgumentNullException() { // Arrange MapperInitializer.InitializeMapper(); var context = HotelDbContextInMemoryFactory.InitializeContext(); var roomTypeRepository = new EfDeletableEntityRepository <RoomType>(context); var roomTypesService = this.GetRoomTypesService(roomTypeRepository, context); var nonExistentId = Guid.NewGuid().ToString(); var model = new EditRoomTypeViewModel { Id = nonExistentId, Name = "Test-1", Price = 100, CapacityAdults = 1, CapacityKids = 0, Image = "test1.jpg", Description = "Description1", }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await roomTypesService.EditAsync(model); }); }
public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult() { var errorMessage = "RoomTypesService EditAsync() method does not work properly."; // 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 roomType = context.RoomTypes.First(); var model = new EditRoomTypeViewModel { Id = roomType.Id, Name = "Test-1", Price = 100, CapacityAdults = 1, CapacityKids = 0, Image = "test1.jpg", Description = "Description1", }; // Act var result = await roomTypesService.EditAsync(model); // Assert Assert.True(result, errorMessage + " " + "Returns false."); }
public async Task <bool> EditAsync(EditRoomTypeViewModel roomTypeEditViewModel) { var roomType = this.roomTypeRepository.All().FirstOrDefault(r => r.Id == roomTypeEditViewModel.Id); if (roomType == null) { throw new ArgumentNullException(string.Format(string.Format(ServicesDataConstants.InvalidRoomTypeIdErrorMessage, roomTypeEditViewModel.Id))); } if (roomTypeEditViewModel.Name == null || roomTypeEditViewModel.Image == null || roomTypeEditViewModel.Description == null) { throw new ArgumentNullException(string.Format(ServicesDataConstants.InvalidPropertyNameErrorMessage)); } if (roomTypeEditViewModel.RoomImage == null) { roomTypeEditViewModel.Image = roomType.Image; } roomType.Name = roomTypeEditViewModel.Name; roomType.Image = roomTypeEditViewModel.Image; roomType.Price = roomTypeEditViewModel.Price; roomType.CapacityAdults = roomTypeEditViewModel.CapacityAdults; roomType.CapacityKids = roomTypeEditViewModel.CapacityKids; roomType.Description = roomTypeEditViewModel.Description; this.roomTypeRepository.Update(roomType); var result = await this.roomTypeRepository.SaveChangesAsync(); return(result > 0); }
public EditRoomTypeWindow(Window window, out EditRoomTypeViewModel viewmodel) { InitializeComponent(); this.Owner = window; this.WindowStartupLocation = WindowStartupLocation.CenterOwner; viewmodel = new EditRoomTypeViewModel(this); this.DataContext = viewmodel; isclosetrans = 0; }
public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit() { var errorMessagePrefix = "RoomTypeService EditAsync() method does not work properly."; // 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 roomType = context.RoomTypes.First(); var model = new EditRoomTypeViewModel { Id = roomType.Id, Name = "Test-2-Edited", Price = 130, CapacityAdults = 1, CapacityKids = 0, Image = "test2-edited.jpg", Description = "Description2-edited", }; // Act await roomTypesService.EditAsync(model); var actualResult = roomTypeRepository.All().First(); var expectedResult = model; // 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."); }
public async Task GetViewModelByIdAsync_WithExistentId_ShouldReturnCorrectResult() { var errorMessagePrefix = "RoomTypesService GetViewModelByIdAsync() 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 roomTypeId = roomTypeRepository.All().First().Id; // Act var actualResult = await roomTypesService.GetViewModelByIdAsync <EditRoomTypeViewModel>(roomTypeId); var expectedResult = new EditRoomTypeViewModel { Id = roomTypeId, 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, Price = roomTypeRepository.All().First().Price, }; // 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."); }