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, "");
 }
Ejemplo n.º 2
0
 public static AdminEmployeeController getMoqAdminEmployeeController()
 {
     var context = new Mock<ControllerContext>();
     var session = new MockHttpSession();
     context.Setup(m => m.HttpContext.Session).Returns(session);
     var controller = new AdminEmployeeController(new EmployeeBLL(new EmployeeDALStub()), new UserBLL(new UserDALStub()), new LoggingBLL(new LoggingDALStub()));
     controller.ControllerContext = context.Object;
     return controller;
 }
 public void AllEmployeesTest()
 {
     //Arrange
     var controller = new AdminEmployeeController(new EmployeeBLL(new EmployeeDALStub()), new UserBLL(new UserDALStub()), new LoggingBLL(new LoggingDALStub()));
     var list = new List<EmployeeModel>();
     var employeeModel = new EmployeeModel();
     employeeModel.employeeID = 1;
     employeeModel.firstName = "Ola";
     employeeModel.lastName = "Nordmann";
     employeeModel.phone = "12345678";
     employeeModel.customerAdmin = false;
     employeeModel.orderAdmin = true;
     employeeModel.databaseAdmin = false;
     employeeModel.employeeAdmin = false;
     employeeModel.password = "******";
     employeeModel.productAdmin = false;
     employeeModel.username = "******";
     list.Add(employeeModel);
     list.Add(employeeModel);
     list.Add(employeeModel);
     list.Add(employeeModel);
     //Act
     var result = (ViewResult)controller.AllEmployees();
     var resultList = (List<EmployeeModel>)result.Model;
     //Assert
     Assert.AreEqual(result.ViewName, "");
     Assert.AreEqual(resultList.Count, list.Count);
     for(int i = 0; i < resultList.Count; i++)
     {
         Assert.AreEqual(resultList[i].customerAdmin, list[i].customerAdmin);
         Assert.AreEqual(resultList[i].databaseAdmin, list[i].databaseAdmin);
         Assert.AreEqual(resultList[i].employeeAdmin, list[i].employeeAdmin);
         Assert.AreEqual(resultList[i].employeeID, list[i].employeeID);
         Assert.AreEqual(resultList[i].firstName, list[i].firstName);
         Assert.AreEqual(resultList[i].lastName, list[i].lastName);
         Assert.AreEqual(resultList[i].orderAdmin, list[i].orderAdmin);
         Assert.AreEqual(resultList[i].password, list[i].password);
         Assert.AreEqual(resultList[i].phone, list[i].phone);
         Assert.AreEqual(resultList[i].productAdmin, list[i].productAdmin);
         Assert.AreEqual(resultList[i].username, list[i].username);
     }
 }
 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);
 }