public async void TestDeleteInstallationExceptionInvalidTenantId() { // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); var service = NbService.Singleton; service.TenantId = ("InvalidTenantId"); // Main try { await currentInstallation.DeleteInstallation(); Assert.Fail("No Exception"); } catch (NbHttpException e) { Assert.AreEqual(HttpStatusCode.NotFound, e.StatusCode); } finally { // After Test service.TenantId = TestConfig.TenantId; } }
public async void TestRefreshInstallationNormalSaved() { // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); var channels = currentInstallation.Channels; var allowedSenders = currentInstallation.AllowedSenders; var owner = currentInstallation.Owner; var options = currentInstallation.Options; // Change Strorage Data var json = ITUtil.GetJsonFromStorage(); json["options"] = null; ITUtil.SaveJsonToStorage(json); // Main var result = await NbSsePushInstallation.RefreshCurrentInstallation(); // Check Response ITUtil.CheckCommonResponse(result); Assert.AreEqual(channels, result.Channels); Assert.AreEqual(allowedSenders, result.AllowedSenders); Assert.AreEqual(owner, result.Owner); Assert.AreEqual(options, result.Options); // Check Storage ITUtil.CheckSaveStorage(result); }
public async void TestDeleteInstallationExceptionNotExists() { // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); // Change InstallationId currentInstallation.InstallationId = "InvalidId"; // Main try { await currentInstallation.DeleteInstallation(); Assert.Fail("No Exception"); } catch (NbHttpException e) { Assert.AreEqual(HttpStatusCode.NotFound, e.StatusCode); // Check Delete Storage CheckDeleteStorage(); } }
public async void TestRefreshInstallationExceptionInvalidAppKey() { // Save Installation await ITUtil.UpsertInstallation(); var service = NbService.Singleton; service.AppKey = ("InvalidAppKey"); // Main try { await NbSsePushInstallation.RefreshCurrentInstallation(); Assert.Fail("No Exception"); } catch (NbHttpException e) { Assert.AreEqual(HttpStatusCode.Unauthorized, e.StatusCode); } finally { // After Test service.TenantId = TestConfig.AppKey; } }
public async void TestUpdateInstallationExceptionInvalidTenantId() { // Save Installation await ITUtil.UpsertInstallation(); var service = NbService.Singleton; service.TenantId = ("InvalidTenantId"); // Main try { // Update Installation await ITUtil.UpsertInstallation(); Assert.Fail("No Exception"); } catch (NbHttpException e) { Assert.AreEqual(HttpStatusCode.NotFound, e.StatusCode); // Check Delete Storage CheckDeleteStorage(); } finally { // After Test service.TenantId = TestConfig.TenantId; } }
public async void TestUpdateInstallationExceptionInvalidAppId() { // Save Installation await ITUtil.UpsertInstallation(); var service = NbService.Singleton; service.AppId = ("InvalidAppId"); // Main try { // Update Installation await ITUtil.UpsertInstallation(); Assert.Fail("No Exception"); } catch (NbHttpException e) { Assert.AreEqual(HttpStatusCode.Unauthorized, e.StatusCode); } finally { // After Test service.AppId = TestConfig.AppId; } }
public async void TestUpdateInstallationNormalNotLoggedIn() { // Signup & Login var user = await ITUtil.SignUpAndLogin(); // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); Assert.AreEqual(user.UserId, currentInstallation.Owner); var preInstallationId = currentInstallation.InstallationId; var preUsername = currentInstallation.Username; var prePassword = currentInstallation.Password; var preUri = currentInstallation.Uri; // Logout await ITUtil.Logout(); // Change Channels, AllowedSenders and Options // Channels Set ISet <string> channels = new HashSet <string>(); channels.Add("chan2"); currentInstallation.Channels = channels; // AllowedSenders Set ISet <string> allowedSenders = new HashSet <string>(); allowedSenders.Add("g:anonymous"); currentInstallation.AllowedSenders = allowedSenders; // Options Set NbJsonObject options = new NbJsonObject(); options.Add("email", "*****@*****.**"); options.Add("test", "testValue2"); currentInstallation.Options = options; // Main var result = await currentInstallation.Save(); // Check Response ITUtil.CheckCommonResponse(result); Assert.AreEqual(preInstallationId, result.InstallationId); Assert.AreEqual(channels, result.Channels); Assert.AreEqual(allowedSenders, result.AllowedSenders); Assert.AreEqual(options, result.Options); // Check Owner is null Assert.IsNull(result.Owner); Assert.AreEqual(preUsername, result.Username); Assert.AreEqual(prePassword, result.Password); Assert.AreEqual(preUri, result.Uri); // Check Storage ITUtil.CheckSaveStorage(result); }
public async void TestDeleteInstallationNormal() { // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); // Main await currentInstallation.DeleteInstallation(); // Check Delete Storage CheckDeleteStorage(); }
public async void TestGetCurrentInstallationNormalSaved() { // Save Installation var upsertInstallation = await ITUtil.UpsertInstallation(); NbSsePushInstallation._sInstance = null; // Main NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); // Assert Equal Installation AssertAreEqualInstallation(upsertInstallation, currentInstallation); }
public async void TestSaveInstallationNormalSameDeviceToken() { // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); var preInstallationId = currentInstallation.InstallationId; var preDeviceToken = currentInstallation.DeviceToken; // Set InstallationId null currentInstallation.InstallationId = null; // Change Channels, AllowedSenders and Options // Channels Set ISet <string> channels = new HashSet <string>(); channels.Add("chan2"); currentInstallation.Channels = channels; // AllowedSenders Set ISet <string> allowedSenders = new HashSet <string>(); allowedSenders.Add("g:anonymous"); currentInstallation.AllowedSenders = allowedSenders; // Options Set NbJsonObject options = new NbJsonObject(); options.Add("email", "*****@*****.**"); options.Add("test", "testValue2"); currentInstallation.Options = options; // Main var result = await currentInstallation.Save(); // Check Response ITUtil.CheckCommonResponse(result); Assert.AreEqual(preInstallationId, result.InstallationId); Assert.AreEqual(channels, result.Channels); Assert.AreEqual(allowedSenders, result.AllowedSenders); Assert.AreEqual(preDeviceToken, result.DeviceToken); // Check Owner is null Assert.IsNull(result.Owner); Assert.AreEqual(options, result.Options); // Check Storage ITUtil.CheckSaveStorage(result); }
public async void TestDeleteAndSaveInstallationNormal() { // Save Installation await ITUtil.UpsertInstallation(); NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); var deviceToken = currentInstallation.DeviceToken; // Main await currentInstallation.DeleteInstallation(); // Check Delete Storage CheckDeleteStorage(); // Save(again) var result = await ITUtil.UpsertInstallation(); // Check Response ITUtil.CheckCommonResponse(result); ISet <string> channels = new HashSet <string>(); channels.Add("chan1"); Assert.AreEqual(channels, result.Channels); ISet <string> allowedSenders = new HashSet <string>(); allowedSenders.Add("g:anonymous"); Assert.AreEqual(allowedSenders, result.AllowedSenders); // Check Owner is null Assert.IsNull(result.Owner); NbJsonObject options = new NbJsonObject(); options.Add("email", "*****@*****.**"); options.Add("test", "testValue"); Assert.AreEqual(options, result.Options); // Check DeviceToken Assert.AreEqual(deviceToken, result.DeviceToken); // Check Storage ITUtil.CheckSaveStorage(result); }
public async void TestGetCurrentInstallationNormalNotSavedTwice() { // Save Installation var upsertInstallation = await ITUtil.UpsertInstallation(); // GetCurrentInstallation()で端末ストレージからインスタレーション取得するために、nullに設定する NbSsePushInstallation._sInstance = null; // Main NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); // Assert Equal Installation AssertAreEqualInstallation(upsertInstallation, currentInstallation); currentInstallation = NbSsePushInstallation.GetCurrentInstallation(); // Assert Equal Installation AssertAreEqualInstallation(upsertInstallation, currentInstallation); }
public async void TestAutoRecoveryCallbackLocked() { // For Callback Wait Class ManualResetEvent manualEvent = new ManualResetEvent(false); // Save Installation var installation = await ITUtil.UpsertInstallation(); // Set Invalid Password in order to execute AutoRecovery installation.Password = "******"; _client = new NbSsePushReceiveClient(); // Set Lock NbSsePushReceiveClient.AcquireLock(); // Register Error Callback _client.RegisterOnError((statusCode, errorInfo) => { _errorCalledCount++; if (statusCode != HttpStatusCode.Unauthorized) { SetAssert("Not Unauthorized Error: " + statusCode.ToString()); } manualEvent.Set(); }); // Main _client.Connect(); // Wait for OnError Callback with Timeout manualEvent.WaitOne(10000); // Test中にAssert.Fail()するとmanualEvent.Setが呼ばれずハングするので、最後にAssertionをthrowする if (_isAssertionExists) { ThrowAssert(); } // Error Callback: Once Assert.AreEqual(1, _errorCalledCount); }
public async void TestAutoRecoveryNormal() { // For Callback Wait Class ManualResetEvent manualEventForOnOpen = new ManualResetEvent(false); ManualResetEvent manualEventForOnMessage = new ManualResetEvent(false); // Save Installation var installation = await ITUtil.UpsertInstallation(); // Set Invalid Password installation.Password = "******"; _client = new NbSsePushReceiveClient(); // Register Message Callback _client.RegisterOnMessage("TestEventType", (message) => { _messageCalledCount++; manualEventForOnMessage.Set(); }); // Register Error Callback _client.RegisterOnError((statusCode, errorInfo) => { _errorCalledCount++; }); // Register Open Callback _client.RegisterOnOpen(() => { _openCalledCount++; manualEventForOnOpen.Set(); }); // Register Close Callback _client.RegisterOnClose(() => { _closeCalledCount++; }); // Main _client.Connect(); // Wait for OnOpen Callback with Timeout manualEventForOnOpen.WaitOne(10000); // Open Callback: Once Assert.AreEqual(1, _openCalledCount); // Send Message var nebulaPush = new NbPush(); nebulaPush.Query = new NbQuery().EqualTo("email", "*****@*****.**"); nebulaPush.Message = "This is Test."; var sse = new NbSseFields(); sse.EventId = "TestId"; sse.EventType = "TestEventType"; nebulaPush.SseFields = sse; await nebulaPush.SendAsync(); // Wait for OnMessage Callback with Timeout manualEventForOnMessage.WaitOne(10000); // Check Callback Count // Open Callback: Once Assert.AreEqual(1, _openCalledCount); // Close Callback: Once Assert.AreEqual(1, _closeCalledCount); // Error Callback: None Assert.AreEqual(0, _errorCalledCount); // Message Callback: Once Assert.AreEqual(1, _messageCalledCount); // Check Installation var installationAfterAutoRecovery = NbSsePushInstallation.GetCurrentInstallation(); ITUtil.CheckCommonResponse(installationAfterAutoRecovery); Assert.AreEqual(installation.Channels, installationAfterAutoRecovery.Channels); Assert.AreEqual(installation.AllowedSenders, installationAfterAutoRecovery.AllowedSenders); Assert.IsNull(installationAfterAutoRecovery.Owner); Assert.AreEqual(installation.Options, installationAfterAutoRecovery.Options); // Check Storage ITUtil.CheckSaveStorage(installationAfterAutoRecovery); }