Test frameworks consolidated (#12672)

This commit is contained in:
Davide Giacometti
2021-08-16 15:25:06 +02:00
committed by GitHub
parent c3a51f9227
commit e96c0da265
53 changed files with 1018 additions and 924 deletions

View File

@@ -21,9 +21,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -3,55 +3,60 @@
// See the LICENSE file in the project root for more information.
using System.Globalization;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wox.Plugin;
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
{
[TestFixture]
[TestClass]
public class InputInterpreterTests
{
[TestCase(new string[] { "1,5'" }, new string[] { "1,5", "'" })]
[TestCase(new string[] { "1.5'" }, new string[] { "1.5", "'" })]
[TestCase(new string[] { "1'" }, new string[] { "1", "'" })]
[TestCase(new string[] { "1'5\"" }, new string[] { "1", "'", "5", "\"" })]
[TestCase(new string[] { "5\"" }, new string[] { "5", "\"" })]
[TestCase(new string[] { "1'5" }, new string[] { "1", "'", "5" })]
[DataTestMethod]
[DataRow(new string[] { "1,5'" }, new object[] { new string[] { "1,5", "'" } })]
[DataRow(new string[] { "1.5'" }, new object[] { new string[] { "1.5", "'" } })]
[DataRow(new string[] { "1'" }, new object[] { new string[] { "1", "'" } })]
[DataRow(new string[] { "1'5\"" }, new object[] { new string[] { "1", "'", "5", "\"" } })]
[DataRow(new string[] { "5\"" }, new object[] { new string[] { "5", "\"" } })]
[DataRow(new string[] { "1'5" }, new object[] { new string[] { "1", "'", "5" } })]
public void RegexSplitsInput(string[] input, string[] expectedResult)
{
string[] shortsplit = InputInterpreter.RegexSplitter(input);
Assert.AreEqual(expectedResult, shortsplit);
CollectionAssert.AreEqual(expectedResult, shortsplit);
}
[TestCase(new string[] { "1cm", "to", "mm" }, new string[] { "1", "cm", "to", "mm" })]
[DataTestMethod]
[DataRow(new string[] { "1cm", "to", "mm" }, new object[] { new string[] { "1", "cm", "to", "mm" } })]
public void InsertsSpaces(string[] input, string[] expectedResult)
{
InputInterpreter.InputSpaceInserter(ref input);
Assert.AreEqual(expectedResult, input);
CollectionAssert.AreEqual(expectedResult, input);
}
[TestCase(new string[] { "1'", "in", "cm" }, new string[] { "1", "foot", "in", "cm" })]
[TestCase(new string[] { "1\"", "in", "cm" }, new string[] { "1", "inch", "in", "cm" })]
[TestCase(new string[] { "1'6", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
[TestCase(new string[] { "1'6\"", "in", "cm" }, new string[] { "1.5", "foot", "in", "cm" })]
[DataTestMethod]
[DataRow(new string[] { "1'", "in", "cm" }, new object[] { new string[] { "1", "foot", "in", "cm" } })]
[DataRow(new string[] { "1\"", "in", "cm" }, new object[] { new string[] { "1", "inch", "in", "cm" } })]
[DataRow(new string[] { "1'6", "in", "cm" }, new object[] { new string[] { "1.5", "foot", "in", "cm" } })]
[DataRow(new string[] { "1'6\"", "in", "cm" }, new object[] { new string[] { "1.5", "foot", "in", "cm" } })]
public void HandlesShorthandFeetInchNotation(string[] input, string[] expectedResult)
{
InputInterpreter.ShorthandFeetInchHandler(ref input, CultureInfo.InvariantCulture);
Assert.AreEqual(expectedResult, input);
CollectionAssert.AreEqual(expectedResult, input);
}
[TestCase(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" })]
[TestCase(new string[] { "5", "f", "in", "celsius" }, new string[] { "5", "<EFBFBD>f", "in", "DegreeCelsius" })]
[TestCase(new string[] { "5", "c", "in", "f" }, new string[] { "5", "<22>c", "in", "<EFBFBD>f" })]
[TestCase(new string[] { "5", "f", "in", "c" }, new string[] { "5", "<22>f", "in", "<22>c" })]
[DataTestMethod]
[DataRow(new string[] { "5", "CeLsIuS", "in", "faHrenheiT" }, new object[] { new string[] { "5", "DegreeCelsius", "in", "DegreeFahrenheit" } })]
[DataRow(new string[] { "5", "f", "in", "celsius" }, new object[] { new string[] { "5", "<22>f", "in", "DegreeCelsius" } })]
[DataRow(new string[] { "5", "c", "in", "f" }, new object[] { new string[] { "5", "<22>c", "in", "<22>f" } })]
[DataRow(new string[] { "5", "f", "in", "c" }, new object[] { new string[] { "5", "<22>f", "in", "<22>c" } })]
public void PrefixesDegrees(string[] input, string[] expectedResult)
{
InputInterpreter.DegreePrefixer(ref input);
Assert.AreEqual(expectedResult, input);
CollectionAssert.AreEqual(expectedResult, input);
}
[TestCase("a f in c")]
[TestCase("12 f in")]
[DataTestMethod]
[DataRow("a f in c")]
[DataRow("12 f in")]
public void ParseInvalidQueries(string queryString)
{
Query query = new Query(queryString);
@@ -59,8 +64,9 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(null, result);
}
[TestCase("12 f in c", 12)]
[TestCase("10m to cm", 10)]
[DataTestMethod]
[DataRow("12 f in c", 12)]
[DataRow("10m to cm", 10)]
public void ParseValidQueries(string queryString, double result)
{
Query query = new Query(queryString);

View File

@@ -3,14 +3,14 @@
// See the LICENSE file in the project root for more information.
using System.Linq;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
{
[TestFixture]
[TestClass]
public class UnitHandlerTests
{
[Test]
[TestMethod]
public void HandleTemperature()
{
var convertModel = new ConvertModel(1, "DegreeCelsius", "DegreeFahrenheit");
@@ -18,7 +18,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(33.79999999999999d, result);
}
[Test]
[TestMethod]
public void HandleLength()
{
var convertModel = new ConvertModel(1, "meter", "centimeter");
@@ -26,7 +26,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(100, result);
}
[Test]
[TestMethod]
public void HandlesByteCapitals()
{
var convertModel = new ConvertModel(1, "kB", "kb");
@@ -34,7 +34,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
Assert.AreEqual(8, result);
}
[Test]
[TestMethod]
public void HandleInvalidModel()
{
var convertModel = new ConvertModel(1, "aa", "bb");