186 lines
7.4 KiB
C#
186 lines
7.4 KiB
C#
using System.Text.Json;
|
|
using dopt.DeltaBarth;
|
|
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
|
|
|
|
namespace dopt.DeltaBarth.Tests
|
|
{
|
|
using Microsoft.Extensions.Configuration;
|
|
internal class Config
|
|
{
|
|
public string apiUrl;
|
|
public string username;
|
|
public string password;
|
|
public string database;
|
|
public string mandant;
|
|
|
|
public Config() {
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
.AddJsonFile("CREDENTIALS.json", optional: false, reloadOnChange: true)
|
|
.Build();
|
|
var v = config["delta-barth-server:api:base_url"];
|
|
Assert.IsNotNull(v);
|
|
apiUrl = v;
|
|
v = config["delta-barth-server:api:user"];
|
|
Assert.IsNotNull(v);
|
|
username = v;
|
|
v = config["delta-barth-server:api:pwd"];
|
|
Assert.IsNotNull(v);
|
|
password = v;
|
|
v = config["delta-barth-server:api:db"];
|
|
Assert.IsNotNull(v);
|
|
database = v;
|
|
v = config["delta-barth-server:api:mandant"];
|
|
Assert.IsNotNull(v);
|
|
mandant = v;
|
|
}
|
|
}
|
|
public class TPlugin : DeltaBarth.Plugin
|
|
{
|
|
private const string absPath = @"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth";
|
|
public TPlugin() : base(absPath) { }
|
|
public new DataObjects.Credentials GetCredentials()
|
|
{
|
|
return base.GetCredentials();
|
|
}
|
|
public new string GetBaseApiUrl()
|
|
{
|
|
return base.GetBaseApiUrl();
|
|
}
|
|
new public void SetzeBasisApiUrl(string basisApiUrl)
|
|
{
|
|
base.SetzeBasisApiUrl(basisApiUrl);
|
|
}
|
|
}
|
|
[TestClass]
|
|
public sealed class PluginTest
|
|
{
|
|
internal Config config = new Config();
|
|
static void PrettyPrint(object toSerialise)
|
|
{
|
|
string prettyJson = JsonSerializer.Serialize(toSerialise, new JsonSerializerOptions
|
|
{
|
|
WriteIndented = true
|
|
});
|
|
Console.WriteLine($"Parsed struct is: {prettyJson}");
|
|
}
|
|
[TestMethod]
|
|
public void ConstructInitialiseFinalise_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
public void Set_and_Obtain_Credentials_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
|
test.SetzeNutzerdaten(user, password, database, mandant);
|
|
var creds = test.GetCredentials();
|
|
PrettyPrint(creds);
|
|
Assert.AreEqual(user, creds.username);
|
|
Assert.AreEqual(password, creds.password);
|
|
Assert.AreEqual(database, creds.database);
|
|
Assert.AreEqual(mandant, creds.mandant);
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
public void Set_and_Obtain_BaseApiUrl_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = "http://10.2.22.21:8080/api/";
|
|
test.SetzeBasisApiUrl(apiUrlSet);
|
|
var apiUrlGet = test.GetBaseApiUrl();
|
|
Console.WriteLine($"Result from Python session was: {apiUrlGet}");
|
|
Assert.AreEqual(apiUrlSet, apiUrlGet);
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
public void Startup_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
|
test.Startup(apiUrlSet, user, password, database, mandant);
|
|
var apiUrlGet = test.GetBaseApiUrl();
|
|
var creds = test.GetCredentials();
|
|
Console.WriteLine($"Result from Python session was: API-URL={apiUrlGet}, creds={creds}");
|
|
PrettyPrint(creds);
|
|
Assert.AreEqual(apiUrlSet, apiUrlGet);
|
|
Assert.AreEqual(user, creds.username);
|
|
Assert.AreEqual(password, creds.password);
|
|
Assert.AreEqual(database, creds.database);
|
|
Assert.AreEqual(mandant, creds.mandant);
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
public void UmsatzprognoseDummy_WithoutParams_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
|
test.Startup(apiUrlSet, user, password, database, mandant);
|
|
var res = test.UmsatzprognoseDummy(null, null);
|
|
PrettyPrint(res);
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
public void UmsatzprognoseDummy_WithCompanyIdWithoutDate_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
|
test.Startup(apiUrlSet, user, password, database, mandant);
|
|
var comp_id = 1000;
|
|
var res = test.UmsatzprognoseDummy(comp_id, null);
|
|
PrettyPrint(res);
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
public void UmsatzprognoseDummy_WithoutCompanyIdWithDate_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = "http://10.2.22.21:8080/api/", user = "user", password = "password", database = "DB1", mandant = "mandant1";
|
|
test.Startup(apiUrlSet, user, password, database, mandant);
|
|
var date = new DateTime(2023, 1, 1, 12, 45, 30);
|
|
var res = test.UmsatzprognoseDummy(null, date);
|
|
PrettyPrint(res);
|
|
test.Dispose();
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory("ActiveAPI")]
|
|
public void Umsatzprognose_WithCompanyIdWithoutDate_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
|
test.Startup(apiUrlSet, user, password, database, mandant);
|
|
var comp_id = 1024;
|
|
var res = test.Umsatzprognose(comp_id, null);
|
|
PrettyPrint(res);
|
|
test.Dispose();
|
|
}
|
|
[TestMethod]
|
|
[TestCategory("ActiveAPI")]
|
|
public void Umsatzprognose_WithoutCompanyIdWithInvalidDate_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
|
test.Startup(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]
|
|
[TestCategory("ActiveAPI")]
|
|
public void Umsatzprognose_WithoutCompanyIdWithValidDate_Test()
|
|
{
|
|
var test = new TPlugin();
|
|
string apiUrlSet = config.apiUrl, user = config.username, password = config.password, database = config.database, mandant = config.mandant;
|
|
test.Startup(apiUrlSet, user, password, database, mandant);
|
|
var date = new DateTime(2015, 1, 1, 12, 45, 30);
|
|
var res = test.Umsatzprognose(null, date);
|
|
PrettyPrint(res);
|
|
test.Dispose();
|
|
}
|
|
}
|
|
}
|