public void SetupTests()
        {
            context = new Mock <ClockContext>();
            List <User> userList = new List <User>
            {
                new User {
                    userId = 1, firstName = "BillTest", lastName = "WeasleyTest", email = "*****@*****.**", password = "******", repeatPassword = "******"
                },
                new User {
                    userId = 2, firstName = "CharlieTest", lastName = "WeasleyTest", email = "*****@*****.**", password = "******", repeatPassword = "******"
                }
            };

            customerList = new List <Customer>
            {
                new Customer {
                    userId = 1, customerId = 1, firstName = "HarryTest", lastName = "PotterTest", status = CustomerStatus.Active
                },
                new Customer {
                    userId = 1, customerId = 2, firstName = "HermioneTest", lastName = "GrangerTest", status = CustomerStatus.Active
                },
                new Customer {
                    userId = 2, customerId = 3, firstName = "RonTest", lastName = "WeasleyTest", status = CustomerStatus.Active
                }
            };

            projectList = new List <Project>
            {
                new Project {
                    userId = 1, customerId = 1, projectId = 1, name = "Quidditch", startDate = DateTime.Parse("2017-06-14"), expectedEndDate = DateTime.Parse("2017-08-14"), status = ProjectStatus.InProgress, timeSpentInHours = 20, customer = customerList.Where(c => c.customerId == 1).FirstOrDefault()
                },
                new Project {
                    userId = 2, customerId = 3, projectId = 2, name = "Fantastic Beasts", startDate = DateTime.Parse("2017-07-14"), expectedEndDate = DateTime.Parse("2018-08-14"), status = ProjectStatus.InProgress, timeSpentInHours = 5, customer = customerList.Where(c => c.customerId == 3).FirstOrDefault()
                }
            };
            context.Setup(c => c.Set <User>()).Returns(() => UnitTestsHelper.GetQueryableMockDbSet(userList));
            context.Setup(c => c.Set <Customer>()).Returns(() => UnitTestsHelper.GetQueryableMockDbSet(customerList));

            Func <Project, int> getClassId = project1 => project1.projectId;

            context.Setup(c => c.Set <Project>()).Returns(() => UnitTestsHelper.GetQueryableMockDbSet(projectList, getClassId));


            var uow = new UnitOfWork(context.Object);

            homeController = new HomeController(uow);
            homeController.ControllerContext = UnitTestsHelper.GetContextBase().Object;
            customerController = new CustomerController(uow);
            customerController.ControllerContext = UnitTestsHelper.GetContextBase().Object;
            projectController = new ProjectController(uow);
            projectController.ControllerContext = UnitTestsHelper.GetContextBase().Object;
        }
        public void TimeLogController_TestRepositoryCallToReturnOnlyUserRelatedTimeLogsInIndexView()
        {
            // Arrange
            timeLogController.ControllerContext.HttpContext.Session["UserID"] = 1;

            //Act
            var result = timeLogController.Index("", "") as ViewResult;

            //Assert
            var timeLogs = (IEnumerable <TimeLog>)result.ViewData.Model;

            Assert.AreEqual(2, timeLogs.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(timeLogs, "Quidditch", "6/18/2017"), true);
            Assert.AreEqual(UnitTestsHelper.ListContains(timeLogs, "Fantastic Beasts", "7/15/2017"), false);
        }
        public void ProjectController_TestRepositoryCallToReturnOnlyUserRelatedProjectsInIndexView()
        {
            // Arrange
            projectController.ControllerContext.HttpContext.Session["UserID"] = 1;

            //Act
            var result = projectController.Index("") as ViewResult;

            //Assert
            var projects = (IEnumerable <Project>)result.ViewData.Model;

            Assert.AreEqual(1, projects.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects, "Quidditch"), true);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects, "Fantastic Beasts"), false);
        }
Ejemplo n.º 4
0
        public void SetupTests()
        {
            context  = new Mock <ClockContext>();
            userList = new List <User>
            {
                new User {
                    firstName = "BillTest", lastName = "WeasleyTest", email = "*****@*****.**", password = "******", repeatPassword = "******"
                }
            };
            context.Setup(c => c.Set <User>()).Returns(() => UnitTestsHelper.GetQueryableMockDbSet(userList));

            var uow = new UnitOfWork(context.Object);

            homeController = new HomeController(uow);
            homeController.ControllerContext = UnitTestsHelper.GetContextBase().Object;
        }
