public async Task Test_DeleteBrand_ShouldDeleteSuccessfully() { //arrange var brandForDelete = new BrandForDeleteDto { Id = 1 }; var resultModel = new BrandDeletedDto { IsSuccess = true }; brandRepositoryMock.Setup(p => p.DeleteBrand(brandForDelete)).Returns(Task.FromResult(resultModel)); //act var result = await subject.DeleteBrand(brandForDelete); var OkActionResult = result as OkResult; //assert Assert.IsInstanceOf <OkResult>(OkActionResult); brandRepositoryMock.Verify(x => x.DeleteBrand(brandForDelete), Times.Once); }
public async Task ValidateDeleteBrand() { _dbContext.Brands.Add(new Brand { Id = 99, Name = "GOG.com" }); var controller = new BrandsController(_dbContext); var result = await controller.DeleteBrand(99); var actionResult = Assert.IsType <NoContentResult>(result); Assert.NotNull(result); Assert.NotNull(actionResult); }
public async Task DeleteCategory_Success() { _applicationDbContex.Brands.Add(new Brand { Name = "Test category" }); await _applicationDbContex.SaveChangesAsync(); var oldCategory = await _applicationDbContex.Brands.OrderByDescending(x => x.BrandID).FirstAsync(); var controller = new BrandsController(_applicationDbContex); var result = await controller.DeleteBrand(oldCategory.BrandID); var returnValue = await _applicationDbContex.Brands.ToListAsync(); Assert.Empty(returnValue); }
public async Task DeleteBrand_Success() { var dbContext = _fixture.Context; Brand brand = new Brand { Name = "Test brand" }; await dbContext.Brands.AddAsync(brand); await dbContext.SaveChangesAsync(); var brandsController = new BrandsController(dbContext); // Act var result = await brandsController.DeleteBrand(brand.ID); // Assert var deleteAtActionResult = Assert.IsType <NoContentResult>(result.Result); await Assert.ThrowsAsync <Exception>(async() => { await brandsController.GetBrand(brand.ID); }); }