public async Task AcquireTokenAsync_WhenNoStateIdentifierWasReturnsFromGetStateIdentifierAsync_AssertIsTrustedDomainWasNotCalledOnTrustedDomainHelper()
        {
            ITokenHelper sut = CreateSut(false);

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            _trustedDomainHelperMock.Verify(m => m.IsTrustedDomain(It.IsAny <Uri>()), Times.Never);
        }
        public async Task AcquireTokenAsync_WhenCalled_AssertGetStateIdentifierAsyncWasCalledOnSut()
        {
            ITokenHelper sut = CreateSut();

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            Assert.That(((Sut)sut).GetStateIdentifierAsyncWasCalled, Is.True);
        }
        public async Task AcquireTokenAsync_WhenNoStateIdentifierWasReturnsFromGetStateIdentifierAsync_AssertUnprotectWasNotCalledOnDataProtector()
        {
            ITokenHelper sut = CreateSut(false);

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            _dataProtectorMock.Verify(m => m.Unprotect(It.IsAny <byte[]>()), Times.Never);
        }
        public async Task AcquireTokenAsync_WhenNoStateIdentifierWasReturnsFromGetStateIdentifierAsync_ReturnsBadRequestResult()
        {
            ITokenHelper sut = CreateSut(false);

            HttpContext   httpContext = CreateHttpContext();
            IActionResult result      = await sut.AcquireTokenAsync(httpContext);

            Assert.That(result, Is.TypeOf <BadRequestResult>());
        }
        public async Task AcquireTokenAsync_WhenNoStateIdentifierWasReturnsFromGetStateIdentifierAsync_AssertTokenCookieNameWasCalledWasNotCalledOnSut()
        {
            ITokenHelper sut = CreateSut(false);

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            Assert.That(((Sut)sut).TokenCookieNameWasCalled, Is.False);
        }
        public async Task AcquireTokenAsync_WhenStateIdentifierWasReturnsFromGetStateIdentifierAsyncButNoCookieForStateIdentifierWasFound_ReturnsBadRequestResult()
        {
            Guid         stateIdentifier = Guid.NewGuid();
            ITokenHelper sut             = CreateSut(stateIdentifier: stateIdentifier);

            HttpContext   httpContext = CreateHttpContext();
            IActionResult result      = await sut.AcquireTokenAsync(httpContext);

            Assert.That(result, Is.TypeOf <BadRequestResult>());
        }
        public async Task AcquireTokenAsync_WhenStateIdentifierWasReturnsFromGetStateIdentifierAsyncButNoCookieForStateIdentifierWasFound_AssertTokenCookieNameWasCalledWasNotCalledOnSut()
        {
            Guid         stateIdentifier = Guid.NewGuid();
            ITokenHelper sut             = CreateSut(stateIdentifier: stateIdentifier);

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            Assert.That(((Sut)sut).TokenCookieNameWasCalled, Is.False);
        }
        public async Task AcquireTokenAsync_WhenStateIdentifierWasReturnsFromGetStateIdentifierAsyncButNoCookieForStateIdentifierWasFound_AssertProtectWasNotCalledOnDataProtector()
        {
            Guid         stateIdentifier = Guid.NewGuid();
            ITokenHelper sut             = CreateSut(stateIdentifier: stateIdentifier);

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            _dataProtectorMock.Verify(m => m.Protect(It.IsAny <byte[]>()), Times.Never);
        }
        public async Task AcquireTokenAsync_WhenStateIdentifierWasReturnsFromGetStateIdentifierAsyncButNoCookieForStateIdentifierWasFound_AssertIsTrustedDomainWasNotCalledOnTrustedDomainHelper()
        {
            Guid         stateIdentifier = Guid.NewGuid();
            ITokenHelper sut             = CreateSut(stateIdentifier: stateIdentifier);

            HttpContext httpContext = CreateHttpContext();
            await sut.AcquireTokenAsync(httpContext);

            _trustedDomainHelperMock.Verify(m => m.IsTrustedDomain(It.IsAny <Uri>()), Times.Never);
        }
        public void AcquireTokenAsync_WhenHttpContextIsNull_ThrowsArgumentNullException()
        {
            ITokenHelper sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.AcquireTokenAsync(null));

            Assert.That(result.ParamName, Is.EqualTo("httpContext"));
        }