Пример #1
0
        public async Task Given_Valid_OrganisationService_And_OrganisationName_And_UserName_When_Call_GetUserAsync_ShouldReturns_OkObjectResult_And_UserInstance(string organisationName, string userName)
        {
            var moqService = new Mock <IUserService>();

            moqService
            .Setup(t => t.GetByUsernameAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new DataContracts.User {
                Username = userName
            })
            .Verifiable();

            var controller = new WebAPI.Controllers.UserController();
            var result     = await controller.GetUserAsync(organisationName, userName, moqService.Object);

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

            var okObjectResult = (OkObjectResult)result;

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

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

            Assert.NotNull(resultOrganisation);
            Assert.Equal(resultOrganisation.Username, userName);
        }
Пример #2
0
        public async Task Given_Invalid_OrganisationName_Or_UserName_When_Call_GetUserAsync_ShouldReturns_BadRequest(string organisationName, string userName)
        {
            var controller = new WebAPI.Controllers.UserController();
            var result     = await controller.GetUserAsync(organisationName, userName, null);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Пример #3
0
        public async Task Given_User_Not_Registered_When_Call_GetUserAsync_ShouldReturns_NotFoundResult(string organisationName, string userName)
        {
            var moqService = new Mock <IUserService>();

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

            var controller = new WebAPI.Controllers.UserController();
            var result     = await controller.GetUserAsync(organisationName, userName, moqService.Object);

            moqService.Verify();
            Assert.IsType <NotFoundResult>(result);
        }
Пример #4
0
        public async Task Given_Invalid_OrganisationService_When_Call_GetUserAsync_ShouldReturns_InternalServerError(string organisationName, string userName)
        {
            var moqService = new Mock <IUserService>();

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

            var controller = new WebAPI.Controllers.UserController();
            var result     = await controller.GetUserAsync(organisationName, userName, moqService.Object);

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

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