示例#1
0
        public async Task Given_Valid_OrganisationService_And_OrganisationName_And_TeamName_When_Call_GetTeamAsync_ShouldReturns_OkObjectResult_And_TeamInstance(string organisationName, string teamName)
        {
            var moqService = new Mock <ITeamService>();

            moqService
            .Setup(t => t.GetByTeamNameAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new DataContracts.Team {
                Name = teamName
            })
            .Verifiable();

            var controller = new WebAPI.Controllers.TeamController();
            var result     = await controller.GetTeamAsync(organisationName, teamName, moqService.Object);

            moqService.Verify();
            Assert.IsType <OkObjectResult>(result);

            var okObjectResult = (OkObjectResult)result;

            Assert.NotNull(okObjectResult);
            Assert.NotNull(okObjectResult.Value);

            var resultOrganisation = (DataContracts.Team)okObjectResult.Value;

            Assert.NotNull(resultOrganisation);
            Assert.Equal(resultOrganisation.Name, teamName);
        }
示例#2
0
        public async Task Given_Invalid_OrganisationName_Or_TeamName_When_Call_GetTeamAsync_ShouldReturns_BadRequest(string organisationName, string teamName)
        {
            var controller = new WebAPI.Controllers.TeamController();
            var result     = await controller.GetTeamAsync(organisationName, teamName, null);

            Assert.IsType <BadRequestObjectResult>(result);
        }
示例#3
0
        public async Task Given_Team_Not_Registered_When_Call_GetTeamAsync_ShouldReturns_NotFoundResult(string organisationName, string teamName)
        {
            var moqService = new Mock <ITeamService>();

            moqService
            .Setup(t => t.GetByTeamNameAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(() => null)
            .Verifiable();

            var controller = new WebAPI.Controllers.TeamController();
            var result     = await controller.GetTeamAsync(organisationName, teamName, moqService.Object);

            moqService.Verify();
            Assert.IsType <NotFoundResult>(result);
        }
示例#4
0
        public async Task Given_Invalid_OrganisationService_When_Call_GetTeamAsync_ShouldReturns_InternalServerError(string organisationName, string teamName)
        {
            var moqService = new Mock <ITeamService>();

            moqService
            .Setup(t => t.GetByTeamNameAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Throws <Exception>()
            .Verifiable();

            var controller = new WebAPI.Controllers.TeamController();
            var result     = await controller.GetTeamAsync(organisationName, teamName, moqService.Object);

            moqService.Verify();
            Assert.IsType <StatusCodeResult>(result);
            var internalServerError = (StatusCodeResult)result;

            Assert.NotNull(internalServerError);
            Assert.Equal((int)HttpStatusCode.InternalServerError, internalServerError.StatusCode);
        }