public async Task when_AddOrReplaceFileToTransaction_is_called_default_digest_is_sha256() { var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(HttpMethod.Put, "http://localhost/api/transaction/transaction Id/file/file Id") .WithHeaders("Digest", "SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") .Respond(HttpStatusCode.OK); using (var httpClient = mockHttp.ToHttpClient()) { var signhostApiClient = new SignHostApiClient(settings, httpClient); await signhostApiClient.AddOrReplaceFileToTransaction(new MemoryStream(), "transaction Id", "file 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(); }
public async Task when_AddOrReplaceFileToTransaction_is_called_then_we_should_have_called_the_file_put_once() { var mockHttp = new MockHttpMessageHandler(); mockHttp .Expect(HttpMethod.Put, "http://localhost/api/transaction/transaction Id/file/file Id") .WithHeaders("Content-Type", "application/pdf") .WithHeaders("Digest", "SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") .Respond(HttpStatusCode.OK); using (var httpClient = mockHttp.ToHttpClient()) { var signhostApiClient = new SignHostApiClient(settings, httpClient); // Create a 0 sized file using (Stream file = System.IO.File.Create("unittestdocument.pdf")) { await signhostApiClient.AddOrReplaceFileToTransaction(file, "transaction Id", "file Id"); } } mockHttp.VerifyNoOutstandingExpectation(); }