From 9d6da552cfa2667434bbe75b1aafffdaa4707722 Mon Sep 17 00:00:00 2001 From: Christoph Kaineder Date: Fri, 11 Oct 2019 13:24:07 +0200 Subject: [PATCH 1/6] tests: add tests for api code examples --- FiskalyClientTest/ApiCodeExamplesTest.cs | 389 ++++++++++++++++++ FiskalyClientTest/ClientTest.cs | 48 +-- FiskalyClientTest/Helper.cs | 54 +++ .../RequestUriEnforcementHandlerTest.cs | 6 - FiskalyClientTest/TransactionHandlerTest.cs | 4 - 5 files changed, 449 insertions(+), 52 deletions(-) create mode 100644 FiskalyClientTest/ApiCodeExamplesTest.cs create mode 100644 FiskalyClientTest/Helper.cs diff --git a/FiskalyClientTest/ApiCodeExamplesTest.cs b/FiskalyClientTest/ApiCodeExamplesTest.cs new file mode 100644 index 0000000..ee5e4d9 --- /dev/null +++ b/FiskalyClientTest/ApiCodeExamplesTest.cs @@ -0,0 +1,389 @@ +using System.Threading.Tasks; +using NUnit.Framework; +using System.Net; +using System.Net.Http; +using System.Text; +using Serilog; +using Newtonsoft.Json.Linq; +using System; + +namespace Fiskaly.Client.Test +{ + public class ApiCodeExamplesTest + { + private static string tssId; + private static string clientId; + private static string serialNumber; + private static string exportId; + private static string txId; + private static int lastRevision; + + [OneTimeSetUp] + public async Task Setup() + { + Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .CreateLogger(); + + var apiKey = Environment.GetEnvironmentVariable("API_KEY"); + var apiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(apiKey, apiSecret).ConfigureAwait(false); + + tssId = Guid.NewGuid().ToString(); + await Helper.CreateTss(client, tssId).ConfigureAwait(false); + clientId = Guid.NewGuid().ToString(); + serialNumber = Guid.NewGuid().ToString(); + await Helper.CreateClient(client, tssId, clientId).ConfigureAwait(false); + exportId = Guid.NewGuid().ToString(); + await Helper.TriggerExport(client, tssId, exportId).ConfigureAwait(false); + txId = Guid.NewGuid().ToString(); + await Helper.CreateTx(client, tssId, clientId, txId).ConfigureAwait(false); + lastRevision = 1; + } + + [Test] + public async Task ListAllClients() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "client"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListClients() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/client"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveClient() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var clientId = "..."; + var url = $"tss/{tssId}/client/{clientId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT", (string)obj["_type"]); + Assert.AreEqual(clientId, (string)obj["_id"]); + } + + [Test] + public async Task UpsertClient() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var clientId = "..."; + // var serialNumber = "..."; + var url = $"tss/{tssId}/client/{clientId}"; + var data = $"{{\"serial_number\": \"{serialNumber}\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT", (string)obj["_type"]); + Assert.AreEqual(clientId, (string)obj["_id"]); + } + + [Test] + public async Task CancelExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var exportId = "..."; + var url = $"tss/{tssId}/export/{exportId}"; + HttpResponseMessage response = await client.DeleteAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task ListAllExports() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "export"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListExports() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/export"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var exportId = "..."; + var url = $"tss/{tssId}/export/{exportId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task TriggerExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var exportId = Guid.NewGuid().ToString(); + var url = $"tss/{tssId}/export/{exportId}"; + var data = "{}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task ListTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "tss"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS", (string)obj["_type"]); + Assert.AreEqual(tssId, (string)obj["_id"]); + } + + [Test] + public async Task UpsertTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var tssId = Guid.NewGuid().ToString(); + var url = $"tss/{tssId}"; + var data = $"{{\"description\": \"\", \"state\": \"INITIALIZED\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS", (string)obj["_type"]); + Assert.AreEqual(tssId, (string)obj["_id"]); + } + + [Test] + public async Task ListAllTransactions() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "tx"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListTransactions() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/tx"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveTransaction() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + var url = $"tss/{tssId}/tx/{txId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION", (string)obj["_type"]); + Assert.AreEqual(txId, (string)obj["_id"]); + } + + [Test] + public async Task RetrieveTransactionLog() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + var url = $"tss/{tssId}/tx/{txId}/log"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + var content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); + + // The code example ends here. + + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [Test] + public async Task UpsertTransaction() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + // var clientId = "..."; + // var lastRevision = "..."; + var url = $"tss/{tssId}/tx/{txId}?last_revision={lastRevision}"; + var data = $"{{\"type\": \"OTHER\", \"data\": {{ \"aeao\": {{ \"other\": {{}} }} }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientId}\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION", (string)obj["_type"]); + Assert.AreEqual(txId, (string)obj["_id"]); + } + } +} diff --git a/FiskalyClientTest/ClientTest.cs b/FiskalyClientTest/ClientTest.cs index d205cf0..b508616 100644 --- a/FiskalyClientTest/ClientTest.cs +++ b/FiskalyClientTest/ClientTest.cs @@ -1,10 +1,7 @@ using System.Threading.Tasks; using NUnit.Framework; using System.Net.Http; -using System.Text; -using Fiskaly.Client; using Serilog; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -14,39 +11,6 @@ public class ClientTest { private HttpClient client; - public StringContent Content(string payload) - { - return new StringContent(payload, Encoding.UTF8, "application/json"); - } - - public async Task CreateTss(string tssGuid) - { - Log.Information("creating tss..."); - var url = $"tss/{tssGuid}"; - var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public async Task CreateClient(string tssGuid, string clientGuid) - { - var url = $"tss/{tssGuid}/client/{clientGuid}"; - var payload = $"{{\"serial_number\": \"{clientGuid}\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public async Task CreateTx(string tssGuid, string clientGuid, string txGuid) - { - var url = $"tss/{tssGuid}/tx/{txGuid}?last_revision=0"; - var payload = $"{{\"type\": \"OTHER\", \"data\": {{ \"binary\": \"test\" }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientGuid}\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - [SetUp] public async Task Setup() { @@ -65,7 +29,7 @@ public async Task Setup() public async Task CreateTss() { var tssGuid = Guid.NewGuid().ToString(); - var response = await CreateTss(tssGuid).ConfigureAwait(false); + var response = await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var description = (string)obj["description"]; @@ -79,10 +43,10 @@ public async Task CreateTss() public async Task CreateClient() { var tssGuid = Guid.NewGuid().ToString(); - await CreateTss(tssGuid).ConfigureAwait(false); + await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); var clientGuid = Guid.NewGuid().ToString(); - var response = await CreateClient(tssGuid, clientGuid).ConfigureAwait(false); + var response = await Helper.CreateClient(client, tssGuid, clientGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var serial = (string)obj["serial_number"]; @@ -94,13 +58,13 @@ public async Task CreateClient() public async Task CreateTx() { var tssGuid = Guid.NewGuid().ToString(); - await CreateTss(tssGuid).ConfigureAwait(false); + await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); var clientGuid = Guid.NewGuid().ToString(); - await CreateClient(tssGuid, clientGuid).ConfigureAwait(false); + await Helper.CreateClient(client, tssGuid, clientGuid).ConfigureAwait(false); var txGuid = Guid.NewGuid().ToString(); - var response = await CreateTx(tssGuid, clientGuid, txGuid).ConfigureAwait(false); + var response = await Helper.CreateTx(client, tssGuid, clientGuid, txGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var number = (string)obj["number"]; diff --git a/FiskalyClientTest/Helper.cs b/FiskalyClientTest/Helper.cs new file mode 100644 index 0000000..fbbe03f --- /dev/null +++ b/FiskalyClientTest/Helper.cs @@ -0,0 +1,54 @@ +using System.Threading.Tasks; +using System.Net.Http; +using System.Text; +using Serilog; +using System; + +namespace Fiskaly.Client.Test +{ + public static class Helper + { + public static StringContent Content(string payload) + { + return new StringContent(payload, Encoding.UTF8, "application/json"); + } + + public static async Task CreateTss(HttpClient client, string tssGuid) + { + Log.Information("creating tss..."); + var url = $"tss/{tssGuid}"; + var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public static async Task CreateClient(HttpClient client, string tssGuid, string clientGuid) + { + var url = $"tss/{tssGuid}/client/{clientGuid}"; + var payload = $"{{\"serial_number\": \"{clientGuid}\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public static async Task CreateTx(HttpClient client, string tssGuid, string clientGuid, string txGuid) + { + var url = $"tss/{tssGuid}/tx/{txGuid}?last_revision=0"; + var payload = $"{{\"type\": \"OTHER\", \"data\": {{ \"binary\": \"test\" }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientGuid}\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public static async Task TriggerExport(HttpClient client, string tssGuid, string exportGuid) + { + Log.Information("triggering export..."); + var url = $"tss/{tssGuid}/export/{exportGuid}"; + var payload = "{}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + } +} diff --git a/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs b/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs index b8383fe..6b80f9d 100644 --- a/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs +++ b/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs @@ -1,12 +1,6 @@ -using Fiskaly.Client; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NUnit.Framework; -using System; -using Serilog; using System.Net; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/FiskalyClientTest/TransactionHandlerTest.cs b/FiskalyClientTest/TransactionHandlerTest.cs index d092bcf..5849622 100644 --- a/FiskalyClientTest/TransactionHandlerTest.cs +++ b/FiskalyClientTest/TransactionHandlerTest.cs @@ -1,9 +1,5 @@ -using Fiskaly.Client; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NUnit.Framework; using System; -using Serilog; using System.Net; using System.Net.Http; using System.Text; From b919f2adb445c97005b24beb6f6fd3dd9d6d4dd4 Mon Sep 17 00:00:00 2001 From: Christoph Kaineder Date: Fri, 11 Oct 2019 13:31:09 +0200 Subject: [PATCH 2/6] Revert "tests: add tests for api code examples" This reverts commit 9d6da552cfa2667434bbe75b1aafffdaa4707722. --- FiskalyClientTest/ApiCodeExamplesTest.cs | 389 ------------------ FiskalyClientTest/ClientTest.cs | 48 ++- FiskalyClientTest/Helper.cs | 54 --- .../RequestUriEnforcementHandlerTest.cs | 6 + FiskalyClientTest/TransactionHandlerTest.cs | 4 + 5 files changed, 52 insertions(+), 449 deletions(-) delete mode 100644 FiskalyClientTest/ApiCodeExamplesTest.cs delete mode 100644 FiskalyClientTest/Helper.cs diff --git a/FiskalyClientTest/ApiCodeExamplesTest.cs b/FiskalyClientTest/ApiCodeExamplesTest.cs deleted file mode 100644 index ee5e4d9..0000000 --- a/FiskalyClientTest/ApiCodeExamplesTest.cs +++ /dev/null @@ -1,389 +0,0 @@ -using System.Threading.Tasks; -using NUnit.Framework; -using System.Net; -using System.Net.Http; -using System.Text; -using Serilog; -using Newtonsoft.Json.Linq; -using System; - -namespace Fiskaly.Client.Test -{ - public class ApiCodeExamplesTest - { - private static string tssId; - private static string clientId; - private static string serialNumber; - private static string exportId; - private static string txId; - private static int lastRevision; - - [OneTimeSetUp] - public async Task Setup() - { - Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateLogger(); - - var apiKey = Environment.GetEnvironmentVariable("API_KEY"); - var apiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(apiKey, apiSecret).ConfigureAwait(false); - - tssId = Guid.NewGuid().ToString(); - await Helper.CreateTss(client, tssId).ConfigureAwait(false); - clientId = Guid.NewGuid().ToString(); - serialNumber = Guid.NewGuid().ToString(); - await Helper.CreateClient(client, tssId, clientId).ConfigureAwait(false); - exportId = Guid.NewGuid().ToString(); - await Helper.TriggerExport(client, tssId, exportId).ConfigureAwait(false); - txId = Guid.NewGuid().ToString(); - await Helper.CreateTx(client, tssId, clientId, txId).ConfigureAwait(false); - lastRevision = 1; - } - - [Test] - public async Task ListAllClients() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "client"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task ListClients() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}/client"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveClient() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var clientId = "..."; - var url = $"tss/{tssId}/client/{clientId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT", (string)obj["_type"]); - Assert.AreEqual(clientId, (string)obj["_id"]); - } - - [Test] - public async Task UpsertClient() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var clientId = "..."; - // var serialNumber = "..."; - var url = $"tss/{tssId}/client/{clientId}"; - var data = $"{{\"serial_number\": \"{serialNumber}\"}}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT", (string)obj["_type"]); - Assert.AreEqual(clientId, (string)obj["_id"]); - } - - [Test] - public async Task CancelExport() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var exportId = "..."; - var url = $"tss/{tssId}/export/{exportId}"; - HttpResponseMessage response = await client.DeleteAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT", (string)obj["_type"]); - Assert.AreEqual(exportId, (string)obj["_id"]); - } - - [Test] - public async Task ListAllExports() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "export"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task ListExports() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}/export"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveExport() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var exportId = "..."; - var url = $"tss/{tssId}/export/{exportId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT", (string)obj["_type"]); - Assert.AreEqual(exportId, (string)obj["_id"]); - } - - [Test] - public async Task TriggerExport() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var exportId = Guid.NewGuid().ToString(); - var url = $"tss/{tssId}/export/{exportId}"; - var data = "{}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT", (string)obj["_type"]); - Assert.AreEqual(exportId, (string)obj["_id"]); - } - - [Test] - public async Task ListTss() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "tss"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TSS_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveTss() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TSS", (string)obj["_type"]); - Assert.AreEqual(tssId, (string)obj["_id"]); - } - - [Test] - public async Task UpsertTss() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var tssId = Guid.NewGuid().ToString(); - var url = $"tss/{tssId}"; - var data = $"{{\"description\": \"\", \"state\": \"INITIALIZED\"}}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TSS", (string)obj["_type"]); - Assert.AreEqual(tssId, (string)obj["_id"]); - } - - [Test] - public async Task ListAllTransactions() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "tx"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); - } - - [Test] - public async Task ListTransactions() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}/tx"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveTransaction() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var txId = "..."; - var url = $"tss/{tssId}/tx/{txId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION", (string)obj["_type"]); - Assert.AreEqual(txId, (string)obj["_id"]); - } - - [Test] - public async Task RetrieveTransactionLog() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var txId = "..."; - var url = $"tss/{tssId}/tx/{txId}/log"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - var content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); - - // The code example ends here. - - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - } - - [Test] - public async Task UpsertTransaction() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var txId = "..."; - // var clientId = "..."; - // var lastRevision = "..."; - var url = $"tss/{tssId}/tx/{txId}?last_revision={lastRevision}"; - var data = $"{{\"type\": \"OTHER\", \"data\": {{ \"aeao\": {{ \"other\": {{}} }} }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientId}\"}}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION", (string)obj["_type"]); - Assert.AreEqual(txId, (string)obj["_id"]); - } - } -} diff --git a/FiskalyClientTest/ClientTest.cs b/FiskalyClientTest/ClientTest.cs index b508616..d205cf0 100644 --- a/FiskalyClientTest/ClientTest.cs +++ b/FiskalyClientTest/ClientTest.cs @@ -1,7 +1,10 @@ using System.Threading.Tasks; using NUnit.Framework; using System.Net.Http; +using System.Text; +using Fiskaly.Client; using Serilog; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -11,6 +14,39 @@ public class ClientTest { private HttpClient client; + public StringContent Content(string payload) + { + return new StringContent(payload, Encoding.UTF8, "application/json"); + } + + public async Task CreateTss(string tssGuid) + { + Log.Information("creating tss..."); + var url = $"tss/{tssGuid}"; + var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public async Task CreateClient(string tssGuid, string clientGuid) + { + var url = $"tss/{tssGuid}/client/{clientGuid}"; + var payload = $"{{\"serial_number\": \"{clientGuid}\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public async Task CreateTx(string tssGuid, string clientGuid, string txGuid) + { + var url = $"tss/{tssGuid}/tx/{txGuid}?last_revision=0"; + var payload = $"{{\"type\": \"OTHER\", \"data\": {{ \"binary\": \"test\" }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientGuid}\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + [SetUp] public async Task Setup() { @@ -29,7 +65,7 @@ public async Task Setup() public async Task CreateTss() { var tssGuid = Guid.NewGuid().ToString(); - var response = await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); + var response = await CreateTss(tssGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var description = (string)obj["description"]; @@ -43,10 +79,10 @@ public async Task CreateTss() public async Task CreateClient() { var tssGuid = Guid.NewGuid().ToString(); - await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); + await CreateTss(tssGuid).ConfigureAwait(false); var clientGuid = Guid.NewGuid().ToString(); - var response = await Helper.CreateClient(client, tssGuid, clientGuid).ConfigureAwait(false); + var response = await CreateClient(tssGuid, clientGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var serial = (string)obj["serial_number"]; @@ -58,13 +94,13 @@ public async Task CreateClient() public async Task CreateTx() { var tssGuid = Guid.NewGuid().ToString(); - await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); + await CreateTss(tssGuid).ConfigureAwait(false); var clientGuid = Guid.NewGuid().ToString(); - await Helper.CreateClient(client, tssGuid, clientGuid).ConfigureAwait(false); + await CreateClient(tssGuid, clientGuid).ConfigureAwait(false); var txGuid = Guid.NewGuid().ToString(); - var response = await Helper.CreateTx(client, tssGuid, clientGuid, txGuid).ConfigureAwait(false); + var response = await CreateTx(tssGuid, clientGuid, txGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var number = (string)obj["number"]; diff --git a/FiskalyClientTest/Helper.cs b/FiskalyClientTest/Helper.cs deleted file mode 100644 index fbbe03f..0000000 --- a/FiskalyClientTest/Helper.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Threading.Tasks; -using System.Net.Http; -using System.Text; -using Serilog; -using System; - -namespace Fiskaly.Client.Test -{ - public static class Helper - { - public static StringContent Content(string payload) - { - return new StringContent(payload, Encoding.UTF8, "application/json"); - } - - public static async Task CreateTss(HttpClient client, string tssGuid) - { - Log.Information("creating tss..."); - var url = $"tss/{tssGuid}"; - var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public static async Task CreateClient(HttpClient client, string tssGuid, string clientGuid) - { - var url = $"tss/{tssGuid}/client/{clientGuid}"; - var payload = $"{{\"serial_number\": \"{clientGuid}\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public static async Task CreateTx(HttpClient client, string tssGuid, string clientGuid, string txGuid) - { - var url = $"tss/{tssGuid}/tx/{txGuid}?last_revision=0"; - var payload = $"{{\"type\": \"OTHER\", \"data\": {{ \"binary\": \"test\" }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientGuid}\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public static async Task TriggerExport(HttpClient client, string tssGuid, string exportGuid) - { - Log.Information("triggering export..."); - var url = $"tss/{tssGuid}/export/{exportGuid}"; - var payload = "{}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - } -} diff --git a/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs b/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs index 6b80f9d..b8383fe 100644 --- a/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs +++ b/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs @@ -1,6 +1,12 @@ +using Fiskaly.Client; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NUnit.Framework; +using System; +using Serilog; using System.Net; using System.Net.Http; +using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/FiskalyClientTest/TransactionHandlerTest.cs b/FiskalyClientTest/TransactionHandlerTest.cs index 5849622..d092bcf 100644 --- a/FiskalyClientTest/TransactionHandlerTest.cs +++ b/FiskalyClientTest/TransactionHandlerTest.cs @@ -1,5 +1,9 @@ +using Fiskaly.Client; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NUnit.Framework; using System; +using Serilog; using System.Net; using System.Net.Http; using System.Text; From 92d0be8304a55715617d0fcc07fc8ae003949ffa Mon Sep 17 00:00:00 2001 From: Christoph Kaineder Date: Fri, 11 Oct 2019 13:34:20 +0200 Subject: [PATCH 3/6] tests: add tests for api code examples --- FiskalyClientTest/ApiCodeExamplesTest.cs | 389 ++++++++++++++++++ FiskalyClientTest/ClientTest.cs | 48 +-- FiskalyClientTest/Helper.cs | 54 +++ .../RequestUriEnforcementHandlerTest.cs | 6 - FiskalyClientTest/TransactionHandlerTest.cs | 4 - 5 files changed, 449 insertions(+), 52 deletions(-) create mode 100644 FiskalyClientTest/ApiCodeExamplesTest.cs create mode 100644 FiskalyClientTest/Helper.cs diff --git a/FiskalyClientTest/ApiCodeExamplesTest.cs b/FiskalyClientTest/ApiCodeExamplesTest.cs new file mode 100644 index 0000000..ee5e4d9 --- /dev/null +++ b/FiskalyClientTest/ApiCodeExamplesTest.cs @@ -0,0 +1,389 @@ +using System.Threading.Tasks; +using NUnit.Framework; +using System.Net; +using System.Net.Http; +using System.Text; +using Serilog; +using Newtonsoft.Json.Linq; +using System; + +namespace Fiskaly.Client.Test +{ + public class ApiCodeExamplesTest + { + private static string tssId; + private static string clientId; + private static string serialNumber; + private static string exportId; + private static string txId; + private static int lastRevision; + + [OneTimeSetUp] + public async Task Setup() + { + Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .CreateLogger(); + + var apiKey = Environment.GetEnvironmentVariable("API_KEY"); + var apiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(apiKey, apiSecret).ConfigureAwait(false); + + tssId = Guid.NewGuid().ToString(); + await Helper.CreateTss(client, tssId).ConfigureAwait(false); + clientId = Guid.NewGuid().ToString(); + serialNumber = Guid.NewGuid().ToString(); + await Helper.CreateClient(client, tssId, clientId).ConfigureAwait(false); + exportId = Guid.NewGuid().ToString(); + await Helper.TriggerExport(client, tssId, exportId).ConfigureAwait(false); + txId = Guid.NewGuid().ToString(); + await Helper.CreateTx(client, tssId, clientId, txId).ConfigureAwait(false); + lastRevision = 1; + } + + [Test] + public async Task ListAllClients() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "client"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListClients() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/client"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveClient() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var clientId = "..."; + var url = $"tss/{tssId}/client/{clientId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT", (string)obj["_type"]); + Assert.AreEqual(clientId, (string)obj["_id"]); + } + + [Test] + public async Task UpsertClient() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var clientId = "..."; + // var serialNumber = "..."; + var url = $"tss/{tssId}/client/{clientId}"; + var data = $"{{\"serial_number\": \"{serialNumber}\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT", (string)obj["_type"]); + Assert.AreEqual(clientId, (string)obj["_id"]); + } + + [Test] + public async Task CancelExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var exportId = "..."; + var url = $"tss/{tssId}/export/{exportId}"; + HttpResponseMessage response = await client.DeleteAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task ListAllExports() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "export"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListExports() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/export"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var exportId = "..."; + var url = $"tss/{tssId}/export/{exportId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task TriggerExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var exportId = Guid.NewGuid().ToString(); + var url = $"tss/{tssId}/export/{exportId}"; + var data = "{}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task ListTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "tss"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS", (string)obj["_type"]); + Assert.AreEqual(tssId, (string)obj["_id"]); + } + + [Test] + public async Task UpsertTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var tssId = Guid.NewGuid().ToString(); + var url = $"tss/{tssId}"; + var data = $"{{\"description\": \"\", \"state\": \"INITIALIZED\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS", (string)obj["_type"]); + Assert.AreEqual(tssId, (string)obj["_id"]); + } + + [Test] + public async Task ListAllTransactions() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "tx"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListTransactions() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/tx"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveTransaction() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + var url = $"tss/{tssId}/tx/{txId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION", (string)obj["_type"]); + Assert.AreEqual(txId, (string)obj["_id"]); + } + + [Test] + public async Task RetrieveTransactionLog() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + var url = $"tss/{tssId}/tx/{txId}/log"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + var content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); + + // The code example ends here. + + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [Test] + public async Task UpsertTransaction() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + // var clientId = "..."; + // var lastRevision = "..."; + var url = $"tss/{tssId}/tx/{txId}?last_revision={lastRevision}"; + var data = $"{{\"type\": \"OTHER\", \"data\": {{ \"aeao\": {{ \"other\": {{}} }} }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientId}\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION", (string)obj["_type"]); + Assert.AreEqual(txId, (string)obj["_id"]); + } + } +} diff --git a/FiskalyClientTest/ClientTest.cs b/FiskalyClientTest/ClientTest.cs index d205cf0..b508616 100644 --- a/FiskalyClientTest/ClientTest.cs +++ b/FiskalyClientTest/ClientTest.cs @@ -1,10 +1,7 @@ using System.Threading.Tasks; using NUnit.Framework; using System.Net.Http; -using System.Text; -using Fiskaly.Client; using Serilog; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -14,39 +11,6 @@ public class ClientTest { private HttpClient client; - public StringContent Content(string payload) - { - return new StringContent(payload, Encoding.UTF8, "application/json"); - } - - public async Task CreateTss(string tssGuid) - { - Log.Information("creating tss..."); - var url = $"tss/{tssGuid}"; - var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public async Task CreateClient(string tssGuid, string clientGuid) - { - var url = $"tss/{tssGuid}/client/{clientGuid}"; - var payload = $"{{\"serial_number\": \"{clientGuid}\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - - public async Task CreateTx(string tssGuid, string clientGuid, string txGuid) - { - var url = $"tss/{tssGuid}/tx/{txGuid}?last_revision=0"; - var payload = $"{{\"type\": \"OTHER\", \"data\": {{ \"binary\": \"test\" }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientGuid}\"}}"; - var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); - Log.Information("response: {@Response}", response); - return await response.Content.ReadAsStringAsync().ConfigureAwait(false); - } - [SetUp] public async Task Setup() { @@ -65,7 +29,7 @@ public async Task Setup() public async Task CreateTss() { var tssGuid = Guid.NewGuid().ToString(); - var response = await CreateTss(tssGuid).ConfigureAwait(false); + var response = await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var description = (string)obj["description"]; @@ -79,10 +43,10 @@ public async Task CreateTss() public async Task CreateClient() { var tssGuid = Guid.NewGuid().ToString(); - await CreateTss(tssGuid).ConfigureAwait(false); + await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); var clientGuid = Guid.NewGuid().ToString(); - var response = await CreateClient(tssGuid, clientGuid).ConfigureAwait(false); + var response = await Helper.CreateClient(client, tssGuid, clientGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var serial = (string)obj["serial_number"]; @@ -94,13 +58,13 @@ public async Task CreateClient() public async Task CreateTx() { var tssGuid = Guid.NewGuid().ToString(); - await CreateTss(tssGuid).ConfigureAwait(false); + await Helper.CreateTss(client, tssGuid).ConfigureAwait(false); var clientGuid = Guid.NewGuid().ToString(); - await CreateClient(tssGuid, clientGuid).ConfigureAwait(false); + await Helper.CreateClient(client, tssGuid, clientGuid).ConfigureAwait(false); var txGuid = Guid.NewGuid().ToString(); - var response = await CreateTx(tssGuid, clientGuid, txGuid).ConfigureAwait(false); + var response = await Helper.CreateTx(client, tssGuid, clientGuid, txGuid).ConfigureAwait(false); var obj = JObject.Parse(response); var number = (string)obj["number"]; diff --git a/FiskalyClientTest/Helper.cs b/FiskalyClientTest/Helper.cs new file mode 100644 index 0000000..fbbe03f --- /dev/null +++ b/FiskalyClientTest/Helper.cs @@ -0,0 +1,54 @@ +using System.Threading.Tasks; +using System.Net.Http; +using System.Text; +using Serilog; +using System; + +namespace Fiskaly.Client.Test +{ + public static class Helper + { + public static StringContent Content(string payload) + { + return new StringContent(payload, Encoding.UTF8, "application/json"); + } + + public static async Task CreateTss(HttpClient client, string tssGuid) + { + Log.Information("creating tss..."); + var url = $"tss/{tssGuid}"; + var payload = $"{{\"description\": \"{tssGuid}\", \"state\": \"INITIALIZED\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public static async Task CreateClient(HttpClient client, string tssGuid, string clientGuid) + { + var url = $"tss/{tssGuid}/client/{clientGuid}"; + var payload = $"{{\"serial_number\": \"{clientGuid}\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public static async Task CreateTx(HttpClient client, string tssGuid, string clientGuid, string txGuid) + { + var url = $"tss/{tssGuid}/tx/{txGuid}?last_revision=0"; + var payload = $"{{\"type\": \"OTHER\", \"data\": {{ \"binary\": \"test\" }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientGuid}\"}}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + + public static async Task TriggerExport(HttpClient client, string tssGuid, string exportGuid) + { + Log.Information("triggering export..."); + var url = $"tss/{tssGuid}/export/{exportGuid}"; + var payload = "{}"; + var response = await client.PutAsync(url, Content(payload)).ConfigureAwait(false); + Log.Information("response: {@Response}", response); + return await response.Content.ReadAsStringAsync().ConfigureAwait(false); + } + } +} diff --git a/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs b/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs index b8383fe..6b80f9d 100644 --- a/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs +++ b/FiskalyClientTest/RequestUriEnforcementHandlerTest.cs @@ -1,12 +1,6 @@ -using Fiskaly.Client; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NUnit.Framework; -using System; -using Serilog; using System.Net; using System.Net.Http; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/FiskalyClientTest/TransactionHandlerTest.cs b/FiskalyClientTest/TransactionHandlerTest.cs index d092bcf..5849622 100644 --- a/FiskalyClientTest/TransactionHandlerTest.cs +++ b/FiskalyClientTest/TransactionHandlerTest.cs @@ -1,9 +1,5 @@ -using Fiskaly.Client; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using NUnit.Framework; using System; -using Serilog; using System.Net; using System.Net.Http; using System.Text; From 8841ce7731c757c1a8e771589c6ba59f74bf5ee5 Mon Sep 17 00:00:00 2001 From: Christoph Kaineder Date: Fri, 11 Oct 2019 15:42:22 +0200 Subject: [PATCH 4/6] style: formatting --- FiskalyClientTest/ApiCodeExamplesTest.cs | 750 +++++++++++------------ 1 file changed, 375 insertions(+), 375 deletions(-) diff --git a/FiskalyClientTest/ApiCodeExamplesTest.cs b/FiskalyClientTest/ApiCodeExamplesTest.cs index ee5e4d9..69d31b3 100644 --- a/FiskalyClientTest/ApiCodeExamplesTest.cs +++ b/FiskalyClientTest/ApiCodeExamplesTest.cs @@ -9,381 +9,381 @@ namespace Fiskaly.Client.Test { - public class ApiCodeExamplesTest - { - private static string tssId; - private static string clientId; - private static string serialNumber; - private static string exportId; - private static string txId; - private static int lastRevision; - - [OneTimeSetUp] - public async Task Setup() + public class ApiCodeExamplesTest { - Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateLogger(); - - var apiKey = Environment.GetEnvironmentVariable("API_KEY"); - var apiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(apiKey, apiSecret).ConfigureAwait(false); - - tssId = Guid.NewGuid().ToString(); - await Helper.CreateTss(client, tssId).ConfigureAwait(false); - clientId = Guid.NewGuid().ToString(); - serialNumber = Guid.NewGuid().ToString(); - await Helper.CreateClient(client, tssId, clientId).ConfigureAwait(false); - exportId = Guid.NewGuid().ToString(); - await Helper.TriggerExport(client, tssId, exportId).ConfigureAwait(false); - txId = Guid.NewGuid().ToString(); - await Helper.CreateTx(client, tssId, clientId, txId).ConfigureAwait(false); - lastRevision = 1; + private static string tssId; + private static string clientId; + private static string serialNumber; + private static string exportId; + private static string txId; + private static int lastRevision; + + [OneTimeSetUp] + public async Task Setup() + { + Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .CreateLogger(); + + var apiKey = Environment.GetEnvironmentVariable("API_KEY"); + var apiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(apiKey, apiSecret).ConfigureAwait(false); + + tssId = Guid.NewGuid().ToString(); + await Helper.CreateTss(client, tssId).ConfigureAwait(false); + clientId = Guid.NewGuid().ToString(); + serialNumber = Guid.NewGuid().ToString(); + await Helper.CreateClient(client, tssId, clientId).ConfigureAwait(false); + exportId = Guid.NewGuid().ToString(); + await Helper.TriggerExport(client, tssId, exportId).ConfigureAwait(false); + txId = Guid.NewGuid().ToString(); + await Helper.CreateTx(client, tssId, clientId, txId).ConfigureAwait(false); + lastRevision = 1; + } + + [Test] + public async Task ListAllClients() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "client"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListClients() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/client"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveClient() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var clientId = "..."; + var url = $"tss/{tssId}/client/{clientId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT", (string)obj["_type"]); + Assert.AreEqual(clientId, (string)obj["_id"]); + } + + [Test] + public async Task UpsertClient() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var clientId = "..."; + // var serialNumber = "..."; + var url = $"tss/{tssId}/client/{clientId}"; + var data = $"{{\"serial_number\": \"{serialNumber}\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("CLIENT", (string)obj["_type"]); + Assert.AreEqual(clientId, (string)obj["_id"]); + } + + [Test] + public async Task CancelExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var exportId = "..."; + var url = $"tss/{tssId}/export/{exportId}"; + HttpResponseMessage response = await client.DeleteAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task ListAllExports() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "export"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListExports() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/export"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var exportId = "..."; + var url = $"tss/{tssId}/export/{exportId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task TriggerExport() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var exportId = Guid.NewGuid().ToString(); + var url = $"tss/{tssId}/export/{exportId}"; + var data = "{}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("EXPORT", (string)obj["_type"]); + Assert.AreEqual(exportId, (string)obj["_id"]); + } + + [Test] + public async Task ListTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "tss"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS", (string)obj["_type"]); + Assert.AreEqual(tssId, (string)obj["_id"]); + } + + [Test] + public async Task UpsertTss() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var tssId = Guid.NewGuid().ToString(); + var url = $"tss/{tssId}"; + var data = $"{{\"description\": \"\", \"state\": \"INITIALIZED\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TSS", (string)obj["_type"]); + Assert.AreEqual(tssId, (string)obj["_id"]); + } + + [Test] + public async Task ListAllTransactions() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + var url = "tx"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); + } + + [Test] + public async Task ListTransactions() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + var url = $"tss/{tssId}/tx"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); + } + + [Test] + public async Task RetrieveTransaction() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + var url = $"tss/{tssId}/tx/{txId}"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION", (string)obj["_type"]); + Assert.AreEqual(txId, (string)obj["_id"]); + } + + [Test] + public async Task RetrieveTransactionLog() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + var url = $"tss/{tssId}/tx/{txId}/log"; + HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); + var content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); + + // The code example ends here. + + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } + + [Test] + public async Task UpsertTransaction() + { + String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); + String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); + HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); + + // var tssId = "..."; + // var txId = "..."; + // var clientId = "..."; + // var lastRevision = "..."; + var url = $"tss/{tssId}/tx/{txId}?last_revision={lastRevision}"; + var data = $"{{\"type\": \"OTHER\", \"data\": {{ \"aeao\": {{ \"other\": {{}} }} }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientId}\"}}"; + var payload = new StringContent(data, Encoding.UTF8, "application/json"); + HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); + String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + var obj = JObject.Parse(content); + + // The code example ends here. + + Console.WriteLine(obj); + Assert.AreEqual("TRANSACTION", (string)obj["_type"]); + Assert.AreEqual(txId, (string)obj["_id"]); + } } - - [Test] - public async Task ListAllClients() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "client"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task ListClients() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}/client"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveClient() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var clientId = "..."; - var url = $"tss/{tssId}/client/{clientId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT", (string)obj["_type"]); - Assert.AreEqual(clientId, (string)obj["_id"]); - } - - [Test] - public async Task UpsertClient() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var clientId = "..."; - // var serialNumber = "..."; - var url = $"tss/{tssId}/client/{clientId}"; - var data = $"{{\"serial_number\": \"{serialNumber}\"}}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("CLIENT", (string)obj["_type"]); - Assert.AreEqual(clientId, (string)obj["_id"]); - } - - [Test] - public async Task CancelExport() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var exportId = "..."; - var url = $"tss/{tssId}/export/{exportId}"; - HttpResponseMessage response = await client.DeleteAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT", (string)obj["_type"]); - Assert.AreEqual(exportId, (string)obj["_id"]); - } - - [Test] - public async Task ListAllExports() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "export"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task ListExports() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}/export"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveExport() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var exportId = "..."; - var url = $"tss/{tssId}/export/{exportId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT", (string)obj["_type"]); - Assert.AreEqual(exportId, (string)obj["_id"]); - } - - [Test] - public async Task TriggerExport() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var exportId = Guid.NewGuid().ToString(); - var url = $"tss/{tssId}/export/{exportId}"; - var data = "{}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("EXPORT", (string)obj["_type"]); - Assert.AreEqual(exportId, (string)obj["_id"]); - } - - [Test] - public async Task ListTss() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "tss"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TSS_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveTss() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TSS", (string)obj["_type"]); - Assert.AreEqual(tssId, (string)obj["_id"]); - } - - [Test] - public async Task UpsertTss() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var tssId = Guid.NewGuid().ToString(); - var url = $"tss/{tssId}"; - var data = $"{{\"description\": \"\", \"state\": \"INITIALIZED\"}}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TSS", (string)obj["_type"]); - Assert.AreEqual(tssId, (string)obj["_id"]); - } - - [Test] - public async Task ListAllTransactions() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - var url = "tx"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); - } - - [Test] - public async Task ListTransactions() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - var url = $"tss/{tssId}/tx"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION_LIST", (string)obj["_type"]); - } - - [Test] - public async Task RetrieveTransaction() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var txId = "..."; - var url = $"tss/{tssId}/tx/{txId}"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION", (string)obj["_type"]); - Assert.AreEqual(txId, (string)obj["_id"]); - } - - [Test] - public async Task RetrieveTransactionLog() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var txId = "..."; - var url = $"tss/{tssId}/tx/{txId}/log"; - HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); - var content = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); - - // The code example ends here. - - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - } - - [Test] - public async Task UpsertTransaction() - { - String ApiKey = Environment.GetEnvironmentVariable("API_KEY"); - String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); - HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - - // var tssId = "..."; - // var txId = "..."; - // var clientId = "..."; - // var lastRevision = "..."; - var url = $"tss/{tssId}/tx/{txId}?last_revision={lastRevision}"; - var data = $"{{\"type\": \"OTHER\", \"data\": {{ \"aeao\": {{ \"other\": {{}} }} }}, \"state\": \"ACTIVE\", \"client_id\": \"{clientId}\"}}"; - var payload = new StringContent(data, Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); - String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var obj = JObject.Parse(content); - - // The code example ends here. - - Console.WriteLine(obj); - Assert.AreEqual("TRANSACTION", (string)obj["_type"]); - Assert.AreEqual(txId, (string)obj["_id"]); - } - } } From e9e6379aeee8b0d67f4be227ddac3c745d86da0b Mon Sep 17 00:00:00 2001 From: Christoph Kaineder Date: Wed, 16 Oct 2019 11:08:27 +0200 Subject: [PATCH 5/6] tests: minor change in api code example test --- FiskalyClientTest/ApiCodeExamplesTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FiskalyClientTest/ApiCodeExamplesTest.cs b/FiskalyClientTest/ApiCodeExamplesTest.cs index 69d31b3..520b554 100644 --- a/FiskalyClientTest/ApiCodeExamplesTest.cs +++ b/FiskalyClientTest/ApiCodeExamplesTest.cs @@ -270,9 +270,9 @@ public async Task UpsertTss() String ApiSecret = Environment.GetEnvironmentVariable("API_SECRET"); HttpClient client = await ClientFactory.Create(ApiKey, ApiSecret).ConfigureAwait(false); - var tssId = Guid.NewGuid().ToString(); + // var tssId = "..."; var url = $"tss/{tssId}"; - var data = $"{{\"description\": \"\", \"state\": \"INITIALIZED\"}}"; + var data = $"{{\"state\": \"INITIALIZED\"}}"; var payload = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PutAsync(url, payload).ConfigureAwait(false); String content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); From 05b9333cc33f2b006bfb72103b44b3a31081f84d Mon Sep 17 00:00:00 2001 From: Christoph Kaineder Date: Tue, 22 Oct 2019 14:07:04 +0200 Subject: [PATCH 6/6] add minimal visual basic example --- FiskalyClientVbDemo/FiskalyClientVbDemo.vbproj | 18 ++++++++++++++++++ FiskalyClientVbDemo/Program.vb | 13 +++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 FiskalyClientVbDemo/FiskalyClientVbDemo.vbproj create mode 100644 FiskalyClientVbDemo/Program.vb diff --git a/FiskalyClientVbDemo/FiskalyClientVbDemo.vbproj b/FiskalyClientVbDemo/FiskalyClientVbDemo.vbproj new file mode 100644 index 0000000..83657e7 --- /dev/null +++ b/FiskalyClientVbDemo/FiskalyClientVbDemo.vbproj @@ -0,0 +1,18 @@ + + + + + + + + + + + + + Exe + FiskalyClientVbDemo + netcoreapp3.0 + + + diff --git a/FiskalyClientVbDemo/Program.vb b/FiskalyClientVbDemo/Program.vb new file mode 100644 index 0000000..1c32121 --- /dev/null +++ b/FiskalyClientVbDemo/Program.vb @@ -0,0 +1,13 @@ +Imports System +Imports Fiskaly.Client +Imports System.Net.Http +Imports Serilog + +Module Program + Sub Main(args As String()) + Log.Logger = New LoggerConfiguration().WriteTo.Console().CreateLogger() + Dim apiKey as String = Environment.GetEnvironmentVariable("API_KEY") + Dim apiSecret as String = Environment.GetEnvironmentVariable("API_SECRET") + Dim client As HttpClient = ClientFactory.Create(apiKey, apiSecret).AsTask().Result + End Sub +End Module