public void PrepareInMemoryData(DbContextOptions <TodoNotesContext> options) { using (var todoNotesContext = new TodoNotesContext(options)) { var notes = new List <Notes> { new Notes() { Id = 1, Title = "Note one", PlainText = "This is plaintext", PinStatus = true, checkList = new List <CheckList>() { new CheckList() { CheckListName = "Note one CheckList", CheckListStatus = true } }, label = new List <Label>() { new Label() { LabelName = "note one label" } } }, new Notes() { Id = 2, Title = "Note two", PlainText = "This is plaintext", PinStatus = true, checkList = new List <CheckList>() { new CheckList() { CheckListName = "Note one CheckList", CheckListStatus = true } }, label = new List <Label>() { new Label() { LabelName = "note one label" } } } }; todoNotesContext.Notes.AddRange(notes); todoNotesContext.SaveChanges(); } }
//private NotesController _controller; //public UnitTest() //{ // var optionsBuilder = new DbContextOptionsBuilder<TodoNotesContext>(); // optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()); // TodoNotesContext context = new TodoNotesContext(optionsBuilder.Options); // _controller = new NotesController(context); // PrepareInMemoryData(context); //} public NotesController GetController() { var optionsBuilder = new DbContextOptionsBuilder <TodoNotesContext>(); optionsBuilder.UseInMemoryDatabase <TodoNotesContext>(Guid.NewGuid().ToString()); TodoNotesContext todoNotesContext = new TodoNotesContext(optionsBuilder.Options); PrepareInMemoryData(optionsBuilder.Options); return(new NotesController(todoNotesContext)); }
public NotesController(TodoNotesContext context) { _context = context; }