コード例 #1
0
        public async Task <ICollection <LeagueDto> > GetAllAsync()
        {
            //test out mapper


            var leagues = await _repo.GetAllAsync();

            // LeagueDao (database) -> League (entity) -> LeagueDto (contract)
            return(leagues.Select(x => _mapper.Map <LeagueDto>(x)).ToList());
        }
コード例 #2
0
        public async Task <IActionResult> Index()
        {
            var model = await _leagueRepository.GetAllAsync();

            if (model == null)
            {
                return(NotFound());
            }
            return(View(model));
        }
コード例 #3
0
        public async Task <IEnumerable <LeagueDTO> > GetAllAsync()
        {
            var leagues = await _leagueRepository.GetAllAsync();

            return(_mapper.Map <IEnumerable <LeagueDTO> >(leagues));
        }
コード例 #4
0
        public async Task ReturnAllLeaguesWhichExistsInDb()
        {
            // Arrange
            _leagueRepository = SoccerStatisticsContextMocker.GetInMemoryLeagueRepository("GetAllLeagues");

            IEnumerable <League> expectedLeagues = new List <League>
            {
                new League()
                {
                    Id      = 1,
                    Name    = "Primera Division",
                    Country = "Spain",
                    Season  = "2018/2019",
                    MVP     = new Player()
                    {
                        Id = 1, Name = "Lionel", Surname = "Messi"
                    },
                    Winner = new Team()
                    {
                        Id = 1, ShortName = "FC Barcelona"
                    },
                    Rounds = null,
                    Teams  = null
                },
                new League()
                {
                    Id      = 2,
                    Name    = "Serie A",
                    Country = "Italia",
                    Season  = "2017/2018",
                    MVP     = new Player()
                    {
                        Id = 2, Name = "Mauro", Surname = "Icardi"
                    },
                    Winner = new Team()
                    {
                        Id = 2, ShortName = "Juventus"
                    },
                    Rounds = null,
                    Teams  = null
                },
                new League()
                {
                    Id      = 3,
                    Name    = "Lotto Ekstraklasa",
                    Country = "Poland",
                    Season  = "2018/2019",
                    MVP     = new Player()
                    {
                        Id = 3, Name = "Igor", Surname = "Angulo"
                    },
                    Winner = new Team()
                    {
                        Id = 3, ShortName = "Piast Gliwice"
                    },
                    Rounds = null,
                    Teams  = null
                }
            };

            IEnumerable <League> testLeagues = null;

            // Act
            var err = await Record.ExceptionAsync(async
                                                      () => testLeagues = await _leagueRepository.GetAllAsync());

            // Assert
            err.Should().BeNull();

            testLeagues.Should().NotBeNull();

            testLeagues.Should().HaveSameCount(expectedLeagues);

            testLeagues.Should().BeEquivalentTo(expectedLeagues);
        }