Exemplo n.º 1
0
        public async void TestSaveInstallationNormalNoOptions()
        {
            // 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;

            // 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);

            // Check Options is null
            Assert.IsNull(result.Options);

            // Check Storage
            ITUtil.CheckSaveStorage(result);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }