public void Delete_Not_Ajax_Request() { // Arrange var id = 1; var menuItem = new MenuItem() { ID = 1, Position = 1, Title = "Strona główna", ActionName = "Index", ControllerName = "Home" }; var service = Substitute.For <IMenuItemRepository>(); var mapper = Substitute.For <IMapper>(); var fakeController = new FakeController(); var controller = new MenuItemController(service, mapper); fakeController.PrepareFakeRequest(); controller.ControllerContext = fakeController.GetControllerContext <MenuItemController>(new RouteData(), controller); service.Get(id).Returns(menuItem); // Act var result = controller.Delete(id) as RedirectToRouteResult; var ajaxRequest = controller.Request.IsAjaxRequest(); var actionName = result.RouteValues.Values.ElementAt(0); // Assert Assert.That(result, !Is.Null); Assert.That(ajaxRequest, Is.False); Assert.That("Index", Is.EqualTo(actionName)); }
public void Good_Delete() { // Arrange var id = 1; var menuItem = new MenuItem() { ID = 1, Position = 1, Title = "Strona główna", ActionName = "Index", ControllerName = "Home" }; var service = Substitute.For <IMenuItemRepository>(); var mapper = Substitute.For <IMapper>(); var fakeController = new FakeController(); var controller = new MenuItemController(service, mapper); fakeController.PrepareFakeAjaxRequest(); controller.ControllerContext = fakeController.GetControllerContext <MenuItemController>(new RouteData(), controller); service.Get(id).Returns(menuItem); service.Delete(menuItem); service.Save(); // Act var result = controller.Delete(id) as JsonResult; var ajaxRequest = controller.Request.IsAjaxRequest(); var jsonRequestBehavior = result.JsonRequestBehavior; var data = result.Data; // Assert Assert.That(result, !Is.Null); Assert.That(ajaxRequest, Is.True); Assert.That(JsonRequestBehavior.AllowGet, Is.EqualTo(jsonRequestBehavior)); Assert.That("", Is.EqualTo(data)); }
private void deleteBtn_Click(object sender, EventArgs e) { int id = int.Parse(IdText.Text); if (controller.Delete(id)) { MessageBox.Show(null, "Menu item deleted successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); //refresh table dataGrid.DataSource = controller.ViewAll(); } else { MessageBox.Show(null, "Something went wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Delete_Id_Is_Null() { // Arrange int?id = null; var mapper = Substitute.For <IMapper>(); var service = Substitute.For <IMenuItemRepository>(); var controller = new MenuItemController(service, mapper); // Act var result = controller.Delete(id) as HttpStatusCodeResult; var statusCode = result.StatusCode; // Assert Assert.That(result, !Is.Null); Assert.That(400, Is.EqualTo(statusCode)); }
public void Delete_Model_Null() { // Arrange var id = -1; MenuItem menuItem = null; var service = Substitute.For <IMenuItemRepository>(); var mapper = Substitute.For <IMapper>(); var controller = new MenuItemController(service, mapper); service.Get(id).Returns(menuItem); // Act var result = controller.Delete(id) as HttpNotFoundResult; var statusCode = result.StatusCode; // Assert Assert.That(result, !Is.Null); Assert.That(404, Is.EqualTo(statusCode)); }