public async Task OverrideIOCContextResultsInChanges()
        {
            // Setup the TODO Db Context
            altTodoContext.RemoveRange(altTodoContext.TodoItems);
            altTodoContext.Add <TodoItem>(new TodoItem()
            {
                Id = 1, IsComplete = true, Name = "Make an override"
            });
            altTodoContext.Add <TodoItem>(new TodoItem()
            {
                Id = 2, IsComplete = false, Name = "Test the override"
            });
            altTodoContext.Add <TodoItem>(new TodoItem()
            {
                Id = 3, IsComplete = false, Name = "Document override"
            });
            altTodoContext.Add <TodoItem>(new TodoItem()
            {
                Id = 4, IsComplete = true, Name = "Make test project"
            });
            altTodoContext.Add <TodoItem>(new TodoItem()
            {
                Id = 5, IsComplete = true, Name = "Run test project"
            });
            altTodoContext.SaveChanges();
            var ctrllr    = this.GetTodoController(useAlt: true);
            int itemCount = (await ctrllr.GetTodoItems()).Value.ToList().Count;

            Assert.AreEqual(altTodoContext.TodoItems.Count(), itemCount);
        }
Exemplo n.º 2
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.RemoveRange(_context.TodoItems.Where(i => i.IsCompleted));
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
        public async Task <IEnumerable <Data.Todo> > Post(
            [FromServices] TodoQueueClient todoQueueClient,
            [FromServices] TodoContext todoContext,
            [FromServices] ILogger <TodosController> logger,
            [FromBody] List <Data.Todo> todos)
        {
            var doneTodos    = todos.Where(x => x.Done);
            var doneTodosIds = doneTodos.Select(x => x.Id);

            var newlyDoneTodos = await todoContext.Todos
                                 .Where(t => !t.Done)
                                 .Where(t => doneTodosIds.Contains(t.Id))
                                 .ToListAsync();

            newlyDoneTodos = newlyDoneTodos.Union(doneTodos.Where(x => x.Id == null)).ToList();

            foreach (var todo in newlyDoneTodos)
            {
                await todoQueueClient.SendMessageAsync(new Core.TodoActionMessageQueue
                {
                    TodoName      = todo.Name,
                    CorrelationId = System.Diagnostics.Activity.Current.RootId
                });
            }

            todoContext.RemoveRange(todoContext.Todos);
            await todoContext.Todos.AddRangeAsync(todos);

            await todoContext.SaveChangesAsync();

            logger.LogInformation($"{todos.Count} Todos saved");
            return(todos);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var todoItem = await GetTodoItem(id);

            _context.RemoveRange(todoItem.TagAssignments);
            _context.TodoItem.Remove(todoItem);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 5
0
 public void Reset()
 {
     _context.RemoveRange(_context.Todos);
     _context.SaveChanges();
 }
Exemplo n.º 6
0
 public void RemoveRange <TEntity>(List <TEntity> entity)
     where TEntity : BaseEntity
 {
     _context.RemoveRange(entity);
 }
Exemplo n.º 7
0
 public void DeleteAllTodoItems()
 {
     _context.RemoveRange(_context.TodoItems); //.Database.ExecuteSqlRaw("delete from TodoItems where IsComplete = 'true'");
     _context.SaveChanges();
 }
 public void TearDown()
 {
     context.RemoveRange(context.TodoItems);
     context.SaveChanges();
 }