public async Task DeleteAllAsync_Should_DeleteAllPoints() { //Setup DbContext and DbSet mock var dbContextMock = new Mock <ITodoContext>(); var testPoints = GetTestTodoPoints(); var todoPointDbSetMock = testPoints.AsQueryable().GetMockDbSet(); dbContextMock.Setup(x => x.DbSet <TodoPoint>()).Returns(todoPointDbSetMock.Object); //Execute var todoPointService = new TodoPointService(dbContextMock.Object); var todoPointsBefore = await todoPointService.GetAllAsync <TodoPoint>(); await todoPointService.DeleteAllAsync <TodoPoint>(); var todoPointsAfter = await todoPointService.GetAllAsync <TodoPoint>(); //Assert Assert.IsAssignableFrom <IEnumerable <TodoPoint> >(todoPointsBefore); Assert.NotNull(todoPointsBefore); Assert.Empty(todoPointsAfter); }
public async Task GetAllAsync_Should_ReturnAllPoints() { //Setup DbContext and DbSet mock var dbContextMock = new Mock <ITodoContext>(); var testPoints = GetTestTodoPoints(); var todoPointDbSetMock = testPoints.AsQueryable().GetMockDbSet(); dbContextMock.Setup(x => x.DbSet <TodoPoint>()).Returns(todoPointDbSetMock.Object); //Execute var todoPointService = new TodoPointService(dbContextMock.Object); var todoPoints = await todoPointService.GetAllAsync <TodoPoint>(); //Assert Assert.IsAssignableFrom <IEnumerable <TodoPoint> >(todoPoints); Assert.Equal(2, todoPoints.Count); }