Exemplo n.º 1
0
 public void WhenRemovingTheProjectThenThereShouldBeNoProjectsLeft()
 {
     ProjectMemoryBackend.InternalProjects.Add(new Project {
         Id = 1, Name = "projectName"
     });
     ProjectsController.DeleteConfirmed(1);
     ProjectMemoryBackend.InternalProjects.Count.Should().Be(0);
 }
Exemplo n.º 2
0
        public void WhenRemovingTheProjectThenTheReturnedActionShouldBeIndex()
        {
            ProjectMemoryBackend.InternalProjects.Add(new Project {
                Id = 1, Name = "projectName"
            });
            var result = ProjectsController.DeleteConfirmed(1) as RedirectToRouteResult;

            result.RouteValues["action"].Should().Be("Index");
        }
Exemplo n.º 3
0
 public void WhenMultipleProjectsExistRemovingASingleProjectThenThereShouldBeOneProjectsLeft()
 {
     ProjectMemoryBackend.InternalProjects.Add(new Project {
         Id = 1, Name = "projectName"
     });
     ProjectMemoryBackend.InternalProjects.Add(new Project {
         Id = 2, Name = "projectName2"
     });
     ProjectsController.DeleteConfirmed(1);
     ProjectMemoryBackend.InternalProjects.Count.Should().Be(1);
 }
Exemplo n.º 4
0
        private async Task DeleteAllProjectsAsync()
        {
            var c     = new ProjectsController(_context);
            var index = await c.Index();

            var list = (Microsoft.AspNetCore.Mvc.ViewResult)index;

            foreach (var project in (List <ProjectModel>)list.Model)
            {
                var result = await c.DeleteConfirmed(project.ProjectID);
            }
        }
Exemplo n.º 5
0
        public void DeleteConfirmed()
        {
            // ARRANGE
            var dummyProjects = new List <Project>
            {
                new Project
                {
                    ProjectId   = 1,
                    Description = "Dummy Project 1"
                },
                new Project
                {
                    ProjectId   = 2,
                    Description = "Dummy Project 2"
                }
            }.AsQueryable();


            // Mock the project DbSet and ApplicationDbContext
            _projectSet = MockingHelper.Create(dummyProjects);
            _db.Setup(x => x.Projects).Returns(_projectSet.Object);

            _db.Setup(x => x.Projects.Remove(It.IsAny <Project>())).Returns(dummyProjects.ToList()[1]);

            _db.Setup(x => x.Projects.Find())
            .Returns(dummyProjects.ToList()[1]);

            _db.Setup(c => c.SaveChanges()).Returns(1);

            // ACT - delete the Project with id 2
            var result = _controller.DeleteConfirmed(2);

            // ASSERT
            Assert.AreNotEqual(null, result);

            // check if the method on DbSet was called
            _db.Verify(x => x.Projects.Find(It.IsAny <int>()), Times.Once);
            _db.Verify(x => x.Projects.Remove(It.IsAny <Project>()), Times.Once);
        }
Exemplo n.º 6
0
        public void WhenTheProjectDoesNotExistTheResultShouldGiveAnError()
        {
            var result = ProjectsController.DeleteConfirmed(1) as HttpNotFoundResult;

            result.StatusDescription.Should().Be("Project does not exist");
        }