예제 #1
0
        public async Task GetSeason_WhenExceptionIsCaught_ShouldReturnInternalServerError()
        {
            // Arrange
            var    seasonRepository = A.Fake <ISeasonRepository>();
            Season?season           = new Season();

            A.CallTo(() => seasonRepository.GetSeasonAsync(A <int> .Ignored)).Throws <Exception>();

            var sharedRepository = A.Fake <ISharedRepository>();

            var         mapper      = A.Fake <IMapper>();
            SeasonModel?seasonModel = new SeasonModel();

            A.CallTo(() => mapper.Map <SeasonModel>(A <Season> .Ignored)).Returns(seasonModel);

            var linkGenerator = A.Fake <LinkGenerator>();

            var testController = new SeasonsController(seasonRepository, sharedRepository, mapper, linkGenerator);

            int id = 1;

            // Act
            var result = await testController.GetSeason(id);

            // Assert
            result.Result.ShouldBeOfType <ObjectResult>();
            ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError);
            ((ObjectResult)result.Result).Value.ShouldBe("Database failure");
        }
예제 #2
0
        public PlayerModel Main(int?SeasonId, int?TeamId)
        {
            PlayerModel p = new PlayerModel();

            p.CurrentUser   = a.AspNetUserByID(User.Identity.GetUserId());
            p.CurrentPlayer = c.GetPlayerbyUserID(p.CurrentUser.Id);
            p.ActiveSeason  = s.GetActiveSeason();
            if (SeasonId != null)
            {
                p.ActiveSeason = s.GetSeasonByID(SeasonId.Value);
            }
            ;
            p.CurrentPlayerTeams = tp.GetTeamsForPlayerandSeason(p.CurrentPlayer.Id, p.ActiveSeason.Id, true, null);
            p.Seasons            = s.GetSeason(p.CurrentPlayer.Id, true, null);
            if (TeamId != null)
            {
                p.ActiveTeam = t.GetTeamById(TeamId.Value);
            }
            if (TeamId == null)
            {
                p.ActiveTeam = t.GetTeamById(p.CurrentPlayerTeams.FirstOrDefault().Teams.Id);
            }

            return(p);
        }
예제 #3
0
        public async Task GetSeason_WhenSeasonIsNotNull_ShouldReturnSeasonModelOfDesiredSeason()
        {
            // Arrange
            var    seasonRepository = A.Fake <ISeasonRepository>();
            Season?season           = new Season();

            A.CallTo(() => seasonRepository.GetSeasonAsync(A <int> .Ignored)).Returns(season);

            var sharedRepository = A.Fake <ISharedRepository>();

            var         mapper      = A.Fake <IMapper>();
            SeasonModel?seasonModel = new SeasonModel();

            A.CallTo(() => mapper.Map <SeasonModel>(A <Season> .Ignored)).Returns(seasonModel);

            var linkGenerator = A.Fake <LinkGenerator>();

            var testController = new SeasonsController(seasonRepository, sharedRepository, mapper, linkGenerator);

            int id = 1;

            // Act
            var result = await testController.GetSeason(id);

            // Assert
            A.CallTo(() => seasonRepository.GetSeasonAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map <SeasonModel>(season)).MustHaveHappenedOnceExactly();
            result.Value.ShouldBeOfType <SeasonModel>();
        }
예제 #4
0
        public async Task GetSeason_WhenCalled_ReturnSeasonFromDb()
        {
            const int id             = 1;
            var       expectedSeason = new Season
            {
                Id = id,
            };

            _seasonService.Setup(s => s.GetDetailByIdAsync(id)).ReturnsAsync(expectedSeason);

            var result = await _seasonsController.GetSeason(id);

            var okObjectResult      = result as OkObjectResult;
            var okObjectResultValue = okObjectResult.Value as SeasonDetailDto;

            Assert.That(result, Is.TypeOf <OkObjectResult>());

            Assert.That(okObjectResultValue, Is.Not.Null);
            Assert.That(okObjectResultValue.Id, Is.EqualTo(id));
        }