Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/FixedPointNano.Tests/FixedPointNano.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.7.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
Expand Down
30 changes: 23 additions & 7 deletions tests/FixedPointNano.Tests/FixedPointNanoTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using System.Numerics;
using Moq;
using Seerstone;

namespace Seerstone.Tests;
Expand Down Expand Up @@ -231,18 +230,17 @@ public void ToStringAndTryFormatShouldUseProvidedFormatProvider()
numberFormat.NumberDecimalSeparator = "_";
numberFormat.NumberGroupSeparator = " ";

var provider = new Mock<IFormatProvider>(MockBehavior.Strict);
provider.Setup(x => x.GetFormat(typeof(NumberFormatInfo))).Returns(numberFormat);
var provider = new TrackingFormatProvider(numberFormat);

var value = FixedPointNano.FromDecimal(1234.5m);
Span<char> buffer = stackalloc char[32];

Assert.That(value.ToString(provider.Object), Is.EqualTo("1234_5"));
Assert.That(value.ToString("N2", provider.Object), Is.EqualTo("1 234_50"));
Assert.That(value.TryFormat(buffer, out var charsWritten, "F3", provider.Object), Is.True);
Assert.That(value.ToString(provider), Is.EqualTo("1234_5"));
Assert.That(value.ToString("N2", provider), Is.EqualTo("1 234_50"));
Assert.That(value.TryFormat(buffer, out var charsWritten, "F3", provider), Is.True);
Assert.That(new string(buffer[..charsWritten]), Is.EqualTo("1234_500"));

provider.Verify(x => x.GetFormat(typeof(NumberFormatInfo)), Times.AtLeastOnce);
Assert.That(provider.GetFormatCallCount, Is.GreaterThan(0));
}

[Test]
Expand Down Expand Up @@ -432,6 +430,24 @@ public void Dispose()
}
}

private sealed class TrackingFormatProvider : IFormatProvider
{
private readonly NumberFormatInfo _numberFormat;

public int GetFormatCallCount { get; private set; }

public TrackingFormatProvider(NumberFormatInfo numberFormat)
{
_numberFormat = numberFormat;
}

public object? GetFormat(Type? formatType)
{
GetFormatCallCount++;
return formatType == typeof(NumberFormatInfo) ? _numberFormat : null;
}
}

[Test]
public void UnaryPlusOperatorShouldReturnSameValue()
{
Expand Down
Loading