コード例 #1
0
        public void UpdateProject_Failure_Test()
        {
            ProjectViewModel pjVM = new ProjectViewModel();

            pjVM.ProjectName = "testproj2";
            pjVM.StartDate   = DateTime.Now;
            pjVM.EndDate     = DateTime.Now.AddDays(1);
            pjVM.Priority    = 10;
            pjVM.UserId      = 1;
            pjVM.ProjectId   = 1;
            Project pj1 = new Project();

            pj1.ProjectName = "testproj1";
            pj1.StartDate   = DateTime.Now;
            pj1.EndDate     = DateTime.Now.AddDays(1);
            pj1.Priority    = 10;
            pj1.UserId      = 1;
            pj1.ProjectId   = 1;
            Project pj2 = new Project();

            pj2.ProjectName = "testproj2";
            pj2.StartDate   = DateTime.Now;
            pj2.EndDate     = DateTime.Now.AddDays(1);
            pj2.Priority    = 10;
            pj2.UserId      = 1;
            pj2.ProjectId   = 2;
            List <Project> projList = new List <Project>();

            projList.Add(pj1);
            projList.Add(pj2);
            IQueryable <Project> Projects = projList.AsQueryable();
            var mockRepo = new Mock <IProjectRepository>();

            mockRepo.Setup(p => p.GetAllProject()).Returns(Projects);
            mockRepo.Setup(p => p.GetProjectById(pjVM.ProjectId)).Returns(pj1);
            var handler = new ProjectHandler(mockRepo.Object);

            Assert.That(() => handler.UpdateProject(pjVM),
                        Throws.TypeOf <CustomException>());
            mockRepo.Verify(mock => mock.GetProjectById(pjVM.ProjectId), Times.Once());
        }