Esempio n. 1
0
        public static LogDbContextTests GetContextWithData()
        {
            var options = new DbContextOptionsBuilder<LogDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            var dbContext = new LogDbContextTests(options);

            var data = new InitialData();

            dbContext.LogEvents.AddRange(KeySetter.SetKeys(data.LogEvents));
            dbContext.LogDetail.AddRange(KeySetter.SetKeys(data.LogDetail));
            dbContext.SystemInfo.AddRange(KeySetter.SetKeys(data.SystemInfo));

            dbContext.SaveChanges();

            return dbContext;
        }
        public static AppDbContextTests GetContextWithData()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new AppDbContextTests(options);

            var data = new InitialData();

            dbContext.Schools.AddRange(KeySetter.SetKeys(data.Schools));
            dbContext.Lessons.AddRange(data.Lessons);
            dbContext.Books.AddRange(KeySetter.SetKeys(data.Books));
            dbContext.Students.AddRange(KeySetter.SetKeys(data.Students));
            dbContext.StudentLessons.AddRange(KeySetter.SetKeys(data.StudentLessons));
            dbContext.ContactInfo.AddRange(KeySetter.SetKeys(data.ContactInfo));
            dbContext.Phones.AddRange(KeySetter.SetKeys(data.Phones));

            dbContext.SaveChanges();

            return(dbContext);
        }