예제 #1
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));
            }
        }
예제 #2
0
        //GetAll
        public override Task <Courses> GetCourses(Empty request, ServerCallContext context)
        {
            Courses collectionofcourses          = new Courses();
            List <SchoolAPI.Models.Course> pocos = _Courselogic.GetAll();

            foreach (Course poco in pocos)
            {
                collectionofcourses.Cour.Add(FromPoco(poco));
            }
            return(Task.FromResult <Courses>(collectionofcourses));
        }