public async Task should_delegate_to_repo_to_delete_document_and_update_denormalized_data_in_certification()
        {
            var objectId            = ObjectId.Parse(Id);
            var certId              = ObjectId.Parse(CertId);
            var courseCursor        = StubCursor <Course>(CourseCollectionName);
            var certificationCursor = StubCursor <Certification>(CertCollectionName);
            var course              = new Course {
                Id = objectId, CertificationId = CertId
            };
            var cert = new Certification {
                Id = certId, Courses = new List <DenormalizedCourse> {
                    new DenormalizedCourse {
                        Id = objectId
                    }, new DenormalizedCourse {
                        Id = ObjectId.Empty
                    }
                }
            };

            StubSingleFoundResult(courseCursor, course);
            StubSingleFoundResult(certificationCursor, cert);
            Repository.Setup(x => x.DeleteAsync(CourseCollectionName, It.IsAny <Expression <Func <Course, bool> > >()))
            .ReturnsAsync(new DeleteResult.Acknowledged(1));

            await _controller.Delete(Id);

            Repository.Verify(x => x.DeleteAsync(CourseCollectionName,
                                                 It.Is <Expression <Func <Course, bool> > >(e => Lambda.Eq(e, f => f.Id == objectId))));
            Repository.Verify(x => x.UpdateAsync(CertCollectionName,
                                                 It.Is <Expression <Func <Certification, bool> > >(e => Lambda.Eq(e, f => f.Id == certId)), It.IsAny <Certification>()));
            cert.Courses.Count.Should().Be(1);
        }
Exemple #2
0
        public async Task ReturnNoContentResponseWhenCourseDeleted()
        {
            var courseCtrl = new CourseController(_mapper.Object, _courseService.Object);
            var actual     = await courseCtrl.Delete(1);

            var okResult = Assert.IsType <NoContentResult>(actual);
        }
Exemple #3
0
        public void CourseControllerCanDeleteWhenNoStudents()
        {
            DbContextOptions <EnrollmentDbContext> options =
                new DbContextOptionsBuilder <EnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (EnrollmentDbContext context = new EnrollmentDbContext(options))
            {
                Course course = new Course();
                course.ID           = 1;
                course.ClassName    = ClassName.Python;
                course.Instructor   = "Miss Snake";
                course.StartingDate = new DateTime(2012, 12, 12);
                course.EndDate      = new DateTime(2012, 12, 25);

                CourseController cc = new CourseController(context);
                var x = cc.Create(course);

                var y = cc.Delete(1);

                var results = context.Course.Where(a => a.Instructor == "Miss Snake");

                Assert.Equal(0, results.Count());
            }
        }
        public async void CanDeleteCourse()
        {
            DbContextOptions <MetalDbContext> options =
                new DbContextOptionsBuilder <MetalDbContext>()
                .UseInMemoryDatabase("CanDeleteCourse")
                .Options;

            using (MetalDbContext context = new MetalDbContext(options))
            {
                Course course1 = new Course();
                course1.ID = 1;
                Course course2 = new Course();
                course2.ID = 2;
                Course course3 = new Course();
                course3.ID = 3;

                await context.Courses.AddAsync(course1);

                await context.Courses.AddAsync(course2);

                await context.Courses.AddAsync(course3);

                await context.SaveChangesAsync();

                var findCourse = context.Courses.Find(1);

                CourseController cc = new CourseController(context);

                var deleteCourse = cc.Delete(1);

                Assert.Equal(2, context.Courses.Count());
            }
        }
Exemple #5
0
        public void CourseControllerCanDelete()
        {
            DbContextOptions <Lab13StudentEnrollmentDbContext> options =
                new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options))
            {
                // Arrange
                Course course = new Course();
                course.Name        = "DotNet";
                course.Description = "Embrace the flood";

                CourseController cc = new CourseController(context);

                var x = cc.Create(course);
                // Act

                var y = cc.Delete(course.ID);

                var results = context.Courses.Where(a => a.Name == "DotNet");
                // Assert
                Assert.Equal(0, results.Count());
            }
        }
        public ActionResult DeleteStudentCourses(int courseid)
        {
            string username = User.Identity.Name;
            int    si       = s.Get(username).StudentID;

            bool var = c.Delete(si, courseid);

            return(PartialView("_DropCoursePartial", c.GetStudentCourses(si)));
        }