Ejemplo n.º 5
0
        public void CustomerController_TestRepositoryCallToReturnOnlyUserRelatedCustomersInIndexView()
        {
            // Arrange
            customerController.ControllerContext.HttpContext.Session["UserID"] = 2;

            //Act
            var result = customerController.Index("") as ViewResult;

            //Assert
            var customers = (IEnumerable <Customer>)result.ViewData.Model;

            Assert.AreEqual(1, customers.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers, "RonTest"), true);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers, "HarryTest"), false);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers, "HermioneTest"), false);
        }
        public void TimeLogController_TestDeleteTimeLog()
        {
            // Arrange
            timeLogController.ControllerContext.HttpContext.Session["UserID"] = 1;
            int idToDelete = timeLogList.Where(c => c.project.name == "Quidditch" && c.date.Date.ToShortDateString() == "6/18/2017").FirstOrDefault().timeLogId;

            //Check
            var result1   = timeLogController.Index("", "") as ViewResult;
            var timeLogs1 = (IEnumerable <TimeLog>)result1.ViewData.Model;

            Assert.AreEqual(2, timeLogs1.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(timeLogs1, "Quidditch", "6/18/2017"), true);

            //Act
            timeLogController.Delete(idToDelete);
            var result = timeLogController.Index("", "") as ViewResult;

            //Assert
            var timeLogs = (IEnumerable <TimeLog>)result.ViewData.Model;

            Assert.AreEqual(1, timeLogs.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(timeLogs, "Quidditch", "6/18/2017"), false);
        }
Ejemplo n.º 7
0
        public void CustomerController_TestDeleteCustomer()
        {
            // Arrange
            customerController.ControllerContext.HttpContext.Session["UserID"] = 1;
            int idToDelete = customerList.Where(c => c.firstName == "HarryTest").FirstOrDefault().customerId;

            //Check
            var result1    = customerController.Index("") as ViewResult;
            var customers1 = (IEnumerable <Customer>)result1.ViewData.Model;

            Assert.AreEqual(2, customers1.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers1, "HarryTest"), true);

            //Act
            customerController.Delete(idToDelete);
            var result = customerController.Index("") as ViewResult;

            //Assert
            var customers = (IEnumerable <Customer>)result.ViewData.Model;

            Assert.AreEqual(1, customers.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers, "HarryTest"), false);
        }
        public void ProjectController_TestDeleteProject()
        {
            // Arrange
            projectController.ControllerContext.HttpContext.Session["UserID"] = 1;
            int idToDelete = projectList.Where(c => c.name == "Quidditch").FirstOrDefault().projectId;

            //Check
            var result1   = projectController.Index("") as ViewResult;
            var projects1 = (IEnumerable <Project>)result1.ViewData.Model;

            Assert.AreEqual(1, projects1.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects1, "Quidditch"), true);

            //Act
            projectController.Delete(idToDelete);
            var result = projectController.Index("") as ViewResult;

            //Assert
            var projects = (IEnumerable <Project>)result.ViewData.Model;

            Assert.AreEqual(0, projects.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects, "Quidditch"), false);
        }
Ejemplo n.º 9
0
        public void SetupTests()
        {
            context  = new Mock <ClockContext>();
            userList = new List <User>
            {
                new User {
                    userId = 1, firstName = "BillTest", lastName = "WeasleyTest", email = "*****@*****.**", password = "******", repeatPassword = "******"
                },
                new User {
                    userId = 2, firstName = "CharlieTest", lastName = "WeasleyTest", email = "*****@*****.**", password = "******", repeatPassword = "******"
                }
            };
            customerList = new List <Customer>
            {
                new Customer {
                    userId = 1, customerId = 1, firstName = "HarryTest", lastName = "PotterTest", status = CustomerStatus.Active
                },
                new Customer {
                    userId = 1, customerId = 2, firstName = "HermioneTest", lastName = "GrangerTest", status = CustomerStatus.Active
                },
                new Customer {
                    userId = 2, customerId = 3, firstName = "RonTest", lastName = "WeasleyTest", status = CustomerStatus.Active
                }
            };
            context.Setup(c => c.Set <User>()).Returns(() => UnitTestsHelper.GetQueryableMockDbSet(userList));

            Func <Customer, int> getClassId = customer1 => customer1.customerId;

            context.Setup(c => c.Set <Customer>()).Returns(() => UnitTestsHelper.GetQueryableMockDbSet(customerList, getClassId));

            var uow = new UnitOfWork(context.Object);

            homeController = new HomeController(uow);
            homeController.ControllerContext = UnitTestsHelper.GetContextBase().Object;
            customerController = new CustomerController(uow);
            customerController.ControllerContext = UnitTestsHelper.GetContextBase().Object;
        }