-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure number and decimal does best effort parsing (#147)
- Loading branch information
1 parent
c6ad6fe
commit 7a35d4d
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
Dan.Common.UnitTest/Extensions/EvidenceHarvesterRequestExtensionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Dan.Common.Extensions; | ||
using FluentAssertions; | ||
|
||
namespace Dan.Common.UnitTest.Extensions; | ||
|
||
[TestClass] | ||
public class EvidenceHarvesterRequestExtensionTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow(1, true, 1)] | ||
[DataRow("1", true, 1)] | ||
[DataRow(null, false, 0)] | ||
[DataRow(3000000000, false, 0)] | ||
[DataRow(-3000000000, false, 0)] | ||
public void TryGetParameter_Numbers(object value, bool expectedBool, int expectedInt) | ||
{ | ||
// Arrange | ||
const string parameterName = "NumberParam"; | ||
var request = new EvidenceHarvesterRequest | ||
{ | ||
Parameters = | ||
[ | ||
new EvidenceParameter() | ||
{ | ||
EvidenceParamName = parameterName, | ||
Value = value | ||
} | ||
] | ||
}; | ||
|
||
// Act | ||
var actualBool = request.TryGetParameter(parameterName, out int actualInt); | ||
|
||
// Assert | ||
actualBool.Should().Be(expectedBool); | ||
actualInt.Should().Be(expectedInt); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(1, true, 1)] | ||
[DataRow(1.2, true, 1.2)] | ||
[DataRow("1", true, 1)] | ||
[DataRow("1.2", true, 1.2)] | ||
[DataRow(null, false, 0)] | ||
[DataRow(3000000000d, true, 3000000000)] | ||
[DataRow(-3000000000d, true, -3000000000)] | ||
public void TryGetParameter_Decimal(object value, bool expectedBool, double expectedTemp) | ||
{ | ||
// Arrange | ||
// decimal is not const so need to cast | ||
var expectedDecimal = (decimal)expectedTemp; | ||
const string parameterName = "NumberParam"; | ||
var request = new EvidenceHarvesterRequest | ||
{ | ||
Parameters = | ||
[ | ||
new EvidenceParameter() | ||
{ | ||
EvidenceParamName = parameterName, | ||
Value = value | ||
} | ||
] | ||
}; | ||
|
||
// Act | ||
var actualBool = request.TryGetParameter(parameterName, out decimal actualDecimal); | ||
|
||
// Assert | ||
actualBool.Should().Be(expectedBool); | ||
actualDecimal.Should().Be(expectedDecimal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters