示例#1
0
        public async Task GetAllUserCoursesTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var courseRepository     = new EfDeletableEntityRepository <Course>(new ApplicationDbContext(options.Options));
            var userCourseRepository = new EfRepository <UserCourse>(new ApplicationDbContext(options.Options));

            var coursesToAdd     = this.GetCourseData();
            var userCoursesToAdd = this.GetUserCourseData();

            foreach (var course in coursesToAdd)
            {
                await courseRepository.AddAsync(course);

                await courseRepository.SaveChangesAsync();
            }

            foreach (var userCourse in userCoursesToAdd)
            {
                await userCourseRepository.AddAsync(userCourse);

                await userCourseRepository.SaveChangesAsync();
            }

            var mockConfiguration   = new Mock <IConfiguration>();
            var mockCategoryService = new Mock <ICategoriesService>();
            var store           = new Mock <IUserStore <ApplicationUser> >();
            var mockUserManager = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);

            var service = new CoursesService(courseRepository, userCourseRepository, mockConfiguration.Object, mockCategoryService.Object, mockUserManager.Object);

            AutoMapperConfig.RegisterMappings(typeof(DiscoverCourseViewModel).Assembly);

            var courses = service.GetAllUserCourses <DiscoverCourseViewModel>("User1");

            Assert.Equal(3, courses.Count());
        }