Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a07907b33c | |||
| e298c2ce51 | |||
| e44a4b4958 | |||
| 2a66b8582d | |||
| 11c313087f | |||
| 443893eadf | |||
| 068af2bdbd |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
|||||||
## Get latest from `dotnet new gitignore`
|
## Get latest from `dotnet new gitignore`
|
||||||
**/python/
|
**/python/
|
||||||
CREDENTIALS*
|
CREDENTIALS*
|
||||||
|
test_data_path/
|
||||||
|
|
||||||
# dotenv files
|
# dotenv files
|
||||||
.env
|
.env
|
||||||
|
|||||||
@@ -5,28 +5,32 @@ using System.Text.Json;
|
|||||||
namespace dopt.DeltaBarth.Tests
|
namespace dopt.DeltaBarth.Tests
|
||||||
{
|
{
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Unicode;
|
||||||
|
|
||||||
internal class TestPlugin : DeltaBarth.Plugin
|
internal class TestPlugin : DeltaBarth.Plugin
|
||||||
{
|
{
|
||||||
internal dynamic pyModJsonStructs;
|
internal dynamic pyModJsonData;
|
||||||
private const string absPath = @"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth";
|
private const string absPath = @"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth";
|
||||||
internal TestPlugin() : base(absPath) {
|
internal TestPlugin() : base(absPath) {
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyModJsonStructs = Py.Import("delta_barth._csharp.json_types");
|
pyModJsonData = Py.Import("delta_barth._csharp.json_types");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class JsonStructsTest
|
public class DataObjectsTest
|
||||||
{
|
{
|
||||||
static void PrettyPrint(object toSerialise)
|
static void PrettyPrint(object toSerialise)
|
||||||
{
|
{
|
||||||
string prettyJson = JsonSerializer.Serialize(toSerialise, new JsonSerializerOptions
|
string prettyJson = JsonSerializer.Serialize(toSerialise, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
});
|
});
|
||||||
Console.WriteLine($"Parsed struct is: {prettyJson}");
|
Console.WriteLine($"Parsed data is: {prettyJson}");
|
||||||
}
|
}
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Parse_Error_Status_Test()
|
public void Parse_Error_Status_Test()
|
||||||
@@ -35,11 +39,12 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
string pyJson;
|
string pyJson;
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyJson = (string)plugin.pyModJsonStructs.status_err();
|
pyJson = (string)plugin.pyModJsonData.status_err();
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.Status>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.Status>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
Assert.AreEqual(102, parsed.code);
|
Assert.AreEqual(102, parsed.code);
|
||||||
Assert.AreEqual("internal error occurred", parsed.description);
|
Assert.IsTrue(parsed.description.Contains("internal error occurred"));
|
||||||
Assert.AreEqual("caused by test", parsed.message);
|
Assert.AreEqual("caused by test", parsed.message);
|
||||||
Assert.IsNull(parsed.apiServerError);
|
Assert.IsNull(parsed.apiServerError);
|
||||||
PrettyPrint(parsed);
|
PrettyPrint(parsed);
|
||||||
@@ -52,9 +57,10 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
string pyJson;
|
string pyJson;
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyJson = (string)plugin.pyModJsonStructs.delta_barth_api_error();
|
pyJson = (string)plugin.pyModJsonData.delta_barth_api_error();
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.ApiServerError>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.ApiServerError>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
Assert.AreEqual(401, parsed.status_code);
|
Assert.AreEqual(401, parsed.status_code);
|
||||||
Assert.AreEqual("test message", parsed.message);
|
Assert.AreEqual("test message", parsed.message);
|
||||||
Assert.AreEqual("test code", parsed.code);
|
Assert.AreEqual("test code", parsed.code);
|
||||||
@@ -72,9 +78,10 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
string pyJson;
|
string pyJson;
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyJson = (string)plugin.pyModJsonStructs.api_credentials();
|
pyJson = (string)plugin.pyModJsonData.api_credentials();
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.Credentials>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.Credentials>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
Assert.AreEqual("user", parsed.username);
|
Assert.AreEqual("user", parsed.username);
|
||||||
Assert.AreEqual("pass", parsed.password);
|
Assert.AreEqual("pass", parsed.password);
|
||||||
Assert.AreEqual("test1", parsed.database);
|
Assert.AreEqual("test1", parsed.database);
|
||||||
@@ -89,9 +96,10 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
string pyJson;
|
string pyJson;
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyJson = (string)plugin.pyModJsonStructs.sales_prognosis_result();
|
pyJson = (string)plugin.pyModJsonData.sales_prognosis_result();
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.UmsatzPrognoseEinzelergebnis>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseEinzelergebnis>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
Assert.AreEqual(2023, parsed.jahr);
|
Assert.AreEqual(2023, parsed.jahr);
|
||||||
Assert.AreEqual(12, parsed.monat);
|
Assert.AreEqual(12, parsed.monat);
|
||||||
Assert.AreEqual(3000.3456m, parsed.vorhersage);
|
Assert.AreEqual(3000.3456m, parsed.vorhersage);
|
||||||
@@ -105,14 +113,15 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
string pyJson;
|
string pyJson;
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyJson = (string)plugin.pyModJsonStructs.sales_prognosis_results();
|
pyJson = (string)plugin.pyModJsonData.sales_prognosis_results();
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.UmsatzPrognoseErgebnisse>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseErgebnisse>(pyJson);
|
||||||
|
Assert.IsNotNull(parsed);
|
||||||
Assert.AreEqual(3, parsed.daten.Length);
|
Assert.AreEqual(3, parsed.daten.Length);
|
||||||
var e1 = new JsonStructs.UmsatzPrognoseEinzelergebnis { jahr = 2023, monat = 12, vorhersage = 3000.3456m };
|
var e1 = new DataObjects.UmsatzPrognoseEinzelergebnis { jahr = 2023, monat = 12, vorhersage = 3000.3456m };
|
||||||
var e2 = new JsonStructs.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 1, vorhersage = 3300.685m };
|
var e2 = new DataObjects.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 1, vorhersage = 3300.685m };
|
||||||
var e3 = new JsonStructs.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 2, vorhersage = 3700.548m };
|
var e3 = new DataObjects.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 2, vorhersage = 3700.548m };
|
||||||
ImmutableArray<JsonStructs.UmsatzPrognoseEinzelergebnis> arr = ImmutableArray.Create(e1, e2, e3);
|
ImmutableArray<DataObjects.UmsatzPrognoseEinzelergebnis> arr = ImmutableArray.Create(e1, e2, e3);
|
||||||
|
|
||||||
for (int i = 0; i < parsed.daten.Length; i++)
|
for (int i = 0; i < parsed.daten.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -128,15 +137,16 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
string pyJson;
|
string pyJson;
|
||||||
using (Py.GIL())
|
using (Py.GIL())
|
||||||
{
|
{
|
||||||
pyJson = (string)plugin.pyModJsonStructs.sales_prognosis_results_export();
|
pyJson = (string)plugin.pyModJsonData.sales_prognosis_results_export();
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.UmsatzPrognoseAusgabe>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseAusgabe>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
// result
|
// result
|
||||||
var e1 = new JsonStructs.UmsatzPrognoseEinzelergebnis { jahr = 2023, monat = 12, vorhersage = 3000.3456m };
|
var e1 = new DataObjects.UmsatzPrognoseEinzelergebnis { jahr = 2023, monat = 12, vorhersage = 3000.3456m };
|
||||||
var e2 = new JsonStructs.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 1, vorhersage = 3300.685m };
|
var e2 = new DataObjects.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 1, vorhersage = 3300.685m };
|
||||||
var e3 = new JsonStructs.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 2, vorhersage = 3700.548m };
|
var e3 = new DataObjects.UmsatzPrognoseEinzelergebnis { jahr = 2024, monat = 2, vorhersage = 3700.548m };
|
||||||
ImmutableArray<JsonStructs.UmsatzPrognoseEinzelergebnis> arr = ImmutableArray.Create(e1, e2, e3);
|
ImmutableArray<DataObjects.UmsatzPrognoseEinzelergebnis> arr = ImmutableArray.Create(e1, e2, e3);
|
||||||
var data = new JsonStructs.UmsatzPrognoseErgebnisse { daten = arr };
|
var data = new DataObjects.UmsatzPrognoseErgebnisse { daten = arr };
|
||||||
// check status
|
// check status
|
||||||
Assert.AreEqual(0, parsed.status.code);
|
Assert.AreEqual(0, parsed.status.code);
|
||||||
Assert.AreEqual("Erfolg", parsed.status.description);
|
Assert.AreEqual("Erfolg", parsed.status.description);
|
||||||
@@ -4,6 +4,7 @@ using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext
|
|||||||
|
|
||||||
namespace dopt.DeltaBarth.Tests
|
namespace dopt.DeltaBarth.Tests
|
||||||
{
|
{
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
internal class Config
|
internal class Config
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,7 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
private const string absPath = @"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth";
|
private const string absPath = @"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth";
|
||||||
public TPlugin() : base(absPath) { }
|
public TPlugin() : base(absPath) { }
|
||||||
public new JsonStructs.Credentials GetCredentials()
|
public new DataObjects.Credentials GetCredentials()
|
||||||
{
|
{
|
||||||
return base.GetCredentials();
|
return base.GetCredentials();
|
||||||
}
|
}
|
||||||
@@ -47,15 +48,25 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
return base.GetBaseApiUrl();
|
return base.GetBaseApiUrl();
|
||||||
}
|
}
|
||||||
|
public new string GetDataPath()
|
||||||
|
{
|
||||||
|
return base.GetDataPath();
|
||||||
|
}
|
||||||
|
public new void Setup(string datenPfad, string basisApiUrl)
|
||||||
|
{
|
||||||
|
base.Setup(datenPfad, basisApiUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public sealed class PluginTest
|
public sealed class PluginTest
|
||||||
{
|
{
|
||||||
|
private const string baseDataPath = @"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth\test_data_path";
|
||||||
internal Config config = new Config();
|
internal Config config = new Config();
|
||||||
static void PrettyPrint(object toSerialise)
|
static void PrettyPrint(object toSerialise)
|
||||||
{
|
{
|
||||||
string prettyJson = JsonSerializer.Serialize(toSerialise, new JsonSerializerOptions
|
string prettyJson = JsonSerializer.Serialize(toSerialise, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
});
|
});
|
||||||
Console.WriteLine($"Parsed struct is: {prettyJson}");
|
Console.WriteLine($"Parsed struct is: {prettyJson}");
|
||||||
@@ -81,13 +92,19 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
test.Dispose();
|
test.Dispose();
|
||||||
}
|
}
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Set_and_Obtain_BaseApiUrl_Test()
|
public void SetupSession_Test()
|
||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = "http://10.2.22.21:8080/api/";
|
string apiUrlSet = "http://10.2.22.21:8080/api/";
|
||||||
test.SetzeBasisApiUrl(apiUrlSet);
|
test.Setup(baseDataPath, apiUrlSet);
|
||||||
|
// data path
|
||||||
|
var dataPathGet = test.GetDataPath();
|
||||||
|
Console.WriteLine($"Result for data path from Python session was: {dataPathGet}");
|
||||||
|
bool pathElementsContained = dataPathGet.Contains("test_data_path");
|
||||||
|
Assert.IsTrue(pathElementsContained);
|
||||||
|
// API URL
|
||||||
var apiUrlGet = test.GetBaseApiUrl();
|
var apiUrlGet = test.GetBaseApiUrl();
|
||||||
Console.WriteLine($"Result from Python session was: {apiUrlGet}");
|
Console.WriteLine($"Result for API URL from Python session was: {apiUrlGet}");
|
||||||
Assert.AreEqual(apiUrlSet, apiUrlGet);
|
Assert.AreEqual(apiUrlSet, apiUrlGet);
|
||||||
test.Dispose();
|
test.Dispose();
|
||||||
}
|
}
|
||||||
@@ -96,7 +113,7 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var apiUrlGet = test.GetBaseApiUrl();
|
var apiUrlGet = test.GetBaseApiUrl();
|
||||||
var creds = test.GetCredentials();
|
var creds = test.GetCredentials();
|
||||||
Console.WriteLine($"Result from Python session was: API-URL={apiUrlGet}, creds={creds}");
|
Console.WriteLine($"Result from Python session was: API-URL={apiUrlGet}, creds={creds}");
|
||||||
@@ -113,7 +130,7 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var res = test.UmsatzprognoseDummy(null, null);
|
var res = test.UmsatzprognoseDummy(null, null);
|
||||||
PrettyPrint(res);
|
PrettyPrint(res);
|
||||||
test.Dispose();
|
test.Dispose();
|
||||||
@@ -123,7 +140,7 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var comp_id = 1000;
|
var comp_id = 1000;
|
||||||
var res = test.UmsatzprognoseDummy(comp_id, null);
|
var res = test.UmsatzprognoseDummy(comp_id, null);
|
||||||
PrettyPrint(res);
|
PrettyPrint(res);
|
||||||
@@ -134,22 +151,33 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var date = new DateTime(2023, 1, 1, 12, 45, 30);
|
var date = new DateTime(2023, 1, 1, 12, 45, 30);
|
||||||
var res = test.UmsatzprognoseDummy(null, date);
|
var res = test.UmsatzprognoseDummy(null, date);
|
||||||
PrettyPrint(res);
|
PrettyPrint(res);
|
||||||
test.Dispose();
|
test.Dispose();
|
||||||
}
|
}
|
||||||
|
[TestMethod]
|
||||||
|
public void Umsatzprognose_NoConnectionNeeded_Test()
|
||||||
|
{
|
||||||
|
var test = new TPlugin();
|
||||||
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
||||||
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
|
var date = new DateTime(2030, 1, 1, 12, 45, 30);
|
||||||
|
var res = test.Umsatzprognose(null, date);
|
||||||
|
PrettyPrint(res);
|
||||||
|
test.Dispose();
|
||||||
|
}
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[TestCategory("ActiveAPI")]
|
[TestCategory("ActiveAPI")]
|
||||||
public void Umsatzprognose_WithCompanyIdWithoutDate_Test()
|
public void Umsatzprognose_WithCompanyIdWithoutDate_Test()
|
||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var comp_id = 1024;
|
var comp_id = 1024;
|
||||||
var res = test.Umsatzprognose(comp_id, null);
|
var res = test.Umsatzprognose(comp_id, null);
|
||||||
|
Assert.AreEqual(4, res.status.code);
|
||||||
PrettyPrint(res);
|
PrettyPrint(res);
|
||||||
test.Dispose();
|
test.Dispose();
|
||||||
}
|
}
|
||||||
@@ -159,9 +187,10 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var date = new DateTime(2030, 1, 1, 12, 45, 30);
|
var date = new DateTime(2030, 1, 1, 12, 45, 30);
|
||||||
var res = test.Umsatzprognose(null, date);
|
var res = test.Umsatzprognose(null, date);
|
||||||
|
Assert.AreEqual(3, res.status.code);
|
||||||
PrettyPrint(res);
|
PrettyPrint(res);
|
||||||
test.Dispose();
|
test.Dispose();
|
||||||
}
|
}
|
||||||
@@ -171,9 +200,10 @@ namespace dopt.DeltaBarth.Tests
|
|||||||
{
|
{
|
||||||
var test = new TPlugin();
|
var test = new TPlugin();
|
||||||
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
||||||
test.Startup(apiUrlSet, user, password, database, mandant);
|
test.Startup(baseDataPath, apiUrlSet, user, password, database, mandant);
|
||||||
var date = new DateTime(2015, 1, 1, 12, 45, 30);
|
var date = new DateTime(2015, 1, 1, 12, 45, 30);
|
||||||
var res = test.Umsatzprognose(null, date);
|
var res = test.Umsatzprognose(null, date);
|
||||||
|
Assert.AreEqual(4, res.status.code);
|
||||||
PrettyPrint(res);
|
PrettyPrint(res);
|
||||||
test.Dispose();
|
test.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
50
dopt.DeltaBarth/DataObjects.cs
Normal file
50
dopt.DeltaBarth/DataObjects.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
|
namespace dopt.DeltaBarth.DataObjects
|
||||||
|
{
|
||||||
|
public record class ApiServerError
|
||||||
|
{
|
||||||
|
public required int status_code { get; init; }
|
||||||
|
public required string message { get; init; }
|
||||||
|
public string? code { get; init; }
|
||||||
|
public string? hints { get; init; }
|
||||||
|
public string? type { get; init; }
|
||||||
|
public string? title { get; init; }
|
||||||
|
public string? traceId { get; init; }
|
||||||
|
}
|
||||||
|
public record class Status
|
||||||
|
{
|
||||||
|
public required int code { get; init; }
|
||||||
|
public required string description { get; init; }
|
||||||
|
public required string message { get; init; }
|
||||||
|
public ApiServerError? apiServerError { get; init; }
|
||||||
|
|
||||||
|
}
|
||||||
|
public record class Credentials
|
||||||
|
{
|
||||||
|
public required string username { get; init; }
|
||||||
|
public required string password { get; init; }
|
||||||
|
public required string database { get; init; }
|
||||||
|
public required string mandant { get; init; }
|
||||||
|
}
|
||||||
|
public record class UmsatzPrognoseEinzelergebnis
|
||||||
|
{
|
||||||
|
public required int jahr { get; init; }
|
||||||
|
public required int monat { get; init; }
|
||||||
|
public required decimal vorhersage { get; init; }
|
||||||
|
}
|
||||||
|
public record class UmsatzPrognoseErgebnisse
|
||||||
|
{
|
||||||
|
public required ImmutableArray<UmsatzPrognoseEinzelergebnis> daten { get; init; }
|
||||||
|
}
|
||||||
|
public record class UmsatzPrognoseAusgabe
|
||||||
|
{
|
||||||
|
public required UmsatzPrognoseErgebnisse response { get; init; }
|
||||||
|
public required Status status { get; init; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Collections.Immutable;
|
|
||||||
|
|
||||||
namespace dopt.DeltaBarth.JsonStructs
|
|
||||||
{
|
|
||||||
public readonly struct ApiServerError
|
|
||||||
{
|
|
||||||
public int status_code { get; init; }
|
|
||||||
public string message { get; init; }
|
|
||||||
public string? code { get; init; }
|
|
||||||
public string? hints { get; init; }
|
|
||||||
public string? type { get; init; }
|
|
||||||
public string? title { get; init; }
|
|
||||||
public string? traceId { get; init; }
|
|
||||||
}
|
|
||||||
public readonly struct Status
|
|
||||||
{
|
|
||||||
public int code { get; init; }
|
|
||||||
public string description { get; init; }
|
|
||||||
public string message { get; init; }
|
|
||||||
public ApiServerError? apiServerError { get; init; }
|
|
||||||
|
|
||||||
}
|
|
||||||
public readonly struct Credentials
|
|
||||||
{
|
|
||||||
public string username { get; init; }
|
|
||||||
public string password { get; init; }
|
|
||||||
public string database { get; init; }
|
|
||||||
public string mandant { get; init; }
|
|
||||||
}
|
|
||||||
public readonly struct UmsatzPrognoseEinzelergebnis
|
|
||||||
{
|
|
||||||
public int jahr { get; init; }
|
|
||||||
public int monat { get; init; }
|
|
||||||
public decimal vorhersage { get; init; }
|
|
||||||
}
|
|
||||||
public readonly struct UmsatzPrognoseErgebnisse
|
|
||||||
{
|
|
||||||
public ImmutableArray<UmsatzPrognoseEinzelergebnis> daten { get; init; }
|
|
||||||
}
|
|
||||||
public readonly struct UmsatzPrognoseAusgabe
|
|
||||||
{
|
|
||||||
public UmsatzPrognoseErgebnisse response { get; init; }
|
|
||||||
public Status status { get; init; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,11 @@ using System.Text.Json;
|
|||||||
|
|
||||||
namespace dopt.DeltaBarth
|
namespace dopt.DeltaBarth
|
||||||
{
|
{
|
||||||
|
public class PythonParsingException : Exception
|
||||||
|
{
|
||||||
|
public PythonParsingException() { }
|
||||||
|
public PythonParsingException(string message) : base(message) { }
|
||||||
|
}
|
||||||
public class Plugin : SharpPython.BasePlugin
|
public class Plugin : SharpPython.BasePlugin
|
||||||
{
|
{
|
||||||
protected dynamic pyModManagement;
|
protected dynamic pyModManagement;
|
||||||
@@ -16,17 +21,12 @@ namespace dopt.DeltaBarth
|
|||||||
pyModPipeline = Py.Import("delta_barth.pipelines");
|
pyModPipeline = Py.Import("delta_barth.pipelines");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Startup(string basisApiUrl, string nutzername, string passwort, string datenbank, string mandant)
|
public void Startup(string datenPfad, string basisApiUrl, string nutzername, string passwort, string datenbank, string mandant)
|
||||||
{
|
{
|
||||||
AssertNotDisposed();
|
AssertNotDisposed();
|
||||||
SetzeBasisApiUrl(basisApiUrl);
|
Setup(datenPfad, basisApiUrl);
|
||||||
SetzeNutzerdaten(nutzername, passwort, datenbank, mandant);
|
SetzeNutzerdaten(nutzername, passwort, datenbank, mandant);
|
||||||
}
|
}
|
||||||
public void SetzeBasisApiUrl(string basisApiUrl)
|
|
||||||
{
|
|
||||||
AssertNotDisposed();
|
|
||||||
pyModManagement.set_base_url(basisApiUrl);
|
|
||||||
}
|
|
||||||
public void SetzeNutzerdaten(string nutzername, string passwort, string datenbank, string mandant)
|
public void SetzeNutzerdaten(string nutzername, string passwort, string datenbank, string mandant)
|
||||||
{
|
{
|
||||||
AssertNotDisposed();
|
AssertNotDisposed();
|
||||||
@@ -34,7 +34,7 @@ namespace dopt.DeltaBarth
|
|||||||
pyModManagement.set_credentials(nutzername, passwort, datenbank, mandant);
|
pyModManagement.set_credentials(nutzername, passwort, datenbank, mandant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public JsonStructs.UmsatzPrognoseAusgabe UmsatzprognoseDummy(int? firmaId, DateTime? buchungsDatum)
|
public DataObjects.UmsatzPrognoseAusgabe UmsatzprognoseDummy(int? firmaId, DateTime? buchungsDatum)
|
||||||
{
|
{
|
||||||
AssertNotDisposed();
|
AssertNotDisposed();
|
||||||
string pyJson;
|
string pyJson;
|
||||||
@@ -42,11 +42,12 @@ namespace dopt.DeltaBarth
|
|||||||
{
|
{
|
||||||
pyJson = pyModPipeline.pipeline_sales_forecast_dummy(firmaId, buchungsDatum);
|
pyJson = pyModPipeline.pipeline_sales_forecast_dummy(firmaId, buchungsDatum);
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.UmsatzPrognoseAusgabe>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseAusgabe>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
public JsonStructs.UmsatzPrognoseAusgabe Umsatzprognose(int? firmaId, DateTime? buchungsDatum)
|
public DataObjects.UmsatzPrognoseAusgabe Umsatzprognose(int? firmaId, DateTime? buchungsDatum)
|
||||||
{
|
{
|
||||||
AssertNotDisposed();
|
AssertNotDisposed();
|
||||||
string pyJson;
|
string pyJson;
|
||||||
@@ -54,10 +55,19 @@ namespace dopt.DeltaBarth
|
|||||||
{
|
{
|
||||||
pyJson = pyModPipeline.pipeline_sales_forecast(firmaId, buchungsDatum);
|
pyJson = pyModPipeline.pipeline_sales_forecast(firmaId, buchungsDatum);
|
||||||
}
|
}
|
||||||
var parsed = JsonSerializer.Deserialize<JsonStructs.UmsatzPrognoseAusgabe>(pyJson);
|
var parsed = JsonSerializer.Deserialize<DataObjects.UmsatzPrognoseAusgabe>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
protected void Setup(string datenPfad, string basisApiUrl)
|
||||||
|
{
|
||||||
|
AssertNotDisposed();
|
||||||
|
using (Py.GIL())
|
||||||
|
{
|
||||||
|
pyModManagement.setup(datenPfad, basisApiUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
protected string GetBaseApiUrl()
|
protected string GetBaseApiUrl()
|
||||||
{
|
{
|
||||||
AssertNotDisposed();
|
AssertNotDisposed();
|
||||||
@@ -68,7 +78,17 @@ namespace dopt.DeltaBarth
|
|||||||
}
|
}
|
||||||
return pyJson;
|
return pyJson;
|
||||||
}
|
}
|
||||||
protected JsonStructs.Credentials GetCredentials()
|
protected string GetDataPath()
|
||||||
|
{
|
||||||
|
AssertNotDisposed();
|
||||||
|
string pyJson;
|
||||||
|
using (Py.GIL())
|
||||||
|
{
|
||||||
|
pyJson = (string)pyModManagement.get_data_path();
|
||||||
|
}
|
||||||
|
return pyJson;
|
||||||
|
}
|
||||||
|
protected DataObjects.Credentials GetCredentials()
|
||||||
{
|
{
|
||||||
AssertNotDisposed();
|
AssertNotDisposed();
|
||||||
string pyJson;
|
string pyJson;
|
||||||
@@ -77,9 +97,10 @@ namespace dopt.DeltaBarth
|
|||||||
pyJson = (string)pyModManagement.get_credentials();
|
pyJson = (string)pyModManagement.get_credentials();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonStructs.Credentials credentials = JsonSerializer.Deserialize<JsonStructs.Credentials>(pyJson);
|
DataObjects.Credentials? parsed = JsonSerializer.Deserialize<DataObjects.Credentials>(pyJson);
|
||||||
|
if (parsed == null) { throw new PythonParsingException("Could not correctly parse object from Python"); }
|
||||||
|
|
||||||
return credentials;
|
return parsed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
<Version>0.2.0</Version>
|
<Version>0.3.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user