Tests: Move tests into package
This commit is contained in:
30
Tests/Helpers/BillingTest.cs
Normal file
30
Tests/Helpers/BillingTest.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Elwig.Helpers;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
[TestFixture]
|
||||
public class BillingTest {
|
||||
|
||||
private SqliteConnection? Connection;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public async Task SetupDatabase() {
|
||||
Connection = await AppDbContext.ConnectAsync();
|
||||
await AppDbContext.ExecuteEmbeddedScript(Connection, Assembly.GetExecutingAssembly(), "Tests.Resources.BillingInsert.sql");
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public async Task TeardownDatabase() {
|
||||
if (Connection == null) return;
|
||||
await AppDbContext.ExecuteEmbeddedScript(Connection, Assembly.GetExecutingAssembly(), "Tests.Resources.BillingDelete.sql");
|
||||
await Connection.DisposeAsync();
|
||||
Connection = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
104
Tests/Helpers/UtilsTest.cs
Normal file
104
Tests/Helpers/UtilsTest.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using Elwig.Helpers;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
[TestFixture]
|
||||
public class UtilsTest {
|
||||
|
||||
private static readonly double[,] Gradation = new double[,] {
|
||||
{ 14.0, 68.0 },
|
||||
{ 15.0, 73.0 },
|
||||
{ 17.1, 84.0 },
|
||||
{ 19.0, 94.0 },
|
||||
{ 21.0, 105.0 },
|
||||
{ 25.0, 127.0 },
|
||||
{ 27.1, 139.0 },
|
||||
{ 30.0, 156.0 },
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void Test_KmwToOe() {
|
||||
Assert.Multiple(() => {
|
||||
for (int i = 0; i < Gradation.GetLength(0); i++) {
|
||||
Assert.That(Utils.KmwToOe(Gradation[i, 0]), Is.EqualTo(Gradation[i, 1]));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_OeToKmw() {
|
||||
Assert.Multiple(() => {
|
||||
for (int i = 0; i < Gradation.GetLength(0); i++) {
|
||||
Assert.That(Utils.OeToKmw(Gradation[i, 1]), Is.EqualTo(Gradation[i, 0]));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_DecFromDb() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Utils.DecFromDb(10670, 3), Is.EqualTo(10.67M));
|
||||
Assert.That(Utils.DecFromDb(-1009999, 4), Is.EqualTo(-100.9999M));
|
||||
Assert.That(Utils.DecFromDb(1, 2), Is.EqualTo(0.01M));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_DecToDb() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Utils.DecToDb(219.48M, 2), Is.EqualTo(21948));
|
||||
Assert.That(Utils.DecToDb(-1.2345M, 4), Is.EqualTo(-12345));
|
||||
Assert.That(Utils.DecToDb(99190, 0), Is.EqualTo(99190));
|
||||
Assert.That(Utils.DecToDb(817.9099M, 3), Is.EqualTo(817910));
|
||||
Assert.That(Utils.DecToDb(-5618.944M, 2), Is.EqualTo(-561894));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_Modulo() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Utils.Modulo("1", 2), Is.EqualTo(1));
|
||||
Assert.That(Utils.Modulo("12", 11), Is.EqualTo(1));
|
||||
Assert.That(Utils.Modulo("65", 16), Is.EqualTo(1));
|
||||
Assert.That(Utils.Modulo("91746381048364", 10), Is.EqualTo(4));
|
||||
Assert.That(Utils.Modulo("210501700012345678131468", 97), Is.EqualTo(1));
|
||||
Assert.Throws<ArgumentException>(() => Utils.Modulo("", 4));
|
||||
Assert.Throws<ArgumentException>(() => Utils.Modulo("1ab", 5));
|
||||
Assert.Throws<ArgumentException>(() => Utils.Modulo("123", 1));
|
||||
Assert.Throws<ArgumentException>(() => Utils.Modulo("456", 0));
|
||||
Assert.Throws<ArgumentException>(() => Utils.Modulo("789", -1));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SplitAddress() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 1"), Is.EqualTo(("Winzerstraße", "1")));
|
||||
Assert.That(Utils.SplitAddress("Auf dem Feld 12"), Is.EqualTo(("Auf dem Feld", "12")));
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 5a"), Is.EqualTo(("Winzerstraße", "5a")));
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 1-3/2"), Is.EqualTo(("Winzerstraße", "1-3/2")));
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 3/4/5"), Is.EqualTo(("Winzerstraße", "3/4/5")));
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 7/2/4/77"), Is.EqualTo(("Winzerstraße", "7/2/4/77")));
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 95b"), Is.EqualTo(("Winzerstraße", "95b")));
|
||||
Assert.That(Utils.SplitAddress("Winzerstraße 1, TOP 3"), Is.EqualTo(("Winzerstraße", "1, TOP 3")));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SplitName() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Utils.SplitName("Max Bauer", "Bauer"), Is.EqualTo(("Bauer", "Max")));
|
||||
Assert.That(Utils.SplitName("Bauer Max", "Bauer"), Is.EqualTo(("Bauer", "Max")));
|
||||
Assert.That(Utils.SplitName("Max und Moritz Bauer", "Bauer"), Is.EqualTo(("Bauer", "Max und Moritz")));
|
||||
Assert.That(Utils.SplitName("Bauer Max und Moritz", "Bauer"), Is.EqualTo(("Bauer", "Max und Moritz")));
|
||||
Assert.That(Utils.SplitName("Bauer GesbR", "Bauer"), Is.EqualTo(("Bauer", "GesbR")));
|
||||
Assert.That(Utils.SplitName("Max und Moritz Bauer GesbR", "Bauer"), Is.EqualTo(("Bauer", "Max und Moritz GesbR")));
|
||||
Assert.That(Utils.SplitName("Bauer Max und Moritz GesbR", "Bauer"), Is.EqualTo(("Bauer", "Max und Moritz GesbR")));
|
||||
Assert.That(Utils.SplitName("Weingut Bauer", "Bauer"), Is.EqualTo(("Bauer", "Weingut")));
|
||||
Assert.That(Utils.SplitName("Bauer Weingut", "Bauer"), Is.EqualTo(("Bauer", "Weingut")));
|
||||
Assert.That(Utils.SplitName("Max und Moritz Bauer und Mustermann", "Bauer"), Is.EqualTo(("Bauer und Mustermann", "Max und Moritz")));
|
||||
Assert.That(Utils.SplitName("Bauer und Mustermann Max und Moritz", "Bauer"), Is.EqualTo(("Bauer und Mustermann", "Max und Moritz")));
|
||||
Assert.That(Utils.SplitName("ABC GesbR", "Bauer"), Is.EqualTo(((string, string?))("ABC GesbR", null)));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
113
Tests/Helpers/ValidatorTest.cs
Normal file
113
Tests/Helpers/ValidatorTest.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using Elwig.Helpers;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Tests.Helpers {
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
public class ValidatorTest {
|
||||
|
||||
private static TextBox TB(string value, int caret = 0) {
|
||||
return new() {
|
||||
Text = value,
|
||||
CaretIndex = caret,
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckInteger_Simple() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckInteger(TB(""), true).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckInteger(TB(""), false).IsValid, Is.True);
|
||||
Assert.That(Validator.CheckInteger(TB("123"), true).IsValid, Is.True);
|
||||
Assert.That(Validator.CheckInteger(TB("456"), false).IsValid, Is.True);
|
||||
Assert.That(Validator.CheckInteger(TB("1234"), false, 4).IsValid, Is.True);
|
||||
Assert.That(Validator.CheckInteger(TB("4567"), false, 3).IsValid, Is.True);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckInteger_Caret() {
|
||||
var tb = TB("1a2b3c", 2);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckInteger(tb, true).IsValid, Is.True);
|
||||
Assert.That(tb.Text, Is.EqualTo("123"));
|
||||
Assert.That(tb.CaretIndex, Is.EqualTo(1));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckInteger_MaxLen() {
|
||||
var tb = TB("1a2b3c4d5e", 4);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckInteger(tb, true, 3).IsValid, Is.True);
|
||||
Assert.That(tb.Text, Is.EqualTo("123"));
|
||||
Assert.That(tb.CaretIndex, Is.EqualTo(2));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckPhoneNumber_Simple() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckPhoneNumber(TB(""), true).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckPhoneNumber(TB("+43"), false).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckPhoneNumber(TB("066412345678"), true).IsValid, Is.True);
|
||||
Assert.That(Validator.CheckPhoneNumber(TB("0ab66412cd345678"), true).IsValid, Is.True);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckPhoneNumber_Format_1() {
|
||||
var tb = TB("066412345678", 5);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckPhoneNumber(tb, true).IsValid, Is.True);
|
||||
Assert.That(tb.Text, Is.EqualTo("+43 664 12345678"));
|
||||
Assert.That(tb.CaretIndex, Is.EqualTo(9));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckPhoneNumber_Format_2() {
|
||||
var tb = TB("0a2574b1c2d34..", 7);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckPhoneNumber(tb, true).IsValid, Is.True);
|
||||
Assert.That(tb.Text, Is.EqualTo("+43 2574 1234"));
|
||||
Assert.That(tb.CaretIndex, Is.EqualTo(8));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckEmailAddress_Simple() {
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckEmailAddress(TB(""), true).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("name"), false).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("@"), false).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("@test.com"), false).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("name@a"), true).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("name@a.com."), true).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("name@a.com.a"), true).IsValid, Is.False);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("name@a.com"), true).IsValid, Is.True);
|
||||
Assert.That(Validator.CheckEmailAddress(TB("my.name@hello#.com"), true).IsValid, Is.True);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckEmailAddress_Format_1() {
|
||||
var tb = TB("my . name . is @heinz#.com", 17);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckEmailAddress(tb, true).IsValid, Is.True);
|
||||
Assert.That(tb.Text, Is.EqualTo("my.name.is@heinz.com"));
|
||||
Assert.That(tb.CaretIndex, Is.EqualTo(12));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_CheckEmailAddress_Format_2() {
|
||||
var tb = TB("sabine.müsterfrau@heinz#.com.b", 30);
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(Validator.CheckEmailAddress(tb, true).IsValid, Is.False);
|
||||
Assert.That(tb.Text, Is.EqualTo("sabine.müsterfrau@heinz.com.b"));
|
||||
Assert.That(tb.CaretIndex, Is.EqualTo(29));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user