Ejemplo n.º 1
0
        public Task DeleteListAsync()
        {
            // Delete list with exception handling
            return(RunWithErrorHandling(async() =>
            {
                // Validate
                if (currentList == null)
                {
                    throw new ArgumentNullException("currentList");
                }

                // Get index of current list
                var index = lists.IndexOf(currentList);

                // Find out previous but bound to 0
                index = Math.Max(index - 1, 0);

                // Attempt to delete current list
                await todoService.DeleteAsync(currentList);

                // Delete successful so remove from lists collection
                lists.Remove(currentList);

                // Set current list to the next closest one
                if (lists.Count > index)
                {
                    CurrentList = lists[index];
                }
            }
                                        , TaskRunOptions.WithFailure(string.Format("Could not delete {0} list", currentList.Title))));
        }
Ejemplo n.º 2
0
        public async Task DeleteTodo_Should_DeleteTodo()
        {
            //Setup DbContext and DbSet mock
            var dbContextMock = new Mock <ITodoContext>();

            var testTodoId = 1;

            var testTodos = GetTestTodos();

            var todoDbSetMock = testTodos.AsQueryable().GetMockDbSet();

            dbContextMock.Setup(x => x.DbSet <Todo>()).Returns(todoDbSetMock.Object);
            todoDbSetMock.Setup(x => x.Remove(testTodos.FirstOrDefault()))
            .Callback(() => testTodos.Clear());

            //Execute
            var todoService      = new TodoService(dbContextMock.Object);
            var todoBeforeDelete = await todoService.GetAsync <Todo>(x => x.TodoId == testTodoId);

            await todoService.DeleteAsync(todoBeforeDelete);

            var todoAfterDelete = await todoService.GetAsync <Todo>(x => x.TodoId == testTodoId);

            //Assert
            Assert.NotNull(todoBeforeDelete);
            Assert.Null(todoAfterDelete);
            Assert.IsAssignableFrom <IEnumerable <Todo> >(testTodos);
            Assert.NotNull(testTodos);
        }
Ejemplo n.º 3
0
                protected override void Context()
                {
                    // Arrange
                    _repositoryMock = new Mock <ITodoRepository>();
                    _sut            = new TodoService(_repositoryMock.Object);

                    // Act
                    var _ = _sut.DeleteAsync(1L).Result;
                }
Ejemplo n.º 4
0
        public async Task <ActionResult> Delete(Guid id)
        {
            await TodoService.DeleteAsync(new DeleteTodoServiceRequest
            {
                Username = Username,
                Id       = id
            });

            return(Json(new
            {
                success = true
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> Delete(int id)
        {
            await TodoService.DeleteAsync(id);

            return(RedirectToAction("index"));
        }
Ejemplo n.º 6
0
 public async Task<ActionResult> Delete(DeleteTodo command)
 {
     await _todoService.DeleteAsync(command);
     return Ok();
 }
Ejemplo n.º 7
0
        public async Task <IActionResult> DeleteAsync(Guid id)
        {
            var todoDeleted = await TodoService.DeleteAsync(id);

            return(HandleResult(todoDeleted));
        }