Exemplo n.º 1
0
        public async Task TotalPlayers_WhenLeagueCodeExistsInDB_ShouldReturn200()
        {
            var leagueCode = "CL";

            int?result = 5;

            var mapperStub = new MapperConfiguration(mc => mc.AddProfile(new MappingsProfile())).CreateMapper();

            var leagueService = new Mock <ILeagueService>();

            leagueService.Setup(x => x.GetTotalPlayers(It.IsAny <string>())).ReturnsAsync(result);

            var logger = new Mock <ILogger <TotalPlayersController> >();

            var controller   = new TotalPlayersController(leagueService.Object, mapperStub, logger.Object);
            var actionResult = await controller.Get(leagueCode);

            leagueService.Verify(x => x.GetTotalPlayers(It.IsAny <string>()));

            Assert.IsType <OkObjectResult>(actionResult);
            var totalPlayersResult = ((OkObjectResult)actionResult).Value as TotalPlayersResponse;

            Assert.IsType <TotalPlayersResponse>(totalPlayersResult);
            Assert.Equal(5, totalPlayersResult.Total);
        }
Exemplo n.º 2
0
        public async Task WhenImportedCode_DoesntExist_ShouldReturns404Code()
        {
            string code = "CL";
            var    mockPlayerService      = new Mock <IPlayersService>();
            var    mockCompetitionService = new Mock <ICompetitionService>();

            mockCompetitionService.Setup(service => service.Exist(code))
            .ReturnsAsync(false);
            var controller = new TotalPlayersController(mockPlayerService.Object, mockCompetitionService.Object);
            var result     = await controller.GetCount(code) as ObjectResult; // ImportAsync(code).Result as ObjectResult;

            Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode);
        }
Exemplo n.º 3
0
        public async Task WhenImportedCode_Exists_ShouldReturns200Code()
        {
            string code = "CL";
            var    mockPlayerService      = new Mock <IPlayersService>();
            var    mockCompetitionService = new Mock <ICompetitionService>();

            mockCompetitionService.Setup(service => service.Exist(code))
            .ReturnsAsync(true);
            mockPlayerService.Setup(service => service.GetCountByLeagueCode(code))
            .ReturnsAsync(10);
            var controller = new TotalPlayersController(mockPlayerService.Object, mockCompetitionService.Object);
            var result     = await controller.GetCount(code) as ObjectResult;

            Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
        }
Exemplo n.º 4
0
        public async Task WhenImportedCode_Exists_ShouldReturnsTeamsAmount()
        {
            string code = "CL";
            var    mockPlayerService      = new Mock <IPlayersService>();
            var    mockCompetitionService = new Mock <ICompetitionService>();

            mockCompetitionService.Setup(service => service.Exist(code))
            .ReturnsAsync(true);
            mockPlayerService.Setup(service => service.GetCountByLeagueCode(code))
            .ReturnsAsync(10);
            var controller = new TotalPlayersController(mockPlayerService.Object, mockCompetitionService.Object);
            var result     = await controller.GetCount(code) as OkObjectResult;

            var teamsAmount = Assert.IsType <PlayerCountDto>(result.Value);

            Assert.Equal(10, teamsAmount.total);
        }
Exemplo n.º 5
0
        public async Task TotalPlayers_WhenLeagueCodeDoesNotExistsInDB_ShouldReturn404()
        {
            var leagueCode = "CL";

            int?result = null;

            var mapperStub = new MapperConfiguration(mc => mc.AddProfile(new MappingsProfile())).CreateMapper();

            var leagueService = new Mock <ILeagueService>();

            leagueService.Setup(x => x.GetTotalPlayers(It.IsAny <string>())).ReturnsAsync(result);

            var logger = new Mock <ILogger <TotalPlayersController> >();

            var controller   = new TotalPlayersController(leagueService.Object, mapperStub, logger.Object);
            var actionResult = await controller.Get(leagueCode);

            leagueService.Verify(x => x.GetTotalPlayers(It.IsAny <string>()));

            Assert.IsType <NotFoundResult>(actionResult);
        }