Пример #1
0
        public IEnumerable <GameViewModel> Handle(GetAllGamesQuery qry)
        {
            var results = GameInMemoryRepository.GetAll().ToList();

            var list = results.Select(x => new GameViewModel {
                ID          = x.ID,
                Name        = x.Name,
                Description = x.Description,
                Publisher   = x.Publisher,
                PublishDate = x.PublishDate
            }).ToList();

            return(list);
        }
Пример #2
0
        public async Task Handle_GivenValidRequest_ShouldReturnValidViewModel()
        {
            // Arrange
            var query = new GetAllGamesQuery();
            var gameRepositoryMock = new Mock <IDeletableEntityRepository <Game> >();
            var dataSet            = new List <Game>()
            {
                new Game()
                {
                    Id                = 1,
                    Name              = It.IsAny <string>(),
                    Description       = "SampleDesc",
                    CreatedOn         = It.IsAny <DateTime>(),
                    GameImageUrl      = It.IsAny <string>(),
                    TournamentFormats = new HashSet <TournamentFormat>()
                    {
                        new TournamentFormat()
                        {
                            Name  = It.IsAny <string>(),
                            Teams = new HashSet <Team>()
                            {
                                new Team()
                                {
                                    Name = "SampleTeam"
                                }
                            }
                        }
                    }
                },
            }.AsQueryable();

            var dataSetMock = dataSet.BuildMock();

            gameRepositoryMock.Setup(m => m.AllAsNoTracking()).Returns(dataSetMock.Object);

            var sut = new GetAllGamesQueryHandler(gameRepositoryMock.Object, this.mapper);

            // Act
            var result = await sut.Handle(query, CancellationToken.None);

            // Assert
            result.Games.Count.ShouldBe(1);
            result.Games.Any(x => x.RegisteredTeams == 1).ShouldBeTrue();
        }
Пример #3
0
        public async void ShouldGetGamesList()
        {
            //arrange
            BoardContext context = new ContextBuilder().BuildClean();

            context.Add(new GameBuilder(context).Build());
            context.Add(new GameBuilder(context).Build());
            context.SaveChanges();

            //act
            var query   = new GetAllGamesQuery();
            var handler = new GetAllGamesQuery.Handler(context);
            var result  = await handler.Handle(query, default);

            //assert
            int expectedAmount = 2;

            Assert.Equal(2, result.Count);
        }
Пример #4
0
        public void Get_All_Games()
        {
            // Arrange
            var getAllGamesQuery = new GetAllGamesQuery();

            // Act
            var result = _queryHandler.Retrieve(getAllGamesQuery);

            // Assert
            Assert.AreEqual(2, result.Count());
        }