Skip to content

Commit

Permalink
Make QuantityParser public and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angularsen committed Apr 22, 2019
1 parent c81e1bb commit 5e26a16
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
44 changes: 44 additions & 0 deletions UnitsNet.Tests/QuantityParserTests.cs
Original file line number Diff line number Diff line change
@@ -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<HowMuch, HowMuchUnit>("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<HowMuch, HowMuchUnit>("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);
}

}
}
8 changes: 8 additions & 0 deletions UnitsNet.Tests/UnitsNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
</PropertyGroup>

<!-- Strong name signing -->
<PropertyGroup>
<AssemblyOriginatorKeyFile>../UnitsNet.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<SignAssembly>true</SignAssembly>
<AssemblyName>UnitsNet.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<Compile Remove="obj\**" />
<EmbeddedResource Remove="obj\**" />
Expand Down
4 changes: 4 additions & 0 deletions UnitsNet/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

5 changes: 0 additions & 5 deletions UnitsNet/InternalHelpers/ReflectionBridgeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5e26a16

Please sign in to comment.