public void SetDisplayUnit() { var unitProvider = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture); var unitSymbol = unitProvider.GetDisplayUnit(typeof(Length)); // Change the display unit unitProvider.RegisterUnit(627.48 * Length.Millimetre, "alen"); unitProvider.TrySetDisplayUnit <Length>("alen"); Assert.AreEqual("1 alen", (0.62748 * Length.Metre).ToString(null, unitProvider)); // Revert Assert.IsTrue(unitProvider.TrySetDisplayUnit <Length>(unitSymbol)); Assert.AreEqual("1 m", Length.Metre.ToString(null, unitProvider)); }
public void SetDisplayUnit() { var unitProvider = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture); var unitSymbol = unitProvider.GetDisplayUnit(typeof(Length)); // Change the display unit unitProvider.RegisterUnit(627.48 * Length.Millimetre, "alen"); unitProvider.TrySetDisplayUnit<Length>("alen"); Assert.AreEqual("1 alen", (0.62748 * Length.Metre).ToString(null, unitProvider)); // Revert Assert.IsTrue(unitProvider.TrySetDisplayUnit<Length>(unitSymbol)); Assert.AreEqual("1 m", Length.Metre.ToString(null, unitProvider)); }
public void TrySetDisplayUnit_NotRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.IsFalse(unitProvider.TrySetDisplayUnit <Length>("km")); }
public void GetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit <TypographicLength>("m"); Assert.Throws <InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.Throws <InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void GetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit <Length>("m"); Assert.AreEqual("m", unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.AreEqual(Length.Metre, unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void TryGetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit <TypographicLength>("m"); Length unit; string symbol; Assert.IsFalse(unitProvider.TryGetDisplayUnit(out unit, out symbol)); }
public void LoadFromList_Test1() { var up = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture); up.TrySetDisplayUnit<Length>("km"); var file = CsvFile.Load(TestList, up); ValidateTest1(file); Assert.AreEqual(typeof(Length), file.Columns[2].Type); var outputStream = new MemoryStream(); file.Save(outputStream, null, up); Assert.AreEqual(Test1Content, Encoding.UTF8.GetString(outputStream.ToArray())); }
public void TryGetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit <Length>("m"); Length unit; string symbol; Assert.IsTrue(unitProvider.TryGetDisplayUnit(out unit, out symbol)); Assert.AreEqual(Length.Metre, unit); Assert.AreEqual("m", symbol); }
public void LoadFromList_Test1() { var up = new UnitProvider(typeof(UnitProvider).Assembly, CultureInfo.InvariantCulture); up.TrySetDisplayUnit <Length>("km"); var file = CsvFile.Load(TestList, up); ValidateTest1(file); Assert.AreEqual(typeof(Length), file.Columns[2].Type); var outputStream = new MemoryStream(); file.Save(outputStream, null, up); Assert.AreEqual(Test1Content, Encoding.UTF8.GetString(outputStream.ToArray())); }
public void GetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit<TypographicLength>("m"); Assert.Throws<InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.Throws<InvalidOperationException>(() => unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void GetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit<Length>("m"); Assert.AreEqual("m", unitProvider.GetDisplayUnit(typeof(Length))); string symbol; Assert.AreEqual(Length.Metre, unitProvider.GetDisplayUnit(typeof(Length), out symbol)); }
public void TryGetDisplayUnit_UnregisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(TypographicLength.Metre, "m"); unitProvider.TrySetDisplayUnit<TypographicLength>("m"); Length unit; string symbol; Assert.IsFalse(unitProvider.TryGetDisplayUnit(out unit, out symbol)); }
public void TryGetDisplayUnit_RegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); unitProvider.TrySetDisplayUnit<Length>("m"); Length unit; string symbol; Assert.IsTrue(unitProvider.TryGetDisplayUnit(out unit, out symbol)); Assert.AreEqual(Length.Metre, unit); Assert.AreEqual("m", symbol); }
public void TrySetDisplayUnit_NotRegisteredUnit() { var unitProvider = new UnitProvider(CultureInfo.InvariantCulture); unitProvider.RegisterUnit(Length.Metre, "m"); Assert.IsFalse(unitProvider.TrySetDisplayUnit<Length>("km")); }