Exemple #1
0
            public DbSetup(WebApplicationFactory <Startup> factory)
            {
                // This fetches the same single lifetime instantiation used by Controller classes
                _dbContext = factory.Services.GetRequiredService <RosterDbContext>();

                // Seed in-memory database with some data needed for tests
                var school = new School
                {
                    Id    = 1,
                    Name  = "School of Hard Knocks",
                    City  = "Life",
                    State = "Madness"
                };

                _dbContext.School.Add(school);
                var teacher = new Teacher
                {
                    Id     = 1,
                    Name   = "Mrs. Stricter",
                    School = school
                };

                _dbContext.Teacher.Add(teacher);
                var @class = new Class
                {
                    Id      = 1,
                    Name    = "Fifth Grade Class",
                    Teacher = teacher
                };

                _dbContext.Class.Add(@class);
                var student1 = new Student
                {
                    Id    = 1,
                    Name  = "Jim Bob",
                    Class = @class
                };

                _dbContext.Student.Add(student1);
                var student2 = new Student
                {
                    Id    = 2,
                    Name  = "Jane Doe",
                    Class = @class
                };

                _dbContext.Student.Add(student2);
                _dbContext.SaveChanges();
            }
 public StudentsController(RosterDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #3
0
 public StudentController(RosterDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Exemple #4
0
 public CreateSchoolCommandHandler(RosterDbContext context)
 {
     this._context = context;
 }