Exemplo n.º 1
0
 /// <inheritdoc />
 public async Task AddOrReplaceFileMetaToTransactionAsync(
     FileMeta fileMeta,
     string transactionId,
     string fileId,
     CancellationToken cancellationToken = default)
 {
     await retryPolicy
     .ExecuteAsync(
         ct => client.AddOrReplaceFileMetaToTransactionAsync(
             fileMeta,
             transactionId,
             fileId,
             ct),
         cancellationToken);
 }
        public async void when_AddOrReplaceFileMetaToTransaction_is_called_then_the_request_body_should_contain_the_serialized_file_meta()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Put, "http://localhost/api/transaction/transactionId/file/fileId")
            .WithContent(RequestBodies.AddOrReplaceFileMetaToTransaction)
            .Respond(HttpStatusCode.OK);

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

                var fileSignerMeta = new FileSignerMeta
                {
                    FormSets = new string[] { "SampleFormSet" }
                };

                var field = new Field
                {
                    Type     = "Check",
                    Value    = "I agree",
                    Location = new Location
                    {
                        Search = "test"
                    }
                };

                FileMeta fileMeta = new FileMeta
                {
                    Signers = new Dictionary <string, FileSignerMeta>
                    {
                        { "someSignerId", fileSignerMeta }
                    },
                    FormSets = new Dictionary <string, IDictionary <string, Field> >
                    {
                        { "SampleFormSet", new Dictionary <string, Field>
                          {
                              { "SampleCheck", field }
                          } }
                    }
                };

                await signhostApiClient.AddOrReplaceFileMetaToTransactionAsync(fileMeta, "transactionId", "fileId");
            }

            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();
        }