Ejemplo n.º 1
0
        public async Task DeleteAllAsync_Should_DeleteAllTodos()
        {
            //Setup DbContext and DbSet mock
            var dbContextMock = new Mock <ITodoContext>();

            var testTodos = GetTestTodos();

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

            dbContextMock.Setup(x => x.DbSet <Todo>()).Returns(todoDbSetMock.Object);

            //Execute
            var todoService = new TodoService(dbContextMock.Object);
            var todosBefore = await todoService.GetAllAsync <Todo>();

            await todoService.DeleteAllAsync <Todo>();

            var todosAfter = await todoService.GetAllAsync <Todo>();

            //Assert
            Assert.IsAssignableFrom <IEnumerable <Todo> >(todosBefore);
            Assert.NotNull(todosBefore);
            Assert.Empty(todosAfter);
        }