コード例 #1
0
ファイル: InventoryTest.cs プロジェクト: ClJarvis/BuildIt
        public void EnsureICanDeleteAProjectFromAnInventory()
        {
            //Begin Arrange
            var data = my_projects.AsQueryable();

            string ProjectName = "ToDo";

            mock_Projects.As<IQueryable<Project>>().Setup(m => m.Provider).Returns(data.Provider);
            mock_Projects.As<IQueryable<Project>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
            mock_Projects.As<IQueryable<Project>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mock_Projects.As<IQueryable<Project>>().Setup(m => m.Expression).Returns(data.Expression);

            mock_Projects.Setup(m => m.Add(It.IsAny<Project>())).Callback((Project p) => my_projects.Add(p));
            mock_Projects.Setup(m => m.Remove(It.IsAny<Project> ())).Callback((Project p) => my_projects.Remove(p));
            mock_context.Setup(m => m.Projects).Returns(mock_Projects.Object);

            InventoryRepository repo = new InventoryRepository(mock_context.Object);
            //End Arrange

            //Begin First Act
            Project NewProject = repo.CreateProject("ToDo", owner);

            // Begin first assert
            Assert.IsNotNull(NewProject);
            Assert.AreEqual(1, repo.GetProjectCount());

            // Begin second act
            Project removed_project = repo.DeleteProject("ToDo", owner);

            //Begin second Assert
            mock_Projects.Verify(m => m.Add(It.IsAny<Project>()));
            mock_context.Verify(x => x.SaveChanges(), Times.Exactly(2));
            repo.DeleteProject(removed_project);
            mock_Projects.Verify(x => x.Remove(It.IsAny<Project>()));
            mock_context.Verify(x => x.SaveChanges(), Times.Exactly(3));
            Assert.AreEqual(0, repo.GetProjectCount());
            //End Assert
        }
コード例 #2
0
ファイル: InventoryTest.cs プロジェクト: ClJarvis/BuildIt
        public void ListEnsureICanEditAProject()
        {
            //Begin Arrange
            var data = my_projects.AsQueryable();
               // InventoryRepository repo = new InventoryRepository(mock_context.Object);
               // Project list = new Project { ProjectName = "ToDo", ProjectId = 1 };
               // my_projects.Remove(new Project { ProjectName = "My First Project", Owner = user1, ProjectId = 1 });

            mock_Projects.As<IQueryable<Project>>().Setup(m => m.Provider).Returns(data.Provider);
            mock_Projects.As<IQueryable<Project>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
            mock_Projects.As<IQueryable<Project>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mock_Projects.As<IQueryable<Project>>().Setup(m => m.Expression).Returns(data.Expression);

            mock_Projects.Setup(m => m.Add(It.IsAny<Project>())).Callback((Project p) => my_projects.Add(p));

            mock_context.Setup(m => m.Projects).Returns(mock_Projects.Object);

            InventoryRepository repo = new InventoryRepository(mock_context.Object);

            //End Arrange

            Project projectToChange = repo.CreateProject("ToDo", owner);
            //Begin Act

            // Begin Assert
            Assert.IsNotNull(projectToChange);
            Assert.AreEqual(1, repo.GetProjectCount());

            projectToChange.ProjectName = "blah blah";
            // my_projects.Add(new Project { ProjectName = "My Next Board", Owner = user1, ProjectId = 1 });

            repo.UpdateProject(projectToChange);

            //End Act

            //Begin Assert
            var updatedProject = repo.GetProjectById(projectToChange.ProjectId);

            Assert.AreEqual(updatedProject.ProjectName, "blah blah");
            //End Assert
        }