2021-08-11 17:22:30 +02:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
2021-06-09 10:46:19 +01:00
|
|
|
|
using System.Linq;
|
2021-08-16 15:25:06 +02:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2021-06-09 10:46:19 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Community.PowerToys.Run.Plugin.UnitConverter.UnitTest
|
|
|
|
|
|
{
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[TestClass]
|
2021-06-09 10:46:19 +01:00
|
|
|
|
public class UnitHandlerTests
|
|
|
|
|
|
{
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[TestMethod]
|
2021-06-09 10:46:19 +01:00
|
|
|
|
public void HandleTemperature()
|
|
|
|
|
|
{
|
|
|
|
|
|
var convertModel = new ConvertModel(1, "DegreeCelsius", "DegreeFahrenheit");
|
|
|
|
|
|
double result = UnitHandler.ConvertInput(convertModel, UnitsNet.QuantityType.Temperature);
|
|
|
|
|
|
Assert.AreEqual(33.79999999999999d, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[TestMethod]
|
2021-06-09 10:46:19 +01:00
|
|
|
|
public void HandleLength()
|
|
|
|
|
|
{
|
|
|
|
|
|
var convertModel = new ConvertModel(1, "meter", "centimeter");
|
|
|
|
|
|
double result = UnitHandler.ConvertInput(convertModel, UnitsNet.QuantityType.Length);
|
|
|
|
|
|
Assert.AreEqual(100, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[TestMethod]
|
2021-06-09 10:46:19 +01:00
|
|
|
|
public void HandlesByteCapitals()
|
|
|
|
|
|
{
|
|
|
|
|
|
var convertModel = new ConvertModel(1, "kB", "kb");
|
|
|
|
|
|
double result = UnitHandler.ConvertInput(convertModel, UnitsNet.QuantityType.Information);
|
|
|
|
|
|
Assert.AreEqual(8, result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-16 15:25:06 +02:00
|
|
|
|
[TestMethod]
|
2021-06-09 10:46:19 +01:00
|
|
|
|
public void HandleInvalidModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
var convertModel = new ConvertModel(1, "aa", "bb");
|
|
|
|
|
|
var results = UnitHandler.Convert(convertModel);
|
|
|
|
|
|
Assert.AreEqual(0, results.Count());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|