예제 #1
0
 /// <inheritdoc />
 public async Task StartTransactionAsync(
     string transactionId,
     CancellationToken cancellationToken = default)
 {
     await retryPolicy
     .ExecuteAsync(
         ct => client.StartTransactionAsync(
             transactionId,
             ct),
         cancellationToken);
 }
        public async Task when_StartTransaction_is_called_then_we_should_have_called_the_transaction_put_once()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect("http://localhost/api/transaction/transaction Id/start")
            .Respond(HttpStatusCode.NoContent);

            using (var httpClient = mockHttp.ToHttpClient()) {
                var signhostApiClient = new SignHostApiClient(settings, httpClient);

                await signhostApiClient.StartTransactionAsync("transaction Id");
            }

            mockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task When_a_complete_transaction_flow_is_created_headers_are_not_set_multiple_times()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Post, "http://localhost/api/transaction")
            .WithHeaders("Application", "APPKey AppKey")
            .WithHeaders("Authorization", "APIKey AuthKey")
            .WithHeaders("X-Custom", "test")
            .Respond(new StringContent(RequestBodies.TransactionSingleSignerJson));
            mockHttp.Expect(HttpMethod.Put, "http://localhost/api/transaction/*/file/somefileid")
            .WithHeaders("Application", "APPKey AppKey")
            .WithHeaders("Authorization", "APIKey AuthKey")
            .WithHeaders("X-Custom", "test")
            .Respond(HttpStatusCode.Accepted, new StringContent(RequestBodies.AddOrReplaceFileMetaToTransaction));
            mockHttp.Expect(HttpMethod.Put, "http://localhost/api/transaction/*/file/somefileid")
            .WithHeaders("Application", "APPKey AppKey")
            .WithHeaders("Authorization", "APIKey AuthKey")
            .WithHeaders("X-Custom", "test")
            .Respond(HttpStatusCode.Created);
            mockHttp.Expect(HttpMethod.Put, "http://localhost/api/transaction/*/start")
            .WithHeaders("Application", "APPKey AppKey")
            .WithHeaders("Authorization", "APIKey AuthKey")
            .WithHeaders("X-Custom", "test")
            .Respond(HttpStatusCode.NoContent);

            using (var httpClient = mockHttp.ToHttpClient()) {
                settings.AddHeader = add => add("X-Custom", "test");
                var signhostApiClient = new SignHostApiClient(settings, httpClient);

                var result = await signhostApiClient.CreateTransactionAsync(new Transaction());

                await signhostApiClient.AddOrReplaceFileMetaToTransactionAsync(new FileMeta(), result.Id, "somefileid");

                using (Stream file = System.IO.File.Create("unittestdocument.pdf")) {
                    await signhostApiClient.AddOrReplaceFileToTransaction(file, result.Id, "somefileid");
                }
                await signhostApiClient.StartTransactionAsync(result.Id);
            }

            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
        }