using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Python.Runtime; using System.Text.Json; using DeltaBarth = dopt.DeltaBarth; using dopt.DeltaBarth.JsonStructs; namespace dopt.DeltaBarth.Tests { internal class TestPlugin : DeltaBarth.Plugin { internal dynamic pyModJsonStructs; internal TestPlugin() : base() { using (Py.GIL()) { pyModJsonStructs = Py.Import("delta_barth._csharp.json_types"); } } } [TestClass] public class JsonStructsTest { static void PrettyPrint(object toSerialise) { string prettyJson = JsonSerializer.Serialize(toSerialise, new JsonSerializerOptions { WriteIndented = true }); Console.WriteLine($"Parsed struct is: {prettyJson}"); } [TestMethod] public void Parse_Error_Status_Test() { var plugin = new TestPlugin(); string pyJson; using (Py.GIL()) { pyJson = (string)plugin.pyModJsonStructs.status_err(); } var parsed = JsonSerializer.Deserialize(pyJson); PrettyPrint(parsed); plugin.Shutdown(); } [TestMethod] public void Parse_ApiError_Test() { var plugin = new TestPlugin(); string pyJson; using (Py.GIL()) { pyJson = (string)plugin.pyModJsonStructs.delta_barth_api_error(); } var parsed = JsonSerializer.Deserialize(pyJson); PrettyPrint(parsed); plugin.Shutdown(); } [TestMethod] public void Parse_SalesPrognosisResult_Test() { var plugin = new TestPlugin(); string pyJson; using (Py.GIL()) { pyJson = (string)plugin.pyModJsonStructs.sales_prognosis_result(); } var parsed = JsonSerializer.Deserialize(pyJson); PrettyPrint(parsed); plugin.Shutdown(); } [TestMethod] public void Parse_SalesPrognosisResults_Test() { var plugin = new TestPlugin(); string pyJson; using (Py.GIL()) { pyJson = (string)plugin.pyModJsonStructs.sales_prognosis_results(); } var parsed = JsonSerializer.Deserialize(pyJson); PrettyPrint(parsed); plugin.Shutdown(); } [TestMethod] public void Parse_SalesPrognosisExport_Test() { var plugin = new TestPlugin(); string pyJson; using (Py.GIL()) { pyJson = (string)plugin.pyModJsonStructs.sales_prognosis_results_export(); } var parsed = JsonSerializer.Deserialize(pyJson); PrettyPrint(parsed); plugin.Shutdown(); } } }