public static void Initialize(TodosContext context) { context.Database.EnsureCreated(); if (context.Todo.Any()) { return; } var tasks = new Todo[] { new Todo { Name = "First task", Description = "whaaat m8, no wei hello", CreateDate = DateTime.Parse("2010-09-01") }, new Todo { Name = "Second task", Description = "whaaat m8, no wei hello", CreateDate = DateTime.Parse("2010-09-02") } }; foreach (var item in tasks) { context.Todo.Add(item); } context.SaveChanges(); }
public void canAddTodos() { using (var context = new TodosContext(_options)) { var todos = new TodosRepo(context).GetAll().ToList(); Assert.AreEqual(1, todos.Count()); Assert.AreEqual("Test todo", todos[0].Description); } }
public void canGetListfromController() { using (var context = new TodosContext(_options)) { var c = new TodosController(new TodosRepo(context)); var list = c.Get(); Assert.AreEqual(1, list.Count()); } }
public void AlreadyDeletedReturnsNotFoundObjectResult() { using (var context = new TodosContext(_options)) { var c = new TodosController(new TodosRepo(context)); var item = c.Delete(2); Assert.True(item is NotFoundObjectResult); } }
public TodosService(TodosContext context) { todosContext = context; mapper = new Mapper(new MapperConfiguration(cfg => { cfg.CreateMap <TodoFolder, TodoFolderDTO>(); cfg.CreateMap <TodoItem, TodoItemDTO>(); }) ); }
public void CanDeleteTodo() { using (var context = new TodosContext(_options)) { var c = new TodosController(new TodosRepo(context)); var viewitem = c.Delete(2); var item = c.Get(2); Assert.True(item is NotFoundResult); } }
public void canAddTodo() { using (var context = new TodosContext(_options)) { var c = new TodosController(new TodosRepo(context)); var list = c.Get(); var newid = list.Last().ID + 1; var newitem = new Todos { ID = newid, Description = $"New item {newid}", IsComplete = false }; c.Put(newid, newitem); int newcount = c.Get().Count(); Assert.AreEqual(newid, newcount); } }
public void canUpdateTodo() { using (var context = new TodosContext(_options)) { var c = new TodosController(new TodosRepo(context)); var viewitem = (OkObjectResult) c.Get(1); var item = (Todos)viewitem.Value; item.Description = "updated item"; c.Post(item); var updatedview = (OkObjectResult)c.Get(1); var updatedDesc = ((Todos)updatedview.Value).Description; Assert.AreEqual(item.Description, updatedDesc); } }
public void getAll_Returns_all_Todos() { //instantiate the context var todosContext = new TodosContext(_logger, _configuration); //Call the context action var result = todosContext.getAll(); //Assert the result Assert.NotNull(result); var todos = Assert.IsType <List <ToDoItemModel> >(result); //Assert the result todos.Should().BeEquivalentTo(todos, options => options.ComparingByMembers <ToDoItemModel>()); }
public void create_Creates_one_Todo_And_Returns_1() { var todo = todosList.First(); //instantiate the context var todosContext = new TodosContext(_logger, _configuration); //Call the context action var result = todosContext.create(todo); //Assert the result var returnedValue = Assert.IsType <int>(result); //Assert the result Assert.Equal(1, returnedValue); }
public void Setup() { _options = new DbContextOptionsBuilder<TodosContext>() .UseInMemoryDatabase(databaseName: "todos") .Options; // Run the test against one instance of the context using (var context = new TodosContext(_options)) { var service = new TodosRepo(context); foreach (var item in service.GetAll()) { service.Delete(item); } service.Add(new Todos { ID = 1, Description = "Test todo", IsComplete = false }); } }
public void getTodoBy_Returns_one_Todo() { var todo = todosList.First(); //instantiate the context var todosContext = new TodosContext(_logger, _configuration); //Call the context action var result = todosContext.getBy(t => t.id == todo.id); //Assert the result Assert.NotNull(result); var returnedTodo = Assert.IsType <ToDoItemModel>(result); //Assert the result returnedTodo.Should().BeEquivalentTo(todo, options => options.ComparingByMembers <ToDoItemModel>()); }
public TodoListsController(TodosContext context) { _context = context; }
public TodoController(TodosContext context) { this.context = context; }
public TodosRepository(TodosContext context) { _context = context; }
public TodosRepo(TodosContext context) { _context = context; }
public TodosController() { _context = new TodosContext(); }
public TodoService(TodosContext todoContext, IMapper mapper) { _todoContext = todoContext; _mapper = mapper; }
public TodoListsController(TodosContext todosContext) { _todosContext = todosContext; }