コード例 #1
0
 public static void Execute(CoursesDbContext context)
 {
     context.Courses.AddRange(Courses);
     context.Chapters.AddRange(Chapters);
     context.Lessons.AddRange(Lessons);
     context.Users.AddRange(Users);
     context.Achievements.AddRange(Achievements);
     context.SaveChanges();
 }
コード例 #2
0
 public AchievementValidator(CoursesDbContext context)
 {
     _context    = context;
     _validators = new Dictionary <int, Func <List <LessonCompletion>, AchievementValidationResult> >
     {
         [1] = (lessons) => ValidateLessonCount(lessons, 5),
         [2] = (lessons) => ValidateLessonCount(lessons, 25),
         [3] = (lessons) => ValidateLessonCount(lessons, 50),
         [4] = (lessons) => ValidateChapterCount(lessons, 1),
         [5] = (lessons) => ValidateChapterCount(lessons, 5),
         [6] = (lessons) => ValidateCourseCompleted(lessons, "Swift"),
         [7] = (lessons) => ValidateCourseCompleted(lessons, "JavaScript"),
         [8] = (lessons) => ValidateCourseCompleted(lessons, "C#"),
     };
 }
コード例 #3
0
        public static void Create(CoursesDbContext context)
        {
            try
            {
                context.Courses.AddRange(Courses);
                context.Chapters.AddRange(Chapters);
                context.Lessons.AddRange(Lessons);
                context.Users.AddRange(Users);
                context.Achievements.AddRange(Achievements);

                context.SaveChanges();
            } catch (InvalidOperationException)
            {
                //ignore, xunit multi threading inmemory db makes it tricky to initialize sample data.
            }
            catch (ArgumentException)
            {
                //ignore, xunit multi threading inmemory db makes it tricky to initialize sample data.
            }
        }
コード例 #4
0
        public static void Inject()
        {
            CoursesDbContext context = new CoursesDbContext();
            var builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            // builder.RegisterType<DevManager>().As<IDevManager>();
            builder.Register(c => new Repository <Author, int>(context)).As <IGenericRepository <Author, int> >();
            builder.Register(c => new Repository <Book, Guid>(context)).As <IGenericRepository <Book, Guid> >();
            builder.Register(c => new Manager <Author, int>(new Repository <Author, int>(context))).As <IManager <Author, int> >();
            builder.Register(c => new Manager <Book, Guid>(new Repository <Book, Guid>(context))).As <IManager <Book, Guid> >();
            //builder.RegisterType<TeamManager>().As<ITeamManager>();
            //builder.Register(c => new TeamRepository(context)).As<ITeamRepository>();
            // builder.RegisterInstance<IDevRepository>(new DevRepository(context));

            //builder.RegisterType<GroupManager>().As<IGroupManager>();
            //builder.RegisterInstance<IGroupRepository>(new GroupRepository(ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString));
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
コード例 #5
0
        public void ReturnCourses()
        {
            var options = new DbContextOptionsBuilder <CoursesDbContext>()
                          .UseInMemoryDatabase(databaseName: "CoursesMEM")
                          .Options;

            using (var context = new CoursesDbContext(options))
            {
                context.Courses.Add(new Course {
                    Title = "Test Course"
                });
                context.Courses.Add(new Course {
                    Title = "Another Silly Course"
                });
                context.SaveChanges();
            }
            using (var context = new CoursesDbContext(options))
            {
                var sut    = new CoursesController(context);
                var result = sut.GetCourses();
                Assert.Equal(2, result.Count());
            }
        }
コード例 #6
0
 public CourseRepo(CoursesDbContext db)
 {
     _db = db;
 }
コード例 #7
0
 public AchievementService(CoursesDbContext context, AchievementValidator achievementValidator)
 {
     _achievementValidator = achievementValidator;
     _context = context;
 }
コード例 #8
0
 public CourseRepository(CoursesDbContext context) : base(context)
 {
     _context = context;
 }
コード例 #9
0
 public CoursesController(CoursesDbContext context)
 {
     _context = context;
 }
コード例 #10
0
 public UsersController(CoursesDbContext context, AchievementService achievementService)
 {
     _achievementService = achievementService;
     _context            = context;
 }
コード例 #11
0
 public SqlServerCoursesProvider(CoursesDbContext db)
 {
     this.db = db;
 }
コード例 #12
0
 public ReviewsController(CoursesDbContext context)
 {
     _context = context;
 }
コード例 #13
0
 public Repository(CoursesDbContext Context)
 {
     context = Context;
     _dbSet  = context.Set <TEntity>();
 }
コード例 #14
0
 public CoursesRepository(CoursesDbContext context, ILoggerFactory loggerFactory)
 {
     _context = context;
     _Logger  = loggerFactory.CreateLogger("CoursesRepository");
 }
コード例 #15
0
 public StudentDataService(CoursesDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #16
0
 public CourseDataService(CoursesDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #17
0
 public TeacherDataService(CoursesDbContext dbContext)
 {
     _dbContext = dbContext;
 }