Skip to content

Bug fixing and making test project compatible#2459

Open
emmche wants to merge 15 commits into
microsoft:feature/calcviewmodel-to-csharpfrom
emmche:emmche/bug-fix
Open

Bug fixing and making test project compatible#2459
emmche wants to merge 15 commits into
microsoft:feature/calcviewmodel-to-csharpfrom
emmche:emmche/bug-fix

Conversation

@emmche
Copy link
Copy Markdown
Contributor

@emmche emmche commented Apr 29, 2026

Fixes

  • Currency conversion not working due to missing mock data implementation and incorrect data loader flow
  • Currency decimal formatting: Values displayed without proper decimal places (e.g., "1" instead of "1.00") and formatter didn't respect per-currency fraction digits
  • Currency converter showed internal abbreviations instead of localized display names (e.g., "USD" instead of "United States - Dollar")
  • Switching between currencies with different fraction digit limits didn't truncate the input value
  • Invalid input on paste not displayed for an out-of-range number in Programmer mode
  • BitFlip flipping the next digit instead of the clicked digit.
  • Date calculator automation names failed to load causing accessibility issues
  • GetNarratorReadableToken missing: Expression accessibility narrator support was not implemented
  • GitHub Actions used outdated image without VS2026/v145 toolset

Description of the changes:

Currency conversion & formatting (UnitConverterViewModel.cs, CurrencyHttpClient.cs, UnitConverterDataLoader.cs):

  • Implemented mock currency data matching the C++ open-source static ratios (always-available offline mode)
  • Added CurrencyFormatter logic for proper decimal display with per-currency fraction digits
  • Implemented input blocking at max fraction digits and truncation on currency/unit switch
  • Fixed unit display names to use abbreviation - displayName format from the data loader
  • Added [DataMember] preservation of HttpClient field to survive .NET Native AOT stripping

Programmer mode paste error (StandardCalculatorViewModel.cs):

  • Fixed DisplayPasteError() to call SetPrimaryDisplay with the localized "Invalid input" error string (matching C++
    CCalcEngine::DisplayError(CALC_E_DOMAIN))

Accessibility (StandardCalculatorViewModel.cs, LocalizationSettings.cs):

  • Implemented GetNarratorReadableToken for expression display accessibility with thread safety
  • Added LocalizationSettings number/operator character mapping for narrator output

Build & CI (.github/workflows/action-ci.yml, Calculator.Tests.csproj, Calculator.sln):

  • Updated CI workflow image to use VS2026 with v145 platform toolset
  • Converted Calculator.Tests to a proper UWP test project with Package.appxmanifest for deployment
  • Fixed solution configuration mappings for x64 platform

UI test updates (UnitConverterPage.cs):

  • Updated currency UI test helpers to match new unit selection behavior with display names

How changes were validated:

  • Manual verification
  • Built locally with x64 Debug and x64 Release (.NET Native) configurations
  • Ran UI tests
  • Verified Calculator.Tests unit test project builds and deploys

Before
bitflip
After
bitflip_after

emmche and others added 6 commits April 28, 2026 10:30
- Remove broken MetadataDirectories from CalcManager.Interop.vcxproj
  (CppWinRT NuGet handles metadata automatically)
- Add AssetTargetFallback=native to Calculator.ViewModels and Calculator
  projects to fix NU1201 errors with native project references
- Convert Calculator.Tests from net8.0 SDK-style to UWP test project:
  - Use SDKReference TestPlatform.Universal for protocol-matched testhost
  - Add Package.appxmanifest, UnitTestApp.xaml/.cs, and Assets
  - Keep MSTest NuGet packages for test attributes/adapter
- Update Calculator.sln platform mappings for Calculator.Tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port the C++ GetTokenToReadableNameMap logic to C# LocalizationSettings.
Maps engine display tokens (e.g. 'sqr(', '-') to narrator-friendly
names (e.g. 'square (', 'Minus (') for the expression automation name.

This fixes UI test failures where tests expected readable names like
'square (9)' and '4 Minus (' but got raw engine strings 'sqr(9)' and '4 -'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The CurrencyHttpClient was hitting dead Microsoft fwlink URLs that now
redirect to Bing HTML pages instead of returning JSON currency data.
The upstream C++ code uses hardcoded mock data (fictional currencies)
since the real currency service is internal to Microsoft.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@emmche emmche changed the title Fix bitflip and date calcuation automation property loading Bug fixing and making test project compatible Apr 30, 2026
Refactor GetTokenToReadableNameMap to use simple helper methods instead
of ValueTuple arrays to avoid potential .NET Native AOT compilation
issues in Release builds. Add double-checked locking pattern to prevent
race conditions during lazy initialization. Wrap initialization in
try-catch to prevent app crash if resources are unavailable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@emmche emmche force-pushed the emmche/bug-fix branch from 13d6de7 to 817a457 Compare May 1, 2026 03:35
emmche and others added 8 commits April 30, 2026 23:18
The previous commit removed the Windows.Web.Http.HttpClient static field,
which caused the app to crash on startup when compiled with .NET Native AOT
(Release mode). This retains the HttpClient field for assembly reference
stability while still returning mock currency data (matching C++ behavior).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix same-currency conversion returning wrong values by wiring
  GetOrderedUnits/LoadOrderedRatios delegation to CurrencyDataLoader
- Always call SetCurrentUnitTypes in OnUnitChanged (matching C++)
- Add ResetCategoriesAndRatios + Calculate in OnCurrencyDataLoadFinished
- Implement ConvertToLocalizedString with CurrencyFormatter to pad
  decimal places (e.g. '20.' displays as '20.00')
- Implement UpdateInputBlocked to limit decimal digit entry
- Add input blocking check in OnButtonPressed
- Implement UpdateIsDecimalEnabled based on FractionDigits
- Add UpdateCurrencyFormatter call in OnUnitChanged
- Add value1cp switching in OnSwitchActive

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Build unit display name as 'CountryName - CurrencyName' matching C++
- Build accessible name as 'CountryName CurrencyName' matching C++
- Add TruncateFractionDigits to truncate (not round) decimal digits
- Call OnPaste with truncated value in UpdateCurrencyFormatter when
  switching currencies (matching C++ behavior)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace nuget restore with msbuild -t:Restore to properly handle
mixed native C++ and managed C# project references without needing
AssetTargetFallback or SkipGetTargetFrameworkProperties workarounds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…perties

NuGet restore fails with NU1201 when a managed UAP project references
a native vcxproj. Two properties are needed:
- AssetTargetFallback=native: tells NuGet to accept 'native' as a
  compatible framework for UAP projects
- SkipGetTargetFrameworkProperties=true: prevents MSBuild from querying
  native projects for their target framework during restore

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@emmche emmche force-pushed the emmche/bug-fix branch from e16629b to 7707e85 Compare May 5, 2026 01:52
@emmche emmche marked this pull request as ready for review May 5, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants