public async Task RemoveToDoItem_Expected() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); const int idToRemove = 1; // act var result = await toDoListService.RemoveToDoItem(idToRemove); // assert Assert.IsNotNull(result); Assert.AreEqual(idToRemove, result.Id); var searchResult = context.Set <ToDoItem>().FirstOrDefault(x => x.Id == idToRemove); Assert.IsNull(searchResult); } }
public async Task AddToDoItem_Expected() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); var newToDo = new ToDoItemVm { TaskName = "Task 3" }; // act var result = await toDoListService.AddToDoItem(newToDo); // assert Assert.IsNotNull(result); Assert.AreEqual("Task 3", result.TaskName); var toDoCount = context.Set <ToDoItem>().Count(); Assert.AreEqual(3, toDoCount); } }
public void Update(T entity) { using var context = new ToDoListContext(); context.Set <T>().Update(entity); context.SaveChanges(); }
public T GetById(int Id) { using var context = new ToDoListContext(); return(context.Set <T>().Find(Id)); }
public List <T> GetAll() { using var context = new ToDoListContext(); return(context.Set <T>().ToList()); }
public void Delete(T entity) { using var context = new ToDoListContext(); context.Set <T>().Remove(entity); context.SaveChanges(); }
public IList <T> GetAll() { return(_context.Set <T>().ToList()); }
public ToDoListRepository(ToDoListContext context) { _context = context; _dbSet = _context.Set <ToDoList>(); }
public EFGenericRepository(ToDoListContext context) { Guard.WhenArgument(context, "Context").IsNull().Throw(); this.Context = context; this.DbSet = context.Set <T>(); }
public void AddNewTask(TaskDetail task) { task.CreatedBy = task.ModifiedBy = "CurrentUser"; task.CreatedOn = task.ModifiedOn = DateTime.Now; ToDoListContext.Set <TaskDetail>().Add(task); }