public void ReturnRedirectToRouteResult_WhenIdIsCorrect() { // Arrange var mockedMappService = new Mock <IMapService>(); var employeeService = new Mock <IEmployeeService>(); EmployeesController emplController = new EmployeesController(mockedMappService.Object, employeeService.Object); var employeeId = 5; employeeService.Setup(x => x.DeleteById(employeeId)).Verifiable(); // Act emplController.DeleteConfirmed(employeeId); // Assert Assert.IsInstanceOf <RedirectToRouteResult>(emplController.DeleteConfirmed(employeeId)); }
public async Task DeletePostAction_DeleteModelFromService() { // Arrange // Act var result = await validController.DeleteConfirmed(entity.Id); // Assert mock.Verify(a => a.DeleteAsync(entity.Id)); }
public void PostDeleteConfirmedTest() { var mock = new Mock <IManager <Employee> >(); var controller = new EmployeesController(mock.Object); var result = controller.DeleteConfirmed(1) as RedirectToRouteResult; mock.Verify(m => m.Delete(It.Is <int>(x => x == 1)), Times.Once); Assert.IsNotNull(result); Assert.AreEqual("Index", result.RouteValues["action"]); }
private async Task DeleteAllEmployeesAsync() { var c = new EmployeesController(_context); var index = await c.Index(); var list = (Microsoft.AspNetCore.Mvc.ViewResult)index; var IndexEmployeeViewModel = (IndexEmployeeViewModel)list.Model; foreach (var employee in IndexEmployeeViewModel.EmployeeModels) { var result = await c.DeleteConfirmed(employee.EmployeeID); } }
public void testEmployeesControllerDeleteConfirmed() { //Arrange DbContextOptions <ProjectContext> context = new DbContextOptions <ProjectContext>(); ProjectContext projectContext = new ProjectContext(context); EmployeesController controller = new EmployeesController(projectContext); //Act var result = controller.DeleteConfirmed(1); //Assert Assert.NotNull(result); }
public async Task DeleteConfirmedWhenFoundEmployeeNotNull() { // ARRANGE var dummyUsers = new List <ApplicationUser> { new ApplicationUser { UserName = "******", Email = "*****@*****.**", ProvinceId = 1, PositionId = 1 } }.AsQueryable(); _userSet = MockingHelper.Create(dummyUsers); // Set the mocked db sets in the mocked db context _db.Setup(c => c.Users).Returns(_userSet.Object); // This value will get returned from UserManager ApplicationUser user = dummyUsers.ToList()[0]; var email = user.Email; // Manipulate the method in and UserManager so that it cannot find the user _userManager.Setup(x => x.FindByEmailAsync(email)).Returns(Task.FromResult(user)); _db.Setup(x => x.SaveChanges()).Returns(3); // ACT var result = await _controller.DeleteConfirmed(user); // ASSERT Assert.AreEqual(typeof(RedirectToRouteResult), result.GetType()); _userManager.Verify(x => x.FindByEmailAsync(It.IsAny <string>()), Times.Once); _userManager.Verify(x => x.DeleteAsync(It.IsAny <ApplicationUser>()), Times.Once); _userManager.Verify(x => x.RemoveFromRoleAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once); _db.Verify(x => x.SaveChanges(), Times.Once); }
public void DeleteTest() { var controller = new EmployeesController(); var result = controller.Index() as ViewResult; var employees = (ICollection <Employee>)result.ViewData.Model; var Id = employees.Last().EmployeeId; controller.DeleteConfirmed(Id); var result2 = controller.Index() as ViewResult; var employees2 = (ICollection <Employee>)result.ViewData.Model; Assert.AreNotEqual(Id, employees2.Last().EmployeeId); }
public void Delete() { //Arrange var EmployeeSizeMock = Builder <Employee> .CreateNew().Build(); var actualResult = _iRepositoryModel.Setup(fs => fs.getModelById <Employee>(1)).Returns(EmployeeSizeMock); //// Act var result = _EmployeesController.DeleteConfirmed(1); //// Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", viewResult.ActionName); }
public void DeleteConfirmed_Interaction() { // Setup. var mock = new Mock <IRepository>(); var id = 1; mock.Setup(a => a.GetEmployeesList()).Returns(new List <Employees>()); EmployeesController controller = new EmployeesController(mock.Object); // Execute. controller.DeleteConfirmed(id); // Verify. mock.Verify(x => x.Delete(id)); mock.Verify(x => x.Save()); }
public void DeleteRecord() { // Arrange EmployeesController controller = new EmployeesController(); // Act ViewResult result = controller.Index() as ViewResult; int iRecordCountBefore = (result.Model as List <Employee>).Count(); Employee employee = new Employee(); employee.DepartmentId = 1; employee.DeskLocation = "X999"; employee.FirstName = "Testy"; employee.LastName = "McTesterson"; employee.HomeAddress1 = "123 Banana Boulevard"; employee.HomeAddress2 = null; employee.HomeCity = "Las Vegas"; employee.HomePhone = "123-456-7890"; employee.HomeState = "NV"; employee.HomeZip = "88888"; employee.WorkPhone = "123-456-0987"; result = controller.Create(employee) as ViewResult; // Create the DB record. result = controller.Index() as ViewResult; // Read a list back. List <Employee> employees = result.Model as List <Employee>; int iRecordCountAfter = employees.Count(); bool addedRecord = (iRecordCountBefore + 1 == iRecordCountAfter); int employeeId = employees.First(x => (x.LastName == "McTesterson")).EmployeeId; // Clean up and delete confirmation. bool deleteWorked = true; // Assuming true as default for this test. try { result = controller.DeleteConfirmed(employeeId) as ViewResult; } catch { deleteWorked = false; } // Assert Assert.IsTrue(deleteWorked); }
public async void Delete_HttpPost_EmployeeEmployee_RedirectToIndexAction() { var id = 1; var employeeRepositroy = new Mock <IEmpoyeeRepository>(); employeeRepositroy.Setup(mock => mock.DeleteEmployee(id)); var employeeController = new EmployeesController(employeeRepositroy.Object); var result = await employeeController.DeleteConfirmed(id); employeeRepositroy.Verify(mock => mock.DeleteEmployee(id), Times.Once()); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); employeeController.Dispose(); }
public void Delete() { // Arrange var controller = new EmployeesController(this.MockContext.Object); // Act controller.Delete(2); controller.DeleteConfirmed(2); var result = controller.Index() as ViewResult; var mockedModels = result.Model as List <Employee>; // Assert Assert.IsNotNull(result); Assert.AreEqual(7, mockedModels.Count); Assert.AreEqual("Worker 1", mockedModels[0].FullName); Assert.AreEqual("Worker 3", mockedModels[1].FullName); }
public async System.Threading.Tasks.Task EmployeesDeleteDeletesAsync() { //Arrange Employees employeeTest = new Employees() { LastName = "test", FirstName = "test" }; await _EmployeesControllerUnderTest.Create(employeeTest); int expected = _db.Employees.Count() - 1; //Act await _EmployeesControllerUnderTest.DeleteConfirmed(employeeTest.EmployeeID); int actual = _db.Employees.Count(); //Assert Assert.AreEqual(expected, actual); }
public async void ShouldDeleteConfirmedItem() { //Arrange var dbContext = serviceProvider.GetRequiredService <EmployeeContext>(); CreateTestData(dbContext); var controller = new EmployeesController(dbContext); //Act var deleteResult = await controller.DeleteConfirmed(6); //Assert Assert.IsType <RedirectToActionResult>(deleteResult); var indexResult = await controller.Index(); var indexView = Assert.IsType <ViewResult>(indexResult); var model = Assert.IsAssignableFrom <IEnumerable <Employee> >(indexView.ViewData.Model); Assert.Equal(5, model.Count()); }
public void DeleteConfirmed_Negative(int id) { // Arrange. var mock = new Mock <IRepository>(); var expectedRoute = "Index"; var employeesList = new List <Employees>() { new Employees { Id = 1, FullName = "Фамилия Имя Отчество", Status = "активен", Position = "должность" } }; mock.Setup(a => a.GetEmployeesList()).Returns(employeesList); EmployeesController controller = new EmployeesController(mock.Object); // Act. RedirectToRouteResult result = controller.DeleteConfirmed(id) as RedirectToRouteResult; // Assert. Assert.AreEqual(expectedRoute, result.RouteValues["action"]); }
public void EditRecord() { // Arrange EmployeesController controller = new EmployeesController(); // Act ViewResult result = controller.Index() as ViewResult; int iRecordCountBefore = (result.Model as List <Employee>).Count(); Employee employee = new Employee(); employee.DepartmentId = 1; employee.DeskLocation = "X999"; employee.FirstName = "Testy"; employee.LastName = "McTesterson"; employee.HomeAddress1 = "123 Banana Boulevard"; employee.HomeAddress2 = null; employee.HomeCity = "Las Vegas"; employee.HomePhone = "123-456-7890"; employee.HomeState = "NV"; employee.HomeZip = "88888"; employee.WorkPhone = "123-456-0987"; result = controller.Create(employee) as ViewResult; // Create the DB record. employee.FirstName = "Testarino"; result = controller.Edit(employee) as ViewResult; // Edit the DB record. result = controller.Index() as ViewResult; // Read a list back. List <Employee> employees = result.Model as List <Employee>; int employeeId = employees.First(x => (x.FirstName == "Testarino")).EmployeeId; // Find the record we added. if (employeeId > -1) { controller.DeleteConfirmed(employeeId); // Clean up. } // Assert Assert.IsTrue((employeeId > -1)); }
public void The_Delete_Employee_Action_Returns_RedirectToRouteResult_When_The_Employee_Model_Is_Valid() { // Arrange const string expectedRouteName = "EmployeeDeleted"; var employee = new Employee() { EmployeeID = 1, }; var employeesController = new EmployeesController(_mockER.Object, _mockUW.Object); var routeData = new RouteData(); employeesController.ControllerContext = new ControllerContext(_mockHttpContext.Object, routeData, employeesController); employeesController.ModelState.Clear(); // Act var result = employeesController.DeleteConfirmed(1) as RedirectToRouteResult; // Assert Assert.AreEqual(2, _data.Count()); Assert.IsNotNull(result, "Should have returned a RedirectToRouteResult"); // Assert.AreEqual(expectedRouteName, result.RouteName, "Route name should have been {0}", expectedRouteName); }