diff --git a/UnitsNet.Tests/QuantityParserTests.cs b/UnitsNet.Tests/QuantityParserTests.cs new file mode 100644 index 0000000000..79f9a7bd72 --- /dev/null +++ b/UnitsNet.Tests/QuantityParserTests.cs @@ -0,0 +1,44 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using UnitsNet.Tests.CustomQuantities; +using Xunit; + +namespace UnitsNet.Tests +{ + public class QuantityParserTests + { + [Fact] + public void Parse_MappedCustomUnit() + { + var unitAbbreviationsCache = new UnitAbbreviationsCache(); + unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh"); + var quantityParser = new QuantityParser(unitAbbreviationsCache); + + HowMuch q = quantityParser.Parse("1 fooh", + null, + (value, unit) => new HowMuch((double) value, unit)); + + Assert.Equal(HowMuchUnit.Some, q.Unit); + Assert.Equal(1, q.Value); + } + + [Fact] + public void TryParse_MappedCustomUnit() + { + var unitAbbreviationsCache = new UnitAbbreviationsCache(); + unitAbbreviationsCache.MapUnitToAbbreviation(HowMuchUnit.Some, "fooh"); + var quantityParser = new QuantityParser(unitAbbreviationsCache); + + bool success = quantityParser.TryParse("1 fooh", + null, + (value, unit) => new HowMuch((double) value, unit), + out HowMuch q); + + Assert.True(success); + Assert.Equal(HowMuchUnit.Some, q.Unit); + Assert.Equal(1, q.Value); + } + + } +} diff --git a/UnitsNet.Tests/UnitsNet.Tests.csproj b/UnitsNet.Tests/UnitsNet.Tests.csproj index 6f38a78f1c..577831ffbb 100644 --- a/UnitsNet.Tests/UnitsNet.Tests.csproj +++ b/UnitsNet.Tests/UnitsNet.Tests.csproj @@ -7,6 +7,14 @@ true + + + ../UnitsNet.snk + false + true + UnitsNet.Tests + + diff --git a/UnitsNet/AssemblyInfo.cs b/UnitsNet/AssemblyInfo.cs index ef8f9364ec..d897374117 100644 --- a/UnitsNet/AssemblyInfo.cs +++ b/UnitsNet/AssemblyInfo.cs @@ -2,4 +2,8 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using System.Runtime.CompilerServices; + [assembly: CLSCompliant(true)] +[assembly: InternalsVisibleTo("UnitsNet.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010089abdcb0025f7d1c4c766686dd852b978ca5bb9fd80bba9d3539e8399b01170ae0ea10c0c3baa301b1d13090d5aff770532de00c88b67c4b24669fde7f9d87218f1c6c073a09016cbb2f87119b94227c2301f4e2a096043e30f7c47c872bbd8e0b80d924952e6b36990f13f847e83e9efb107ec2121fe39d7edaaa4e235af8c4")] + diff --git a/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs b/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs index f5a9341450..0232e43834 100644 --- a/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs +++ b/UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs @@ -4,17 +4,12 @@ using System; using System.Collections.Generic; using System.Reflection; -using System.Runtime.CompilerServices; #if NET40 || NET35 || NET20 || SILVERLIGHT using UniformTypeInfo = System.Type; #else using UniformTypeInfo = System.Reflection.TypeInfo; #endif -[assembly: - InternalsVisibleTo( - "UnitsNet.Serialization.JsonNet, PublicKey=002400000480000094000000060200000024000052534131000400000100010089abdcb0025f7d1c4c766686dd852b978ca5bb9fd80bba9d3539e8399b01170ae0ea10c0c3baa301b1d13090d5aff770532de00c88b67c4b24669fde7f9d87218f1c6c073a09016cbb2f87119b94227c2301f4e2a096043e30f7c47c872bbd8e0b80d924952e6b36990f13f847e83e9efb107ec2121fe39d7edaaa4e235af8c4")] - // Based on // https://github.com/StefH/ReflectionBridge/blob/c1e34e57fe3fc93507e83d5cebc1677396645397/ReflectionBridge/src/ReflectionBridge/Extensions/ReflectionBridgeExtensions.cs // MIT license