mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
fix unit tests
This commit is contained in:
parent
3b91e33ca1
commit
19edc895bc
4 changed files with 11 additions and 14 deletions
|
@ -153,7 +153,6 @@ void UnitConverter::SetCurrentUnitTypes(const Unit& fromType, const Unit& toType
|
||||||
Calculate();
|
Calculate();
|
||||||
|
|
||||||
UpdateCurrencySymbols();
|
UpdateCurrencySymbols();
|
||||||
UpdateViewModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -337,6 +336,7 @@ wstring UnitConverter::Serialize()
|
||||||
/// <param name="serializedData">wstring holding the serialized data. If it does not have expected number of parameters, we will ignore it</param>
|
/// <param name="serializedData">wstring holding the serialized data. If it does not have expected number of parameters, we will ignore it</param>
|
||||||
void UnitConverter::DeSerialize(const wstring& serializedData)
|
void UnitConverter::DeSerialize(const wstring& serializedData)
|
||||||
{
|
{
|
||||||
|
ClearValues();
|
||||||
ResetCategoriesAndRatios();
|
ResetCategoriesAndRatios();
|
||||||
|
|
||||||
if (serializedData.empty())
|
if (serializedData.empty())
|
||||||
|
@ -635,8 +635,6 @@ void UnitConverter::SendCommand(Command command)
|
||||||
}
|
}
|
||||||
|
|
||||||
Calculate();
|
Calculate();
|
||||||
|
|
||||||
UpdateViewModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -974,6 +972,7 @@ void UnitConverter::Calculate()
|
||||||
m_returnDisplay = m_currentDisplay;
|
m_returnDisplay = m_currentDisplay;
|
||||||
m_returnHasDecimal = m_currentHasDecimal;
|
m_returnHasDecimal = m_currentHasDecimal;
|
||||||
TrimString(m_returnDisplay);
|
TrimString(m_returnDisplay);
|
||||||
|
UpdateViewModel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,6 +1022,7 @@ void UnitConverter::Calculate()
|
||||||
}
|
}
|
||||||
m_returnHasDecimal = (m_returnDisplay.find(L'.') != m_returnDisplay.npos);
|
m_returnHasDecimal = (m_returnDisplay.find(L'.') != m_returnDisplay.npos);
|
||||||
}
|
}
|
||||||
|
UpdateViewModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1083,10 +1083,3 @@ void UnitConverter::UpdateViewModel()
|
||||||
m_vmCallback->DisplayCallback(m_currentDisplay, m_returnDisplay);
|
m_vmCallback->DisplayCallback(m_currentDisplay, m_returnDisplay);
|
||||||
m_vmCallback->SuggestedValueCallback(CalculateSuggested());
|
m_vmCallback->SuggestedValueCallback(CalculateSuggested());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitConverter::ResetCategoriesAndRatio()
|
|
||||||
{
|
|
||||||
ResetCategoriesAndRatios();
|
|
||||||
Calculate();
|
|
||||||
UpdateViewModel();
|
|
||||||
}
|
|
||||||
|
|
|
@ -195,7 +195,8 @@ namespace UnitConversionManager
|
||||||
virtual void SetViewModelCallback(_In_ const std::shared_ptr<IUnitConverterVMCallback>& newCallback) = 0;
|
virtual void SetViewModelCallback(_In_ const std::shared_ptr<IUnitConverterVMCallback>& newCallback) = 0;
|
||||||
virtual void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<IViewModelCurrencyCallback>& newCallback) = 0;
|
virtual void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<IViewModelCurrencyCallback>& newCallback) = 0;
|
||||||
virtual concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() = 0;
|
virtual concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() = 0;
|
||||||
virtual void ResetCategoriesAndRatio() = 0;
|
virtual void Calculate() = 0;
|
||||||
|
virtual void ResetCategoriesAndRatios() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnitConverter : public IUnitConverter, public std::enable_shared_from_this<UnitConverter>
|
class UnitConverter : public IUnitConverter, public std::enable_shared_from_this<UnitConverter>
|
||||||
|
@ -221,7 +222,6 @@ namespace UnitConversionManager
|
||||||
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override;
|
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override;
|
||||||
// IUnitConverter
|
// IUnitConverter
|
||||||
|
|
||||||
void ResetCategoriesAndRatio();
|
|
||||||
static std::vector<std::wstring> StringToVector(const std::wstring& w, const wchar_t * delimiter, bool addRemainder = false);
|
static std::vector<std::wstring> StringToVector(const std::wstring& w, const wchar_t * delimiter, bool addRemainder = false);
|
||||||
static std::wstring Quote(const std::wstring& s);
|
static std::wstring Quote(const std::wstring& s);
|
||||||
static std::wstring Unquote(const std::wstring& s);
|
static std::wstring Unquote(const std::wstring& s);
|
||||||
|
|
|
@ -720,7 +720,8 @@ void UnitConverterViewModel::OnCurrencyDataLoadFinished(bool didLoad)
|
||||||
{
|
{
|
||||||
m_isCurrencyDataLoaded = true;
|
m_isCurrencyDataLoaded = true;
|
||||||
CurrencyDataLoadFailed = !didLoad;
|
CurrencyDataLoadFailed = !didLoad;
|
||||||
m_model->ResetCategoriesAndRatio();
|
m_model->ResetCategoriesAndRatios();
|
||||||
|
m_model->Calculate();
|
||||||
ResetCategory();
|
ResetCategory();
|
||||||
|
|
||||||
StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed;
|
StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed;
|
||||||
|
|
|
@ -42,11 +42,14 @@ namespace CalculatorUnitTests
|
||||||
void SendCommand(UCM::Command command) override;
|
void SendCommand(UCM::Command command) override;
|
||||||
void SetViewModelCallback(const std::shared_ptr<UCM::IUnitConverterVMCallback>& newCallback) override;
|
void SetViewModelCallback(const std::shared_ptr<UCM::IUnitConverterVMCallback>& newCallback) override;
|
||||||
void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<UCM::IViewModelCurrencyCallback>& /*newCallback*/) override {}
|
void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<UCM::IViewModelCurrencyCallback>& /*newCallback*/) override {}
|
||||||
|
void Calculate() override {}
|
||||||
|
void ResetCategoriesAndRatios() override{}
|
||||||
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override
|
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override
|
||||||
{
|
{
|
||||||
co_return std::make_pair(L"", L"");
|
co_return std::make_pair(true, L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UINT m_initCallCount;
|
UINT m_initCallCount;
|
||||||
UINT m_getCategoriesCallCount;
|
UINT m_getCategoriesCallCount;
|
||||||
UINT m_setCurrentCategoryCallCount;
|
UINT m_setCurrentCategoryCallCount;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue