//private Google_Keep_ToDoContext dbContext; //public UnitTest1() //{ // var OptionsBuilder = new DbContextOptionsBuilder<Google_Keep_ToDoContext>(); // OptionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()); // dbContext = new Google_Keep_ToDoContext(OptionsBuilder.Options); // _controller = new ToDoController(dbContext); // AddTestData(dbContext); //} public ToDoController GetController() { var optionsBuilder = new DbContextOptionsBuilder <Google_Keep_Context>(); optionsBuilder.UseInMemoryDatabase <Google_Keep_Context>(Guid.NewGuid().ToString()); var dbContext = new Google_Keep_Context(optionsBuilder.Options); CreateTestData(optionsBuilder.Options); return(new ToDoController(dbContext)); }
public IntegrationTest() { var host = new TestServer(new WebHostBuilder() .UseEnvironment("Testing") .UseStartup <Startup>()); _client = host.CreateClient(); _context = host.Host.Services.GetService(typeof(Google_Keep_Context)) as Google_Keep_Context; _context.AddRange(TestNotes); _context.SaveChanges(); }
public void CreateTestData(DbContextOptions <Google_Keep_Context> options) { using (var dbContext = new Google_Keep_Context(options)) { List <Note> TestNotes = new List <Note> { new Note() { Id = 1, Name = "First note", Text = "This is the first note", PinStatus = true, CheckList = new List <CheckList_Item>() { new CheckList_Item() { CheckListName = "1st task", CheckListStatus = false }, new CheckList_Item() { CheckListName = "2nd task", CheckListStatus = false } }, Labels = new List <Label>() { new Label() { LabelName = "Important" } } }, new Note() { Id = 2, Name = "Second note", Text = "This is the second note", PinStatus = false, CheckList = new List <CheckList_Item>() { new CheckList_Item() { CheckListName = "3rd task", CheckListStatus = true } }, Labels = new List <Label>() { new Label() { LabelName = "Important" } } }, new Note() { Id = 3, Name = "Third note", Text = "This is the third note", PinStatus = false, CheckList = new List <CheckList_Item>() { new CheckList_Item() { CheckListName = "3rd task", CheckListStatus = true } }, Labels = new List <Label>() { new Label() { LabelName = "Very Important" } } }, new Note() { Id = 4, Name = "Fourth note", Text = "This is the fourth note", PinStatus = false, CheckList = new List <CheckList_Item>() { new CheckList_Item() { CheckListName = "3rd task", CheckListStatus = true } }, Labels = new List <Label>() { new Label() { LabelName = "Not So Important" } } } }; dbContext.Note.AddRange(TestNotes); dbContext.SaveChanges(); } }
public ToDoController(Google_Keep_Context context) { _context = context; }