public async Task should_call_find_on_collection_returning_all_results()
        {
            var result = await ExecuteEndpoint(_controller.Get());

            Repository.Verify(x => x.Find(CourseCollectionName, It.IsAny <FilterDefinition <Course> >()));
            result.Should().HaveCount(25);
            _findCursor.Verify(x => x.Skip(0));
            _findCursor.Verify(x => x.Limit(100));
        }
Exemplo n.º 2
0
        public async Task Should_Return_GetAllCoursesOutput_Instance()
        {
            // Arrange
            IEnumerable <Course> courseList = new List <Course>();

            _courseServiceMock.Setup(p => p.GetAllAsync()).Returns(Task.FromResult(courseList));

            // Act
            var result = await _courseController.Get();

            // Assert
            Assert.IsAssignableFrom <GetAllCoursesOutput>(result);
        }
Exemplo n.º 3
0
        public async void CourseControllerTest()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "yeet").Options;

            using (var context = new AppDbContext(options))
            {
                Repository repo = new Repository(context);
                var        _CourseController = new CourseController(repo);
                Course     tempCourseOne     = new Course();
                tempCourseOne.Title = "first";

                Course tempCourseTwo = new Course();
                tempCourseOne.Title = "second";
                await _CourseController.CreateCourseAsync(tempCourseOne);

                await _CourseController.CreateCourseAsync(tempCourseTwo);

                ActionResult <List <Course> > testList = _CourseController.GetAll().Result;
                testList = testList.Value;
                Assert.NotNull(testList);
                ActionResult <Course> testList2 = _CourseController.Get(1).Result;
                Assert.NotNull(testList2);
                tempCourseOne.Title = "third";
                await repo.EditCourseScoreAsync(tempCourseOne);

                Assert.Equal("third", (repo.GetCourseAsync(1).Result.Title));
            }
        }
        public void GetCourseTest()
        {
            IEnumerable <Course> expectedCourses;

            expectedCourses = CourseTestData.GetExpectedCourses();
            var expectedCoursesTask = Task.FromResult(expectedCourses);

            mockCourseRepository.Setup(m => m.Course.GetAllCoursesAsync()).Returns(expectedCoursesTask);

            OkObjectResult content        = courseController.Get().Result as OkObjectResult;
            HttpStatusCode httpStatusCode = (HttpStatusCode)content.StatusCode;

            var response      = content.Value as ResponseModel <Course>;
            var actualCourses = response.DataCollection;

            Assert.AreEqual(httpStatusCode, HttpStatusCode.OK);
            Assert.AreEqual(expectedCoursesTask.Result.Count(), actualCourses.ToList().Count);
        }
Exemplo n.º 5
0
        public async Task ReturnCourseById()
        {
            var courseCtrl = new CourseController(_mapper.Object, _courseService.Object);
            var actual     = await courseCtrl.Get(1);

            var okResult = Assert.IsType <OkObjectResult>(actual.Result);
            var course   = Assert.IsType <CourseViewModel>(okResult.Value);

            Assert.Equal("English", course.Name);
        }
Exemplo n.º 6
0
        public async Task ReturnAllCourses()
        {
            var courseCtrl = new CourseController(_mapper.Object, _courseService.Object);
            var actual     = await courseCtrl.Get();

            var okResult = Assert.IsType <OkObjectResult>(actual.Result);
            var items    = Assert.IsType <List <CourseViewModel> >(okResult.Value);

            Assert.Equal(3, items.Count);
        }
        public void GetCourse()
        {
            var mockCourseRepository = RepositoryMocks.GetCourseRepository();
            var courseController     = new CourseController(mockCourseRepository.Object);
            //Act
            var result = courseController.Get();
            //Assert
            //Assert.IsType<List<Course>>(result);
            var items = Assert.IsType <List <Course> >(result);

            Assert.Equal(2, items.Count);
        }
        public void GetAllCoursesTest()
        {
            // Arrange
            var courseManagerMock = new Mock <ICourseManager>(MockBehavior.Strict);

            courseManagerMock.Setup(manager => manager.FindCourses()).Returns(GetDummyDataIntegrationCourses());

            CourseController controller = new CourseController(courseManagerMock.Object);

            // Act
            var result = controller.Get();

            // Assert
            courseManagerMock.Verify(manager => manager.FindCourses());
            TestCoursesWithDummyData(GetDummyDataIntegrationCourses(), result);
        }
Exemplo n.º 9
0
        public async Task ReturnCourseById()
        {
            var options = new DbContextOptionsBuilder <UniversityContext>()
                          .UseInMemoryDatabase(databaseName: "Get-by-id_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 courses = await ctrl.Get(context.Courses.First().Id);

                var okResult = Assert.IsType <OkObjectResult>(courses.Result);
                var item     = Assert.IsType <CourseViewModel>(okResult.Value);
                Assert.Equal("English", item.Name);
            }
        }
        public void CourseREST()
        {
            /*var mock = new Mock<IGroupService>();
             * var group = new GroupViewModel()
             * {
             *  Number = 20,
             *  EndDate = DateTime.Now,
             *  StartDate = DateTime.Now,
             *  HalfGroup = false,
             *  CourseId = 1
             * };*/
            /* mock.Setup(a => a.AddGroup(group)).Returns<GroupViewModel>(group => group);
             * mock.Setup(a => a.GetGroup()).Returns<GroupViewModel>(group => group);
             * mock.Setup(a => a.AddGroup(group)).Returns<GroupViewModel>(group => group);*/
            var controller = new CourseController(CourseService);

            var result = controller.Get(1) as JsonResult;

            Assert.IsNotNull(result);

            /*result = controller.Post(group) as JsonResult;
             * Assert.IsNotNull(result);
             */
            /*var groupForUpdate = new GroupViewModel  {
             *  Number = 20,
             *  EndDate = DateTime.Now,
             *  StartDate = DateTime.Now,
             *  HalfGroup = true,
             *  CourseId = 2
             * };
             * result = controller.Put(((GroupViewModel) result.Value).Id, groupForUpdate) as JsonResult;
             * Assert.IsNotNull(result);
             *
             * result = controller.Get(((GroupViewModel) result.Value).Id) as JsonResult;
             * Assert.IsNotNull(result);
             *
             * result = controller.Delete(((GroupViewModel) result.Value).Id) as JsonResult;
             * Assert.IsNotNull(result);*/
        }
Exemplo n.º 11
0
        //Get
        public override Task <CourseReply> GetCourse(CourseIdRequest request, ServerCallContext context)
        {
            Course poco = _Courselogic.Get(request.CourseID);

            return(Task.FromResult <CourseReply>(FromPoco(poco)));
        }