public void createEmployeeTest() { //Arrange var controller = new AdminEmployeeController(new EmployeeBLL(new EmployeeDALStub()), new UserBLL(new UserDALStub()), new LoggingBLL(new LoggingDALStub())); //Act var result = (ViewResult)controller.createEmployee(); //Assert Assert.AreEqual(result.ViewName, ""); }
public void createEmployeeTestEmployeeAddFail() { //Arrange var context = new Mock<ControllerContext>(); var session = new Mock<HttpSessionStateBase>(); context.Setup(m => m.HttpContext.Session).Returns(session.Object); var controller = new AdminEmployeeController(new EmployeeBLL(new EmployeeDALStub()), new UserBLL(new UserDALStub()), new LoggingBLL(new LoggingDALStub())); controller.ControllerContext = context.Object; var employeeModel = new EmployeeModel(); employeeModel.employeeID = 1; employeeModel.firstName = ""; employeeModel.lastName = "Nordmann"; employeeModel.phone = "12345678"; employeeModel.orderAdmin = true; employeeModel.customerAdmin = false; employeeModel.databaseAdmin = false; employeeModel.employeeAdmin = false; employeeModel.password = "******"; employeeModel.productAdmin = false; employeeModel.username = ""; //Act var result = (ViewResult)controller.createEmployee(employeeModel); var resultModel = (EmployeeModel)result.Model; //Assert Assert.AreEqual(result.ViewName, ""); Assert.AreEqual(employeeModel.firstName, resultModel.firstName); Assert.AreEqual(employeeModel.customerAdmin, resultModel.customerAdmin); Assert.AreEqual(employeeModel.databaseAdmin, resultModel.databaseAdmin); Assert.AreEqual(employeeModel.employeeAdmin, resultModel.employeeAdmin); Assert.AreEqual(employeeModel.employeeID, resultModel.employeeID); Assert.AreEqual(employeeModel.lastName, resultModel.lastName); Assert.AreEqual(employeeModel.orderAdmin, resultModel.orderAdmin); Assert.AreEqual(employeeModel.password, resultModel.password); Assert.AreEqual(employeeModel.phone, resultModel.phone); Assert.AreEqual(employeeModel.username, resultModel.username); }
public void createEmployeeTestTrue() { //Arrange var context = new Mock<ControllerContext>(); var session = new Mock<HttpSessionStateBase>(); context.Setup(m => m.HttpContext.Session).Returns(session.Object); var controller = new AdminEmployeeController(new EmployeeBLL(new EmployeeDALStub()), new UserBLL(new UserDALStub()), new LoggingBLL(new LoggingDALStub())); controller.ControllerContext = context.Object; var employeeModel = new EmployeeModel(); employeeModel.employeeID = 1; employeeModel.firstName = "Ola"; employeeModel.lastName = "Nordmann"; employeeModel.phone = "12345678"; employeeModel.customerAdmin = false; employeeModel.databaseAdmin = false; employeeModel.orderAdmin = true; employeeModel.employeeAdmin = false; employeeModel.password = "******"; employeeModel.productAdmin = false; employeeModel.username = ""; //Act var result = (RedirectToRouteResult)controller.createEmployee(employeeModel); //Assert Assert.AreEqual(result.RouteName, ""); Assert.AreEqual(result.RouteValues.Values.First(), "AllEmployees"); }
public void createEmployeeTestNotValid() { //Arrange var controller = new AdminEmployeeController(new EmployeeBLL(new EmployeeDALStub()), new UserBLL(new UserDALStub()), new LoggingBLL(new LoggingDALStub())); controller.ViewData.ModelState.AddModelError("feil", "testfeil"); //Act var result = (ViewResult)controller.createEmployee(new EmployeeModel()); //Assert Assert.AreEqual(result.ViewName, ""); Assert.IsTrue(result.ViewData.ModelState.Count == 1); }