public void TestConnectNormal()
        {
            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            // Main
            client.Connect();

            // Check State
            Assert.AreEqual(client._clientState, NbSsePushReceiveClient.State.Connect);
        }
        public void TestConnecExceptionNoId()
        {
            DeleteStorage();
            // インスタレーションIDなしでストレージに保存
            SaveInstallationToStorage(false, true);

            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            // Main

            client.Connect();
            Assert.Fail("No Exception");
        }
        public void TestConnecExceptionNoSseInfo()
        {
            DeleteStorage();
            SaveInstallationToStorage(true, false);

            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            // Main
            try
            {
                client.Connect();
                Assert.Fail("No Exception");
            }
            catch (NbHttpException e)
            {
                Assert.AreEqual(e.StatusCode, HttpStatusCode.BadRequest);
            }
        }
        public void TestConnectExceptionFailer()
        {
            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            // 接続状態を「接続中」に設定
            client._clientState = NbSsePushReceiveClient.State.Connect;

            // Main
            try
            {
                client.Connect();
                Assert.Fail("No Exception");
            }
            catch (NbHttpException e)
            {
                Assert.AreEqual(e.StatusCode, HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }