public async Task <IEnumerable <GameSelectItemLookupModel> > Handle(GetAllGamesSelectListQuery request, CancellationToken cancellationToken) { request = request ?? throw new ArgumentNullException(nameof(request)); var lookups = await this.gameRepository .AllAsNoTracking() .ProjectTo <GameSelectItemLookupModel>(this.mapper.ConfigurationProvider) .ToListAsync(cancellationToken); return(lookups); }
public async Task Handle_GivenValidRequest_ShouldReturnValidViewModel() { // Arrange var query = new GetAllGamesSelectListQuery(); var gameRepositoryMock = new Mock <IDeletableEntityRepository <Game> >(); var dataSet = new List <Game>() { new Game() { Id = 1, Name = It.IsAny <string>(), Description = It.IsAny <string>(), CreatedOn = It.IsAny <DateTime>(), TournamentFormats = It.IsAny <ICollection <TournamentFormat> >(), GameImageUrl = It.IsAny <string>() }, new Game() { Id = 2, Name = It.IsAny <string>(), Description = It.IsAny <string>(), CreatedOn = It.IsAny <DateTime>(), TournamentFormats = It.IsAny <ICollection <TournamentFormat> >(), GameImageUrl = It.IsAny <string>() }, new Game() { Id = 3, Name = "CS:GO", Description = It.IsAny <string>(), CreatedOn = It.IsAny <DateTime>(), TournamentFormats = It.IsAny <ICollection <TournamentFormat> >(), GameImageUrl = It.IsAny <string>() }, }.AsQueryable(); var dataSetMock = dataSet.BuildMock(); gameRepositoryMock.Setup(m => m.AllAsNoTracking()).Returns(dataSetMock.Object); var sut = new GetAllGamesSelectListQueryHandler(gameRepositoryMock.Object, this.mapper); // Act var result = await sut.Handle(query, CancellationToken.None); // Assert result.ShouldNotBeNull(); result.ShouldNotBeEmpty(); result.ShouldBeAssignableTo <IEnumerable <GameSelectItemLookupModel> >(); result.Count().ShouldBe(3); result.SingleOrDefault(g => g.Id == 3).Name.ShouldBe("CS:GO"); }