コード例 #1
0
        public async void BankIdFederatedLoginAsync_WithNoParams__ShouldPostToGrandIdFederatedLogin_WithNoPayload()
        {
            // Arrange

            // Act
            await _grandIdApiClient.BankIdFederatedLoginAsync(new BankIdFederatedLoginRequest());

            // Assert
            var request       = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();
            var contentString = await request.Content.ReadAsStringAsync();

            Assert.Empty(contentString);
        }
コード例 #2
0
        public async void BankIdFederatedLoginAsync__ShouldPostToGrandIdFederatedLogin_WithFormPayload()
        {
            // Arrange
            var messageHandlerMock = GetHttpClientMessageHandlerMock(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{ }", Encoding.Default, "application/json"),
            });

            var httpClient = new HttpClient(messageHandlerMock.Object)
            {
                BaseAddress = new Uri("https://grandid/")
            };
            var grandIdApiClient = new GrandIdApiClient(httpClient, new GrandIdApiClientConfiguration("ak", "bsk"));

            // Act
            await grandIdApiClient.BankIdFederatedLoginAsync(new BankIdFederatedLoginRequest("y"));

            // Assert
            Assert.Single(messageHandlerMock.Invocations);
            var request = messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();

            Assert.NotNull(request);

            Assert.Equal(HttpMethod.Post, request.Method);
            Assert.StartsWith("https://grandid/FederatedLogin", request.RequestUri.ToString());
            Assert.Equal(new MediaTypeHeaderValue("application/x-www-form-urlencoded"), request.Content.Headers.ContentType);
        }
コード例 #3
0
        public async void ErrorResponse_WithBadRequestResult__ShouldThrowException_WithErrorCode_AndMessage()
        {
            // Arrange
            var httpClient      = GetHttpClientMockWithBadRequestResponse("{ \"errorObject\": { \"code\": \"FieldsNotValid\", \"message\": \"m\" } }");
            var bankIdApiClient = new GrandIdApiClient(httpClient, new GrandIdApiClientConfiguration("x", "bsk"));

            // Act
            var exception = await Assert.ThrowsAsync <GrandIdApiException>(() => bankIdApiClient.BankIdFederatedLoginAsync(new BankIdFederatedLoginRequest("http://c/")));

            // Assert
            Assert.Equal(ErrorCode.FieldsNotValid, exception.ErrorCode);
            Assert.Equal("m", exception.ErrorDetails);
        }
コード例 #4
0
        public async void BankIdFederatedLoginAsync_WithBankIdFederatedLoginRequest__ShouldParseAndReturnOrderRef_AndAutoStartToken()
        {
            // Arrange
            var httpClient       = GetHttpClientMockWithOkResponse("{ \"sessionId\": \"s\", \"redirectUrl\": \"https://r/\" }");
            var grandIdApiClient = new GrandIdApiClient(httpClient, new GrandIdApiClientConfiguration("x", "bsk"));

            // Act
            var result = await grandIdApiClient.BankIdFederatedLoginAsync(new BankIdFederatedLoginRequest("https://c/"));

            // Assert
            Assert.NotNull(result);
            Assert.Equal("s", result.SessionId);
            Assert.Equal("https://r/", result.RedirectUrl);
        }
コード例 #5
0
        public async void BankIdFederatedLoginAsync_WithApiKey__ShouldPostToGrandIdFederatedLogin_WithApiKey()
        {
            // Arrange
            var messageHandlerMock = GetHttpClientMessageHandlerMock(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("{ }", Encoding.Default, "application/json"),
            });

            var httpClient = new HttpClient(messageHandlerMock.Object)
            {
                BaseAddress = new Uri("https://grandid/")
            };
            var grandIdApiClient = new GrandIdApiClient(httpClient, new GrandIdApiClientConfiguration("ak", "bsk"));

            // Act
            await grandIdApiClient.BankIdFederatedLoginAsync(new BankIdFederatedLoginRequest("https://c/"));

            // Assert
            var request = messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>();

            Assert.Contains("apiKey=ak", request.RequestUri.ToString());
        }