-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from canhorn/fix/current-culture-format-exception
fix: Number Format Exception when Converting decimal from JavaScript 🐛
- Loading branch information
Showing
3 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
....Sample/Pages/Testing/InteropTesting/Validation/InteropDecimalNumberClutureInfoTest.razor
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,78 @@ | ||
@using System.Globalization | ||
<div> | ||
<h3>Literal Decimal Number Cluture Info Validation</h3> | ||
<div class="--lighter">Interop Get</div> | ||
<div> | ||
Status: | ||
@if (TestStatus == "Passed") | ||
{ | ||
<span class="green-badge">@TestStatus</span> | ||
} | ||
else if (TestStatus == "Failed") | ||
{ | ||
<span class="red-badge">@TestStatus</span> | ||
} | ||
else | ||
{ | ||
<span>@TestStatus</span> | ||
} | ||
</div> | ||
<button class="run-btn" @onclick="HandleRunTest">Run</button> | ||
</div> | ||
|
||
<script suppress-error="BL9992"> | ||
(function () { | ||
window["InteropDecimalNumberClutureInfoTest"] = { | ||
value: 0.0000000000000001334646852585, | ||
}; | ||
})(); | ||
</script> | ||
|
||
@code { | ||
public string TestStatus = "Pending"; | ||
|
||
private string testId => "InteropDecimalNumberClutureInfoTest"; | ||
private decimal result; | ||
private decimal expected = 0.0000000000000001334646852585m; | ||
|
||
private void HandleRunTest() | ||
{ | ||
var clutureInfo = CultureInfo.CurrentCulture; | ||
try | ||
{ | ||
// Using de-DE because the decimal place is ',' for decimal/numbers. | ||
CultureInfo.CurrentCulture = new CultureInfo( | ||
"de-DE" | ||
); | ||
|
||
RunTest(); | ||
ValidateTest(); | ||
} | ||
catch { } | ||
finally | ||
{ | ||
// Reset back to ClutureInfo before test changed it. | ||
CultureInfo.CurrentCulture = clutureInfo; | ||
} | ||
} | ||
|
||
public void RunTest() | ||
{ | ||
result = EventHorizonBlazorInterop.Get<decimal>( | ||
testId, | ||
"value" | ||
); | ||
} | ||
|
||
public void ValidateTest() | ||
{ | ||
if (result == expected) | ||
{ | ||
TestStatus = "Passed"; | ||
} | ||
else | ||
{ | ||
TestStatus = "Failed"; | ||
} | ||
} | ||
} |
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