Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring PushNotification unit tests #2389

Merged
merged 16 commits into from
Apr 20, 2022
Merged
18 changes: 9 additions & 9 deletions test/PushNotificationTests/UnpackagedTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Test::PushNotifications

void UnpackagedTests::ChannelRequestUsingNullRemoteId()
{
if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().CreateChannelAsync(winrt::guid()).get(), E_INVALIDARG);
}
Expand All @@ -56,7 +56,7 @@ namespace Test::PushNotifications

void UnpackagedTests::ChannelRequestUsingRemoteId()
{
if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
auto channelOperation{ PushNotificationManager::Default().CreateChannelAsync(c_azureRemoteId) };
VERIFY_SUCCEEDED(ChannelRequestHelper(channelOperation));
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace Test::PushNotifications

void UnpackagedTests::VerifyUnregisterFails()
{
if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED);
}
Expand All @@ -107,7 +107,7 @@ namespace Test::PushNotifications

void UnpackagedTests::VerifyUnregisterAllFails()
{
if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED);
}
Expand All @@ -131,7 +131,7 @@ namespace Test::PushNotifications
PushNotificationManager::Default().Register();
m_registered = true;

if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED));
}
Expand All @@ -148,7 +148,7 @@ namespace Test::PushNotifications

PushNotificationManager::Default().Unregister();

if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().Register(), HRESULT_FROM_WIN32(ERROR_ALREADY_REGISTERED));
}
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace Test::PushNotifications
m_registered = true;

PushNotificationManager::Default().Unregister();
if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().Unregister(), E_UNEXPECTED);
}
Expand All @@ -197,7 +197,7 @@ namespace Test::PushNotifications
PushNotificationManager::Default().UnregisterAll();
m_registered = false;

if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().UnregisterAll(), E_UNEXPECTED);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace Test::PushNotifications
PushNotificationManager::Default().Register();
m_registered = true;

if (!m_isSelfContained)
if (PushNotificationManager::Default().IsSupported())
{
VERIFY_THROWS_HR(PushNotificationManager::Default().PushReceived([](const auto&, PushNotificationReceivedEventArgs const& /* args */) {}), HRESULT_FROM_WIN32(ERROR_NOT_FOUND));
}
Expand Down
6 changes: 3 additions & 3 deletions test/PushNotificationTests/UnpackagedTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Test::PushNotifications
HRESULT ChannelRequestHelper(IAsyncOperationWithProgress<PushNotificationCreateChannelResult, PushNotificationCreateChannelStatus> const& channelOperation);

bool m_registered{ false };
bool m_isSelfContained{ false };
public:
BEGIN_TEST_CLASS(UnpackagedTests)
TEST_CLASS_PROPERTY(L"Description", L"Windows App SDK Push Notifications test")
Expand All @@ -38,9 +37,10 @@ namespace Test::PushNotifications
TEST_CLASS_SETUP(ClassInit)
{
::Test::Bootstrap::Setup();
if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", m_isSelfContained)))
bool isSelfContained{ false };
if (SUCCEEDED(TestData::TryGetValue(L"SelfContained", isSelfContained)))
{
if (!m_isSelfContained)
if (!isSelfContained)
{
::WindowsAppRuntime::SelfContained::TestInitialize(::Test::Bootstrap::TP::WindowsAppRuntimeFramework::c_PackageFamilyName);
}
Expand Down