private void SeedTestsWithRepeatedIdsToDb(MyFirstFullStackApp_DEVContext context) { var tests = new[] { new Test { Id = 1, Title = "Test testModel1" }, new Test { Id = 1, Title = "Test testModel1" } }; if (context.Test.Count() != 0) { foreach (Test test in context.Test) { context.Test.Remove(test); } } context.Test.AddRange(tests); context.SaveChanges(); }
private void SeedProperCandidatesToDb(MyFirstFullStackApp_DEVContext context) { context.Candidate.RemoveRange(context.Candidate); context.Test.RemoveRange(context.Test); context.Result.RemoveRange(context.Result); context.Answer.RemoveRange(context.Answer); context.SaveChanges(); var candidates = PopulateCandidates(); context.Candidate.AddRange(candidates); context.SaveChanges(); }
private ISampleRepository CreateProperTestsInMemory() { var dbOptions = new DbContextOptionsBuilder <MyFirstFullStackApp_DEVContext>() .UseInMemoryDatabase(databaseName: "MyFFSADb") .Options; var context = new MyFirstFullStackApp_DEVContext(dbOptions); SeedProperTestsToDb(context); var autoMapperConfiguration = new MapperConfiguration(c => { c.AddProfile(new ApplicationProfile()); }); return(new SampleRepository(context, autoMapperConfiguration.CreateMapper())); }