public void Can_Delete_Brand() { //---Arrange Brands brand = new Brands() { BrandId = 2, BrandName = "B2" }; Mock <IRepository> mock = new Mock <IRepository>(); mock.Setup(b => b.Brands).Returns(new Brands[] { new Brands() { BrandId = 1, BrandName = "B1" }, brand }); BrandsController controller = new BrandsController(mock.Object); //---Act ActionResult result = controller.Delete(brand.BrandId); //---Assert mock.Verify(b => b.DeleteBrand(brand.BrandId)); }
public void Delete_ShouldReturnOk() { //Arrange var mock = new Mock <IBrandService>(); var controller = new BrandsController(mock.Object); //Act mock.Setup(p => p.Delete(1)); var result = controller.Delete(1) as OkResult; // Assert Assert.IsInstanceOfType(result, typeof(OkResult)); Assert.AreEqual(200, result.StatusCode); }
public async Task DeleteShouldReturnsNotFoundWhenDbReturnsNull() { // Arrange var brandId = 1; var adminBrandsService = new Mock <IAdminBrandsService>(); adminBrandsService .Setup(s => s.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync(() => null); var controller = new BrandsController(adminBrandsService.Object, null); // Act var result = await controller.Delete(brandId); // Assert result.Should().NotBeNull(); result.As <NotFoundResult>().StatusCode.Should().Be(WebConstants.StatusCodeNotFound); }
protected void grvUser_ItemCommand(object source, DataGridCommandEventArgs e) { Id = int.Parse(e.CommandArgument.ToString()); switch (e.CommandName) { case "Edit": DataTable dt = BrandsController.GetByColumn("Id", Id.ToString()); txtName.Text = dt.Rows[0]["Name"].ToString(); txtLogo.Text = dt.Rows[0]["Logo"].ToString(); txtOrd.Text = dt.Rows[0]["Ord"].ToString(); txtLang.Text = dt.Rows[0]["Lang"].ToString(); break; case "Delete": tbBrandInfo obj = new tbBrandInfo(); obj.Id = Id; BrandsController.Delete(obj); _LoadBrand(); break; } }
public async void DeleteBrand_ReturnBrandDeleted(int id) { // Arrange var mockRepo = new Mock <IVehicleCatalogRepository>(); mockRepo.Setup(repo => repo.GetBrand(id)) .Returns(Task.FromResult <Brand>(new Brand() { Id = id, Name = "Brand 1" })); mockRepo.Setup(repo => repo.SaveAll()) .Returns(Task.FromResult <bool>(true)); var mapper = _dependencyFixture.ServiceProvider.GetService <IMapper>(); var logger = Mock.Of <ILogger <BrandsController> >(); var controller = new BrandsController(mockRepo.Object, mapper, logger); // Act var result = await controller.Delete(id); // Assert Assert.IsType <NoContentResult>(result); }
public async Task BrandsController_Delete_Success() { var createRequest = new BrandCreateRequest { Name = "Test brand6" }; var controller = new BrandsController(_fixture.BrandService); var createResult = await controller.Post(createRequest); var createResponse = GetResponse <BrandCreateResponse>(createResult); Assert.Equal("Test brand6", createResponse.Name); var deleteResult = await controller.Delete(createResponse.Id); Assert.IsType <OkResult>(deleteResult); var getResult = await controller.Get(createResponse.Id); var getOkResult = Assert.IsType <OkObjectResult>(getResult); Assert.Null(getOkResult.Value); }
public async Task DeleteReturnRedirectWithValidId() { // Arrange string successMessage = null; var resultBrand = new Brand(); var brandDb = DataHelper.GetBrand(); var adminBrandsService = new Mock <IAdminBrandsService>(); adminBrandsService .Setup(s => s.GetByIdAsync(It.IsAny <int>())) .ReturnsAsync(brandDb); adminBrandsService .Setup(s => s.DeleteAsync(It.IsAny <Brand>())) .Callback((Brand model) => { resultBrand = model; }) .Returns(Task.CompletedTask); var tempData = new Mock <ITempDataDictionary>(); tempData .SetupSet(t => t[WebConstants.TempDataSuccessMessageKey] = It.IsAny <string>()) .Callback((string key, object message) => successMessage = message as string); var controller = new BrandsController(adminBrandsService.Object, null); controller.TempData = tempData.Object; // Act var result = await controller.Delete(brandDb.Id); // Assert successMessage.Should().Be($"Brand {brandDb.Name} successfully deleted."); result.Should().BeOfType <RedirectToActionResult>(); result.As <RedirectToActionResult>().ActionName.Should().Be("Index"); }
public void Delete_ReturnsNoContentType_WhenBrandExists() { var result = brandController.Delete(existedBrandId); Assert.IsInstanceOf(typeof(NoContentResult), result); }