public async Task Put_UpdatesEnrollment_IfValid_AndExists(
            int pathId,
            int id,
            bool shouldNotFind,
            bool shouldUpdateEnrollment,
            Type resultType
            )
        {
            var _enrollments = new Mock <IEnrollmentRepository>();

            if (shouldNotFind)
            {
                _enrollments.Setup(e => e.SaveChangesAsync())
                .Throws(new DbUpdateConcurrencyException());
            }

            var _sites  = new Mock <ISiteRepository>();
            var _mapper = new Mock <IMapper>();

            _mapper.Setup(m => m.Map <Enrollment, EnrollmentDTO>(It.IsAny <Enrollment>()))
            .Returns(It.IsAny <EnrollmentDTO>());

            var controller = new EnrollmentsController(_enrollments.Object, _sites.Object, _mapper.Object);

            var enrollment = new Enrollment {
                Id = id
            };

            var result = await controller.Put(pathId, 1, 1, enrollment);

            var times = shouldUpdateEnrollment ? Times.Once() : Times.Never();

            _enrollments.Verify(e => e.UpdateEnrollment(It.IsAny <Enrollment>(), It.IsAny <EnrollmentDTO>()), times);
            Assert.IsType(resultType, result.Result);
        }
        public async Task Get_IncludeEntities_GetsEnrollmentsForSite_WithEntities()
        {
            var _enrollments = new Mock <IEnrollmentRepository>();
            var _sites       = new Mock <ISiteRepository>();
            var _mapper      = new Mock <IMapper>();

            var controller = new EnrollmentsController(_enrollments.Object, _sites.Object, _mapper.Object);

            var siteId = 1;
            await controller.Get(1, siteId);

            _enrollments.Verify(e => e.GetEnrollmentsForSiteAsync(siteId, null, null, 0, null), Times.Once());
        }
Esempio n. 3
0
        public async Task DeleteByIdAndCourse_WithValidModel_ShouldReturnOk()
        {
            var mockService = new Mock <IEnrollmentService>();

            mockService.Setup(service => service.RemoveCourseFromStudentAsync(0, 0))
            .Returns(Task.CompletedTask)
            .Verifiable();
            var controller = new EnrollmentsController(mockService.Object);

            var response = await controller.Delete(0, new CourseViewModel());

            Assert.IsType <OkObjectResult>(response);
            mockService.Verify();
        }
Esempio n. 4
0
        public async Task PostByIdAndCourse_WithInvalidModel_ShouldReturnBadResponse()
        {
            var mockService = new Mock <IEnrollmentService>();

            mockService.Setup(service => service.AddCourseToStudentAsync(0, 0))
            .ReturnsAsync(null as Enrollment)
            .Verifiable();
            var controller = new EnrollmentsController(mockService.Object);

            var response = await controller.Post(0, new CourseViewModel());

            Assert.IsType <BadRequestObjectResult>(response);
            mockService.Verify();
        }
        public async Task Get_Id_IncludeEntities_GetsEnrollmentForSite_WithEntities()
        {
            var _enrollments = new Mock <IEnrollmentRepository>();
            var _sites       = new Mock <ISiteRepository>();
            var _mapper      = new Mock <IMapper>();

            var controller = new EnrollmentsController(_enrollments.Object, _sites.Object, _mapper.Object);

            var id      = 1;
            var siteId  = 1;
            var include = new string[] { "foo" };
            await controller.Get(id, 1, siteId);

            _enrollments.Verify(e => e.GetEnrollmentForSiteAsync(id, siteId), Times.Once());
        }
        public async Task Post_AddsEnrollment_IfValid(
            int id,
            bool shouldAddEnrollment,
            Type resultType
            )
        {
            var _enrollments = new Mock <IEnrollmentRepository>();
            var _sites       = new Mock <ISiteRepository>();
            var _mapper      = new Mock <IMapper>();

            var controller = new EnrollmentsController(_enrollments.Object, _sites.Object, _mapper.Object);

            var enrollment = new Enrollment {
                Id = id
            };

            var result = await controller.Post(1, 1, enrollment);

            var times = shouldAddEnrollment ? Times.Once() : Times.Never();

            _enrollments.Verify(e => e.AddEnrollment(It.IsAny <Enrollment>()), times);

            Assert.IsType(resultType, result.Result);
        }