Last active
January 9, 2020 04:14
-
-
Save taylorc/040f92de699bf3955cb82bce52dc5089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Collection("QueryTests")] | |
public class GetTodosQueryTests { | |
private readonly ApplicationDbContext _context; | |
private readonly IMapper _mapper; | |
public GetTodosQueryTests(QueryTestFixture fixture) { | |
_mapper = fixture.Mapper; | |
} | |
[Fact] | |
public async Task Handle_ReturnsCorrectVmAndListCount() { | |
//arrange | |
var query = new GetTodosQuery(); | |
var mockedDbContext = new Mock < IApplicationDbContext > (); | |
var todoListEntities = new List < TodoList > { | |
new TodoList { | |
Colour = "Blue", Items = new List < TodoItem > { | |
new TodoItem { | |
Title = "Dynamics" | |
}, | |
new TodoItem { | |
Title = "Case" | |
}, | |
new TodoItem { | |
Title = "Management" | |
}, | |
new TodoItem { | |
Title = "Accelerator" | |
}, | |
new TodoItem { | |
Title = "HSD" | |
} | |
} | |
} | |
}; | |
var mockDbSet = todoListEntities.AsQueryable().BuildMockDbSet(); | |
mockedDbContext.Setup(db => db.TodoLists).Returns(mockDbSet.Object); | |
//act | |
var handler = new GetTodosQuery.GetTodosQueryHandler(mockedDbContext.Object, _mapper); | |
var result = await handler.Handle(query, CancellationToken.None); | |
//assert | |
result.ShouldBeOfType < TodosVm > (); | |
result.Lists.Count.ShouldBe(1); | |
var list = result.Lists.First(); | |
list.Items.Count.ShouldBe(5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment