public async Task DeleteFireplace_WithNonExistingFireplace_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var fireplace = new DeleteFireplaceViewModel { Id = "Test Id", Power = "10w", Chimney = "200Ф", Description = "Some description test 1", ImagePath = "Some dummy data", Price = 1800.00M, Size = "60 / 40 / h50", TypeOfChamber = TypeOfChamber.Basic.ToString(), Name = "Гк Мая", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DeleteFireplaceViewModel).Assembly); await Assert.ThrowsAsync <NullReferenceException>(() => fireplaceService.DeleteAsync <DeleteFireplaceViewModel>(fireplace)); }
public async Task <IActionResult> Delete(DeleteFireplaceViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var typeOfChamber = this.fireplaceService.GetById <DeleteFireplaceViewModel>(model.Id).TypeOfChamber; await this.fireplaceService.DeleteAsync <DeleteFireplaceViewModel>(model); var type = Enum.Parse <TypeOfChamber>(typeOfChamber); return(this.RedirectToAction("All", new { type = typeOfChamber, area = string.Empty })); }
public async Task DeleteAsync <T>(DeleteFireplaceViewModel deleteModel) { var fireplace = this.fireplaceRepository.All().Where(f => f.Id == deleteModel.Id).FirstOrDefault(); if (fireplace == null) { throw new NullReferenceException(string.Format(ExceptionsServices.Null_Fireplace_Id_ErrorMessage, deleteModel.Id)); } fireplace.IsDeleted = true; fireplace.DeletedOn = DateTime.UtcNow; await this.productService.DeleteAsync(fireplace.ProductId); this.fireplaceRepository.Update(fireplace); await this.fireplaceRepository.SaveChangesAsync(); }