public async void CollectAsync_WithCollectRequest__ShouldPostToBankIdCollect_WithJsonPayload() { // Arrange // Act await _bankIdApiClient.CollectAsync(new CollectRequest("abc123")); // Assert Assert.Single(_messageHandlerMock.Invocations); var request = _messageHandlerMock.GetFirstArgumentOfFirstInvocation <HttpMessageHandler, HttpRequestMessage>(); Assert.NotNull(request); Assert.Equal(HttpMethod.Post, request.Method); Assert.Equal(new Uri("https://bankid/collect"), request.RequestUri); Assert.Equal(new MediaTypeHeaderValue("application/json"), request.Content.Headers.ContentType); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnCompletionDataDevice() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"completionData\": { \"device\": { \"ipAddress\": \"1.1.1.1\" } } }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("1.1.1.1", result.CompletionData.Device.IpAddress); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnCompletionDataSignatureXml() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"completionData\": { \"signature\": \"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHNhbXBsZT48dmFsdWU+SGk8L3ZhbHVlPjxjb250ZW50PkJ5ZTwvY29uZW50Pjwvc2FtcGxlPg==\" } }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><sample><value>Hi</value><content>Bye</conent></sample>", result.CompletionData.GetSignatureXml()); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnOrderRef() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"orderRef\":\"abc123\" }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("abc123", result.OrderRef); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnCompletionDataSignature_AndOcspResponse() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"completionData\": { \"signature\": \"s\", \"ocspResponse\": \"or\" } }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("s", result.CompletionData.Signature); Assert.Equal("or", result.CompletionData.OcspResponse); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnStatus() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"status\":\"Pending\" }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("Pending", result.Status); Assert.Equal(CollectStatus.Pending, result.GetCollectStatus()); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnHintCode() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"hintCode\":\"OutstandingTransaction\" }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("OutstandingTransaction", result.HintCode); Assert.Equal(CollectHintCode.OutstandingTransaction, result.GetCollectHintCode()); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnCompletionDataCertDates_ConvetedFromUnixEpochMillisecondsToDateTime() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"completionData\": { \"cert\": { \"notBefore\": \"671630400000\", \"notAfter\": \"671659200000\" } } }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("671630400000", result.CompletionData.Cert.NotBefore); Assert.Equal(new DateTime(1991, 4, 14, 12, 00, 00), result.CompletionData.Cert.GetNotBeforeDateTime()); Assert.Equal("671659200000", result.CompletionData.Cert.NotAfter); Assert.Equal(new DateTime(1991, 4, 14, 20, 00, 00), result.CompletionData.Cert.GetNotAfterDateTime()); }
public async void CollectAsync_WithCollectRequest__ShouldParseAndReturnCompletionDataUser() { // Arrange var httpClient = GetHttpClientMockWithOkResponse("{ \"completionData\": { \"user\": { \"personalNumber\": \"201801012392\", \"name\": \"n\", \"givenName\": \"gn\", \"surname\": \"sn\" } } }"); var bankIdClient = new BankIdApiClient(httpClient); // Act var result = await bankIdClient.CollectAsync(new CollectRequest("x")); // Assert Assert.NotNull(result); Assert.Equal("201801012392", result.CompletionData.User.PersonalIdentityNumber); Assert.Equal("n", result.CompletionData.User.Name); Assert.Equal("gn", result.CompletionData.User.GivenName); Assert.Equal("sn", result.CompletionData.User.Surname); }