コード例 #1
0
        public void Setup()
        {
            //Create an InMemory Sqlite Database for testing
            var connection = new InMemorySqliteConnection();

            //Seed method is called automatically
            _context = connection._context;
        }
コード例 #2
0
        public void Setup()
        {
            //Create an InMemory Sqlite Database for testing
            var connection = new InMemorySqliteConnection();

            _context = connection._context;

            //Create the repository class that will be tested
            _repositorySchool       = new SchoolPerformanceRepository <School>(_context);
            _repositorySchoolResult = new SchoolPerformanceRepository <SchoolResult>(_context);

            //Mock data
            SetData();

            //Remove existing seeded data
            ClearSeedData();

            //Add and save the mock data to the context
            _schools.ForEach(x => _context.School.Add(x));
            _schoolResults.ForEach(x => _context.SchoolResult.Add(x));
            _context.SaveChanges();
        }
コード例 #3
0
        public InMemorySqliteConnection()
        {
            //Creates and open a connection to the sqlite Db
            _connection = new SqliteConnection(_connectionString);
            _connection.Open();

            //Create instance of SchoolPerformanceContext with options included
            var options = new DbContextOptionsBuilder <SchoolPerformanceContext>()
                          .UseSqlite(_connection)
                          .Options;

            _context = new SchoolPerformanceContext(options);


            //// Drop the database if it exists
            if (_context != null)
            {
                _context.Database.EnsureDeleted();
            }

            //Create the database
            _context.Database.EnsureCreated();
        }
コード例 #4
0
 public SchoolPerformanceRepository(SchoolPerformanceContext context)
 {
     _context = context;
     _dbSet   = _context.Set <T>();
 }