public void TimeLogController_TestCreateTimeLogWithLogDateBeforeProjectStart()
        {
            // Arrange
            timeLogController.ControllerContext.HttpContext.Session["UserID"] = 1;
            var timeLogToAdd = new TimeLog {
                userId = 1, customerId = 1, projectId = 1, date = DateTime.Parse("2017-06-13"), timeSpentInHours = 10, project = projectList.Where(c => c.projectId == 1).FirstOrDefault()
            };

            //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/13/2017"), false);

            //Act
            var result2 = timeLogController.Create(timeLogToAdd) as ViewResult;
            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/13/2017"), false);

            Assert.AreEqual("Log date cannot be before project start.", result2.ViewData["Message"]);
        }
        public void TimeLogController_TestEditTimeLogAlsoUpdatesProjectTime()
        {
            // Arrange
            timeLogController.ControllerContext.HttpContext.Session["UserID"] = 1;
            var timeLogToAddAndEdit = new TimeLog {
                userId = 1, customerId = 1, projectId = 1, date = DateTime.Parse("2017-06-19"), timeSpentInHours = 10, project = projectList.Where(c => c.projectId == 1).FirstOrDefault()
            };

            timeLogController.Create(timeLogToAddAndEdit);

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

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

            //Act
            timeLogToAddAndEdit.date = DateTime.Parse("2017-06-20");
            var result2 = timeLogController.Edit(timeLogToAddAndEdit) as ViewResult;
            var result  = timeLogController.Index("", "") as ViewResult;

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

            Assert.AreEqual(3, timeLogs.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(timeLogs, "Quidditch", "6/19/2017"), false);
            Assert.AreEqual(UnitTestsHelper.ListContains(timeLogs, "Quidditch", "6/20/2017"), true);
        }
Exemple #3
0
        public void CustomerController_TestEditCustomer()
        {
            // Arrange
            customerController.ControllerContext.HttpContext.Session["UserID"] = 1;
            var customerToAddAndEdit = new Customer {
                firstName = "SiriusTest", lastName = "BlackTest", status = CustomerStatus.Active
            };

            customerController.Create(customerToAddAndEdit);

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

            Assert.AreEqual(3, customers1.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers1, "SiriusTest"), true);

            //Act
            customerToAddAndEdit.firstName = "SiriusTest1";
            customerController.Edit(customerToAddAndEdit);
            var result = customerController.Index("") as ViewResult;

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

            Assert.AreEqual(3, customers.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers, "SiriusTest"), false);
            Assert.AreEqual(UnitTestsHelper.ListContains(customers, "SiriusTest1"), true);
        }
        public void ProjectController_TestEditProject()
        {
            // Arrange
            projectController.ControllerContext.HttpContext.Session["UserID"] = 1;
            var projectToAddAndEdit = new Project {
                customerId = 2, userId = 1, name = "Elf Liberation", startDate = DateTime.Parse("2017-07-14"), expectedEndDate = DateTime.Parse("2018-08-14"), status = ProjectStatus.InProgress, customer = customerList.Where(c => c.customerId == 2).FirstOrDefault()
            };

            projectController.Create(projectToAddAndEdit);

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

            Assert.AreEqual(2, projects1.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects1, "Elf Liberation"), true);

            //Act
            projectToAddAndEdit.name = "Elf Liberation1";
            projectController.Edit(projectToAddAndEdit);
            var result = projectController.Index("") as ViewResult;

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

            Assert.AreEqual(2, projects.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects, "Elf Liberation"), false);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects, "Elf Liberation1"), true);
        }
        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);
        }
Exemple #7
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);
        }
Exemple #9
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);
        }