示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
 public void Update(T entity)
 {
     using var context = new ToDoListContext();
     context.Set <T>().Update(entity);
     context.SaveChanges();
 }
示例#4
0
 public T GetById(int Id)
 {
     using var context = new ToDoListContext();
     return(context.Set <T>().Find(Id));
 }
示例#5
0
 public List <T> GetAll()
 {
     using var context = new ToDoListContext();
     return(context.Set <T>().ToList());
 }
示例#6
0
 public void Delete(T entity)
 {
     using var context = new ToDoListContext();
     context.Set <T>().Remove(entity);
     context.SaveChanges();
 }
示例#7
0
 public IList <T> GetAll()
 {
     return(_context.Set <T>().ToList());
 }
示例#8
0
 public ToDoListRepository(ToDoListContext context)
 {
     _context = context;
     _dbSet   = _context.Set <ToDoList>();
 }
示例#9
0
 public EFGenericRepository(ToDoListContext context)
 {
     Guard.WhenArgument(context, "Context").IsNull().Throw();
     this.Context = context;
     this.DbSet   = context.Set <T>();
 }
示例#10
0
 public void AddNewTask(TaskDetail task)
 {
     task.CreatedBy = task.ModifiedBy = "CurrentUser";
     task.CreatedOn = task.ModifiedOn = DateTime.Now;
     ToDoListContext.Set <TaskDetail>().Add(task);
 }