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(); }
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#"), }; }
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. } }
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)); }
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()); } }
public CourseRepo(CoursesDbContext db) { _db = db; }
public AchievementService(CoursesDbContext context, AchievementValidator achievementValidator) { _achievementValidator = achievementValidator; _context = context; }
public CourseRepository(CoursesDbContext context) : base(context) { _context = context; }
public CoursesController(CoursesDbContext context) { _context = context; }
public UsersController(CoursesDbContext context, AchievementService achievementService) { _achievementService = achievementService; _context = context; }
public SqlServerCoursesProvider(CoursesDbContext db) { this.db = db; }
public ReviewsController(CoursesDbContext context) { _context = context; }
public Repository(CoursesDbContext Context) { context = Context; _dbSet = context.Set <TEntity>(); }
public CoursesRepository(CoursesDbContext context, ILoggerFactory loggerFactory) { _context = context; _Logger = loggerFactory.CreateLogger("CoursesRepository"); }
public StudentDataService(CoursesDbContext dbContext) { _dbContext = dbContext; }
public CourseDataService(CoursesDbContext dbContext) { _dbContext = dbContext; }
public TeacherDataService(CoursesDbContext dbContext) { _dbContext = dbContext; }