Using NUnit instead of MSTest

This commit is contained in:
2023-04-26 22:14:39 +02:00
parent d6059e724b
commit 6acdbee154
6 changed files with 52 additions and 25 deletions

View File

@ -1,7 +1,7 @@
using Elwig.Helpers;
namespace Tests {
[TestClass]
[TestFixture]
public class HelpersUtilsTest {
private static readonly double[,] Gradation = new double[,] {
@ -15,28 +15,28 @@ namespace Tests {
{ 30.0, 156.0 },
};
[TestMethod]
[Test]
public void Test_KmwToOe() {
for (int i = 0; i < Gradation.GetLength(0); i++) {
Assert.AreEqual(Gradation[i, 1], Utils.KmwToOe(Gradation[i, 0]));
}
}
[TestMethod]
[Test]
public void Test_OeToKmw() {
for (int i = 0; i < Gradation.GetLength(0); i++) {
Assert.AreEqual(Gradation[i, 0], Utils.OeToKmw(Gradation[i, 1]));
}
}
[TestMethod]
[Test]
public void Test_DecFromDb() {
Assert.AreEqual(10.67M, Utils.DecFromDb(10670, 3));
Assert.AreEqual(-100.9999M, Utils.DecFromDb(-1009999, 4));
Assert.AreEqual(0.01M, Utils.DecFromDb(1, 2));
}
[TestMethod]
[Test]
public void Test_DecToDb() {
Assert.AreEqual(21948, Utils.DecToDb(219.48M, 2));
Assert.AreEqual(-12345, Utils.DecToDb(-1.2345M, 4));
@ -45,18 +45,18 @@ namespace Tests {
Assert.AreEqual(-561894, Utils.DecToDb(-5618.944M, 2));
}
[TestMethod]
[Test]
public void Test_Modulo() {
Assert.AreEqual(1, Utils.Modulo("1", 2));
Assert.AreEqual(1, Utils.Modulo("12", 11));
Assert.AreEqual(1, Utils.Modulo("65", 16));
Assert.AreEqual(4, Utils.Modulo("91746381048364", 10));
Assert.AreEqual(1, Utils.Modulo("210501700012345678131468", 97));
Assert.ThrowsException<ArgumentException>(() => Utils.Modulo("", 4));
Assert.ThrowsException<ArgumentException>(() => Utils.Modulo("1ab", 5));
Assert.ThrowsException<ArgumentException>(() => Utils.Modulo("123", 1));
Assert.ThrowsException<ArgumentException>(() => Utils.Modulo("456", 0));
Assert.ThrowsException<ArgumentException>(() => Utils.Modulo("789", -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));
}
}
}

View File

@ -0,0 +1,26 @@
using Elwig.Helpers;
using System.Windows.Controls;
namespace Tests {
[TestFixture]
[Apartment(ApartmentState.STA)]
public class HelpersValidatorTest {
private static TextBox CreateTextBox(string value, int caret = 0) {
return new() {
Text = value,
CaretIndex = caret,
};
}
[Test]
public void Test_CheckInteger_Simple() {
Assert.IsFalse(Validator.CheckInteger(CreateTextBox(""), true).IsValid);
Assert.IsTrue(Validator.CheckInteger(CreateTextBox(""), false).IsValid);
Assert.IsTrue(Validator.CheckInteger(CreateTextBox("123"), true).IsValid);
Assert.IsTrue(Validator.CheckInteger(CreateTextBox("456"), false).IsValid);
Assert.IsTrue(Validator.CheckInteger(CreateTextBox("1234"), false, 4).IsValid);
Assert.IsTrue(Validator.CheckInteger(CreateTextBox("4567"), false, 3).IsValid);
}
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
@ -11,8 +11,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

View File

@ -1 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
global using NUnit.Framework;