public void AcquireToken_WhenAuthenticationValuesWasResolved_ReturnsOkObjectResultWhereValueIsAccessTokenModel()
        {
            Controller sut = CreateSut();

            OkObjectResult result = (OkObjectResult)sut.AcquireToken(GetLegalGrantType()).Result;

            Assert.That(result.Value, Is.TypeOf <AccessTokenModel>());
        }
        public void AcquireToken_WhenGrantTypeIsNotNullEmptyOrWhiteSpace_AssertGetTokenWasCalledOnClaimResolver()
        {
            Controller sut = CreateSut();

            sut.AcquireToken(GetLegalGrantType());

            _claimResolverMock.Verify(m => m.GetToken <IToken>(It.IsNotNull <Func <string, string> >()), Times.Once);
        }
        public void AcquireToken_WhenAuthenticationValuesWasResolved_ReturnsOkObjectResult()
        {
            Controller sut = CreateSut();

            ActionResult <AccessTokenModel> result = sut.AcquireToken(GetLegalGrantType());

            Assert.That(result.Result, Is.TypeOf <OkObjectResult>());
        }
        public void AcquireToken_WhenAuthenticationValuesWasResolved_ReturnsOkObjectResultWithAccessTokenModelWhereExpiresIsEqualToExpiresFromToken()
        {
            DateTimeOffset expires = DateTime.Today.AddMinutes(5);
            IToken         token   = _fixture.BuildTokenMock(expires: expires.DateTime).Object;
            Controller     sut     = CreateSut(token: token);

            AccessTokenModel result = (AccessTokenModel)((OkObjectResult)sut.AcquireToken(GetLegalGrantType()).Result).Value;

            Assert.That(result.Expires, Is.EqualTo(expires));
        }
        public void AcquireToken_WhenAuthenticationValuesWasResolved_ReturnsOkObjectResultWithAccessTokenModelWhereAccessTokenIsEqualToAccessTokenFromToken()
        {
            string     accessToken = _fixture.Create <string>();
            IToken     token       = _fixture.BuildTokenMock(accessToken: accessToken).Object;
            Controller sut         = CreateSut(token: token);

            AccessTokenModel result = (AccessTokenModel)((OkObjectResult)sut.AcquireToken(GetLegalGrantType()).Result).Value;

            Assert.That(result.AccessToken, Is.EqualTo(accessToken));
        }
        public void AcquireToken_WhenGrantTypeIsEmpty_ThrowsIntranetValidationExceptionWhereErrorCodeIsEqualToValueCannotBeNullOrWhiteSpace()
        {
            Controller sut = CreateSut();

            IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.AcquireToken(string.Empty));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueCannotBeNullOrWhiteSpace));
        }
        public void AcquireToken_WhenGrantTypeIsEmpty_ThrowsIntranetValidationException()
        {
            Controller sut = CreateSut();

            Assert.Throws <IntranetValidationException>(() => sut.AcquireToken(string.Empty));
        }
        public void AcquireToken_WhenGrantTypeIsNull_ThrowsIntranetValidationExceptionWhereValidatingFieldIsEqualToGrantType()
        {
            Controller sut = CreateSut();

            IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.AcquireToken(null));

            Assert.That(result.ValidatingField, Is.EqualTo("grantType"));
        }
        public void AcquireToken_WhenGrantTypeIsNull_ThrowsIntranetValidationExceptionWhereValidatingTypeIsTypeOfString()
        {
            Controller sut = CreateSut();

            IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.AcquireToken(null));

            Assert.That(result.ValidatingType, Is.EqualTo(typeof(string)));
        }
        public void AcquireToken_WhenTokenWasNotResolved_ThrowsIntranetBusinessExceptionWhereErrorCodeIsEqualToCannotRetrieveJwtBearerTokenForAuthenticatedUser()
        {
            Controller sut = CreateSut(false);

            IntranetBusinessException result = Assert.Throws <IntranetBusinessException>(() => sut.AcquireToken(GetLegalGrantType()));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.CannotRetrieveJwtBearerTokenForAuthenticatedUser));
        }
        public void AcquireToken_WhenTokenWasNotResolved_ThrowsIntranetBusinessException()
        {
            Controller sut = CreateSut(false);

            Assert.Throws <IntranetBusinessException>(() => sut.AcquireToken(GetLegalGrantType()));
        }
        public void AcquireToken_WhenGrantTypeIsNotEqualToClientCredentials_ThrowsIntranetBusinessExceptionWhereErrorCodeIsEqualToCannotRetrieveJwtBearerTokenForAuthenticatedUser()
        {
            Controller sut = CreateSut();

            IntranetBusinessException result = Assert.Throws <IntranetBusinessException>(() => sut.AcquireToken(_fixture.Create <string>()));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.CannotRetrieveJwtBearerTokenForAuthenticatedUser));
        }
        public void AcquireToken_WhenGrantTypeIsNotEqualToClientCredentials_ThrowsIntranetBusinessException()
        {
            Controller sut = CreateSut();

            Assert.Throws <IntranetBusinessException>(() => sut.AcquireToken(_fixture.Create <string>()));
        }
        public void AcquireToken_WhenGrantTypeIsWhiteSpace_ThrowsIntranetValidationException()
        {
            Controller sut = CreateSut();

            Assert.Throws <IntranetValidationException>(() => sut.AcquireToken(" "));
        }