예제 #1
0
        public void SetUp()
        {
            ITUtil.DeleteInstallationsOfAllApp();

            ITUtil.InitNebula();

            ITUtil.DeleteAllUsers();
            ITUtil.DeleteAllGroups();

            if (NbUser.IsLoggedIn())
            {
                NbUser.LogoutAsync().Wait();
            }

            // 端末ストレージ上のインスタレーション情報削除
            ITUtil.DeleteStorage();

            // 各フィールド初期化
            NbSsePushInstallation._sInstance = null;
            _isAssertionExists  = false;
            _openCalledCount    = 0;
            _closeCalledCount   = 0;
            _errorCalledCount   = 0;
            _messageCalledCount = 0;
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <summary>
        /// 全グループ削除
        /// </summary>
        public static void DeleteAllGroups()
        {
            ITUtil.UseMasterKey();

            var groups = NbGroup.QueryGroupsAsync().Result;

            foreach (var group in groups)
            {
                group.DeleteAsync().Wait();
            }

            ITUtil.UseNormalKey();
        }
예제 #4
0
        /// <summary>
        /// 全ユーザ削除
        /// </summary>
        public static void DeleteAllUsers()
        {
            ITUtil.UseMasterKey();

            var users = NbUser.QueryUserAsync().Result;

            foreach (var user in users)
            {
                user.DeleteAsync().Wait();
            }

            ITUtil.UseNormalKey();
        }
예제 #5
0
 // SSE Pushサーバからのレスポンスのうち、各テストで共通の部分をチェックする
 public static void CheckCommonResponse(NbSsePushInstallation installation)
 {
     //Channels, AllowedSenders, Owner, Options以外
     Assert.IsNotNullOrEmpty(installation.InstallationId);
     Assert.AreEqual("dotnet", installation.OsType);
     Assert.AreEqual("Unknown", installation.OsVersion);
     Assert.IsNotNullOrEmpty(installation.DeviceToken);
     Assert.AreEqual("sse", installation.PushType);
     Assert.AreEqual(-1, installation.AppVersionCode);
     Assert.AreEqual(ITUtil.GetVersionName(), installation.AppVersionString);
     Assert.IsNotNullOrEmpty(installation.Username);
     Assert.IsNotNullOrEmpty(installation.Password);
     StringAssert.Contains(TestConfig.SsePushEndpointUrl, installation.Uri);
 }
예제 #6
0
        /// <summary>
        /// 全インスタレーション削除(Push送信禁止アプリ)
        /// </summary>
        public static void DeleteInstallationsForPushDisabled()
        {
            ITUtil.UseMasterKeyForPushDisabled();

            try
            {
                DeleteInstallations();
            }
            catch (Exception)
            {
                Assert.Fail("DeleteInstallations() Fail");
            }
            finally
            {
                ITUtil.UseNormalKeyForPushDisabled();
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        public void SetUp()
        {
            ITUtil.DeleteInstallationsOfAllApp();

            ITUtil.InitNebula();

            ITUtil.DeleteAllUsers();
            ITUtil.DeleteAllGroups();

            if (NbUser.IsLoggedIn())
            {
                NbUser.LogoutAsync().Wait();
            }

            // 端末ストレージ上のインスタレーション情報削除
            ITUtil.DeleteStorage();

            // 各フィールド初期化
            NbSsePushInstallation._sInstance = null;
        }
예제 #11
0
        public async void TestSaveInstallationNormalNotLoggedIn()
        {
            // Not SignUp & Login

            NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation();

            // Channels Set
            ISet <string> channels = new HashSet <string>();

            channels.Add("chan1");
            currentInstallation.Channels = channels;

            // AllowedSenders Set
            ISet <string> allowedSenders = new HashSet <string>();

            allowedSenders.Add("g:authenticated");
            currentInstallation.AllowedSenders = allowedSenders;

            // Options Set
            NbJsonObject options = new NbJsonObject();

            options.Add("email", "*****@*****.**");
            options.Add("test", "testValue");
            currentInstallation.Options = options;

            // Main
            var result = await currentInstallation.Save();

            // Check Response
            ITUtil.CheckCommonResponse(result);
            Assert.AreEqual(channels, result.Channels);
            Assert.AreEqual(allowedSenders, result.AllowedSenders);

            // Check Owner is null
            Assert.IsNull(result.Owner);
            Assert.AreEqual(options, result.Options);

            // Check Storage
            ITUtil.CheckSaveStorage(result);
        }
예제 #12
0
        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);
        }