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

            client.RegisterOnMessage(null, msg => { });
        }
        public void TestRegisterOnMessageExceptionNullCallback()
        {
            NbSsePushReceiveClient client = new NbSsePushReceiveClient();

            client.RegisterOnMessage("message", null);
        }
Esempio n. 3
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);
        }