Exemple #7
0
        public void DeleteReturnsOk()
        {
            // Arrange
            var controller = new CourseController(_inMemoryRep);

            // Act
            IHttpActionResult actionResult = controller.Delete(8);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkResult));
        }
        public void Get_returns_delete_view_with_id_as_a_model()
        {
            #region Act
            var view = (ViewResult)CourseController.Delete(1);
            #endregion

            #region Assert
            Assert.IsEmpty(view.ViewName);
            Assert.That(view.ViewData.Model, Is.EqualTo(1));
            #endregion
        }
        public void DeleteReturnsOk_Moq()
        {
            // Arrange
            var mockRepository = new Mock <ICourseRepository>();
            var controller     = new CourseController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Delete(8);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkResult));
        }
Exemple #10
0
        public void ShouldDeleteCorrectly()
        {
            Mock <IGenericService <Course> >      courseServiceMock = new Mock <IGenericService <Course> >();
            Mock <IActivityLoggerService>         loggerMock        = new Mock <IActivityLoggerService>();
            Mock <IObjectFinderService <Module> > moduleFinderMock  = new Mock <IObjectFinderService <Module> >();
            Mock <IGenericService <Module> >      moduleServiceMock = new Mock <IGenericService <Module> >();
            Mock <IManyToManyMapperService <Course, CourseModule, Module> > mapperServiceMock = new Mock <IManyToManyMapperService <Course, CourseModule, Module> >();
            Mock <IGenericService <ExamProgram> > examProgramServiceMock = new Mock <IGenericService <ExamProgram> >();

            CourseCreateUpdateViewModel course = new CourseCreateUpdateViewModel()
            {
                Id          = 100,
                Name        = "Periode 2.3 Data Science",
                Description = "Alle opdrachten in deze periode zijn gekoppeld aan vakken; dit kunnen individuele of groepsopdrachten zijn; er zijn geen opdrachten die meerdere vakken betreffen. Daarom is een verdere omschrijving hier niet nodig."
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            moduleFinderMock.Setup(m => m.AreIdsValid(It.IsAny <string[]>())).Returns(true);

            moduleFinderMock.Setup(m => m.GetObjects(It.IsAny <int[]>())).Returns((int[] ids) =>
            {
                return(new List <Module>());
            });

            courseServiceMock.Setup(m => m.FindById(It.IsAny <int>(), It.IsAny <string[]>())).Returns(course);

            courseServiceMock.Setup(m => m.Delete(It.IsAny <Course>())).Returns((Course model) =>
            {
                return(1);
            });

            loggerMock.Setup(m => m.Delete(It.IsAny <string>()));

            CourseController controller = new CourseController(courseServiceMock.Object, moduleServiceMock.Object, moduleFinderMock.Object, mapperServiceMock.Object, examProgramServiceMock.Object, null)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            RedirectToActionResult result = controller.Delete(course.Id) as RedirectToActionResult;

            Assert.Equal("Index", result?.ActionName);
        }
Exemple #11
0
        public async Task ReturnNotFoundResponseIfEntityDoesNotExistDeleteMethod()
        {
            _courseService.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(() => null);
            var courseCtrl = new CourseController(_mapper.Object, _courseService.Object);
            var actual     = await courseCtrl.Delete(1);

            var notFoundResult = Assert.IsType <NotFoundObjectResult>(actual);

            Assert.Equal(404, notFoundResult.StatusCode);
            Assert.Equal("Entity does not exist.", notFoundResult.Value);

            _courseService.Verify(x => x.DeleteAsync(It.IsAny <Course>()), Times.Never);
        }
        public void Delete_CoursePriority()
        {
            // Arrange
            var courseManagerMock = new Mock <ICourseManager>(MockBehavior.Strict);

            courseManagerMock.Setup(manager => manager.Delete(It.IsAny <CoursePriority>()));

            CourseController controller = new CourseController(courseManagerMock.Object);

            // Act
            controller.Delete(GetDummyCourse());

            // Assert
            courseManagerMock.Verify(manager => manager.Delete(It.IsAny <CoursePriority>()));
        }
Exemple #13
0
        public async Task ReturnNotFoundResponseIfEntityDoesNotExistDeleteMethod()
        {
            var options = new DbContextOptionsBuilder <UniversityContext>()
                          .UseInMemoryDatabase(databaseName: "Delete-exception_controller")
                          .Options;

            using (var context = new UniversityContext(options))
            {
                var service = new CourseService(context);
                var ctrl    = new CourseController(_mapper, service);
                var actual  = await ctrl.Delete(1);

                var notFoundResult = Assert.IsType <NotFoundObjectResult>(actual);
                Assert.Equal(404, notFoundResult.StatusCode);
                Assert.Equal("Entity does not exist.", notFoundResult.Value);
            }
        }
Exemple #14
0
        public void Delete_RedirectsToCourses_WhenCourseExists()
        {
            //Arrange
            Course course = new Course()
            {
                Name = "Test course"
            };
            CourseService courseService = Substitute.For <CourseService>();

            courseService.GetCourse(5).Returns(course);
            CourseController controller = new CourseController(courseService, null, null);

            //Act
            var actionResult = controller.Delete(course.Id);

            // Assert
            actionResult.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be("Courses");
        }
Exemple #15
0
        public async Task DeleteCourse()
        {
            var options = new DbContextOptionsBuilder <UniversityContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_from_controller")
                          .Options;

            using (var context = new UniversityContext(options))
            {
                List <Course> courses = new List <Course>()
                {
                    new Course
                    {
                        Name        = "English",
                        TeacherName = "William Shakespeare",
                        Location    = "Building 3 Room 301"
                    },
                    new Course
                    {
                        Name        = "Psychology",
                        TeacherName = "Sigmund Freud",
                        Location    = "Building 4 Room 401"
                    },
                    new Course
                    {
                        Name        = "Philosophy",
                        TeacherName = "Friedrich Nietzsche",
                        Location    = "Building 5 Room 501"
                    }
                };
                await context.Courses.AddRangeAsync(courses);

                await context.SaveChangesAsync();
            }

            using (var context = new UniversityContext(options))
            {
                var service = new CourseService(context);
                var ctrl    = new CourseController(_mapper, service);
                var result  = await ctrl.Delete(context.Courses.First().Id);

                var okResult = Assert.IsType <NoContentResult>(result);
                Assert.Equal(204, okResult.StatusCode);
            }
        }
        public void Delete_RedirectToCourses()
        {
            // Arrange
            int courseId = 42;

            var courseSericeMock = Substitute.For <CourseService>();

            courseSericeMock.DeleteCourse(courseId).Returns(true);
            var controller = new CourseController(courseSericeMock, null, null, null, null);

            // Act
            var result = controller.Delete(courseId);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Courses", redirectToActionResult.ActionName);
        }
        public void DeleteCourseTest()
        {
            Course deleteCourseTestData;

            deleteCourseTestData = CourseTestData.GetTestDataCourseDelete();

            var expectedCourse = Task.FromResult(deleteCourseTestData);

            mockCourseRepository.Setup(m => m.Course.GetCourseByIdAsync(deleteCourseTestData.Id)).Returns(expectedCourse);
            mockCourseRepository.Setup(m => m.Course.DeleteCourse(deleteCourseTestData)).Returns(true);

            OkObjectResult content        = courseController.Delete(deleteCourseTestData.Id).Result as OkObjectResult;
            HttpStatusCode httpStatusCode = (HttpStatusCode)content.StatusCode;

            var response = content.Value as ResponseModel <Course>;
            var actualDeleteSuccessMessage = response.Message;

            Assert.AreEqual(httpStatusCode, HttpStatusCode.OK);
            Assert.AreEqual(ResponseMessage.OnSuccessDeleteMessage, actualDeleteSuccessMessage);
        }
        public async void CanDeleteCourse()
        {
            DbContextOptions <SchoolDbContext> options = new DbContextOptionsBuilder <SchoolDbContext>()
                                                         .UseInMemoryDatabase("CourseDeleteTestDb")
                                                         .Options;

            using (SchoolDbContext context = new SchoolDbContext(options))
            {
                // arrange
                Course course1 = new Course();
                course1.ID         = 55;
                course1.Name       = "Advanced Anger Management";
                course1.Teacher    = "Bob Saget";
                course1.CourseTerm = CourseTerm.Fall2018;

                Course course2 = new Course();
                course2.ID         = 66;
                course2.Name       = "Making Unit Tests";
                course2.Teacher    = "Ron Testmaster";
                course2.CourseTerm = CourseTerm.Winter2018;

                CourseController testCC = new CourseController(context);

                // act
                await testCC.Create(course1);

                await testCC.Create(course2);

                var x = await testCC.Delete(55);

                var y = await testCC.DeleteConfirmed(55);

                var result1 = context.Courses.Where(a => a.Name == "Advanced Anger Management");
                var result2 = context.Courses.Where(a => a.Name == "Making Unit Tests");

                //Assert
                Assert.IsAssignableFrom <IActionResult>(x);
                Assert.Equal(0, result1.Count());
                Assert.Equal(1, result2.Count());
            }
        }