Example #1
0
        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;
            }
        }
        // インスタレーションの内容チェック
        private void CheckInstallation(NbSsePushInstallation installation)
        {
            ISet <string> channels = new HashSet <string>();

            channels.Add("chan0");
            ISet <string> allowedSenders = new HashSet <string>();

            allowedSenders.Add("g:group1");

            Assert.AreEqual(installation.OsType, "dotnet");
            Assert.AreEqual(installation.OsVersion, "Unknown");
            Assert.AreEqual(installation.DeviceToken, "abcdefg");
            Assert.AreEqual(installation.PushType, "sse");
            Assert.AreEqual(installation.Channels, channels);
            Assert.AreEqual(installation.AppVersionCode, -1);
            Assert.AreEqual(installation.AppVersionString, "4.0.0.0");
            Assert.AreEqual(installation.AllowedSenders, allowedSenders);
            Assert.AreEqual(installation.InstallationId, "12345");
            Assert.AreEqual(installation.Owner, "ownerString");
            Assert.AreEqual(installation.Username, "testname");
            Assert.AreEqual(installation.Password, "testpass");
            Assert.AreEqual(installation.Uri, "http://example.push.server/foo/bar");
            Assert.AreEqual(installation.Options["option1"], "option1value");
            Assert.AreEqual(installation.Options["option2"], "option2value");
        }
        public async void TestSaveExceptionNoInstallationId()
        {
            // インスタレーションに必須パラメータとオプションをセット
            NbSsePushInstallation installation = SetInstallationParameterAndOption();

            var response = new MockRestResponse(HttpStatusCode.NotFound);

            executor.AddResponse(response);

            try
            {
                // Main
                await installation.Save();

                Assert.Fail("No Exception");
            }
            catch (NbHttpException e)
            {
                Assert.AreEqual(e.StatusCode, HttpStatusCode.NotFound);
            }

            // ストレージ内のインスタレーション情報削除チェック
            CheckDeleteStorage();

            // インスタレーション初期化チェック
            CheckDeleteInstallation(installation);
        }
Example #4
0
        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();
            }
        }
Example #5
0
        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 TestRefreshCurrentInstallationNormal()
        {
            // インスタレーションをストレージに保存
            SaveInstallationToStorage(true);

            var responseBody = CreateResponseBody(true);
            var response     = new MockRestResponse(HttpStatusCode.OK, responseBody.ToString());

            executor.AddResponse(response);

            // Main
            var installationResp = await NbSsePushInstallation.RefreshCurrentInstallation();

            // Check Response
            CheckInstallation(installationResp);

            // Check Request
            var req = executor.LastRequest;

            Assert.AreEqual(HttpMethod.Get, req.Method);
            Assert.IsTrue(req.Uri.EndsWith("/installations/" + "12345"));
            Assert.AreEqual(3, req.Headers.Count);
            Assert.IsTrue(req.Headers.ContainsKey(appKey));
            Assert.IsTrue(req.Headers.ContainsKey(appId));

            // ストレージ内のインスタレーション情報存在チェック
            CheckSaveStorage();
        }
Example #7
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);
        }
Example #8
0
        public async void TestSaveInstallationExceptionNoAllowedSenders()
        {
            NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation();

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

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

            // AllowedSenders Not Set
            Assert.IsNull(currentInstallation.AllowedSenders);

            // Main
            try
            {
                await currentInstallation.Save();

                Assert.Fail("No Exception");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual("Null Channels or null AllowedSenders.", e.Message);
            }
        }
        public async void TestRefreshCurrentInstallationExceptionNotExists()
        {
            NbSsePushInstallation installation = new NbSsePushInstallation();

            // インスタレーションをストレージに保存
            SaveInstallationToStorage(true);

            var response = new MockRestResponse(HttpStatusCode.NotFound);

            executor.AddResponse(response);

            try
            {
                // Main
                installation = await NbSsePushInstallation.RefreshCurrentInstallation();

                Assert.Fail("No Exception");
            }
            catch (NbHttpException e)
            {
                Assert.AreEqual(e.StatusCode, HttpStatusCode.NotFound);
            }

            // ストレージ内のインスタレーション情報削除チェック
            CheckDeleteStorage();
        }
Example #10
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);
        }
Example #11
0
        /// <summary>
        /// インスタレーション登録/更新 -  任意の情報あり - 未ログイン
        /// </summary>
        public static async Task <NbSsePushInstallation> UpsertInstallation()
        {
            // 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:anonymous");
            currentInstallation.AllowedSenders = allowedSenders;

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

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

            // Main
            return(await currentInstallation.Save());
        }
        public async void TestRefreshCurrentInstallationExceptionNoInstallationId()
        {
            // インスタレーションをストレージに保存(インスタレーションIDなし)
            SaveInstallationToStorage(false);

            // Main
            var installationResp = await NbSsePushInstallation.RefreshCurrentInstallation();
        }
Example #13
0
        public void TestGetCurrentInstallationNormalNotSaved()
        {
            // Main
            NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation();

            // Assert Equal Installation
            AssertAreEqualInstallation(null, currentInstallation);
        }
Example #14
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);
        }
        public void TestLoadFromStorageDeviceTokenNotExists()
        {
            // Main
            NbSsePushInstallation installation = new NbSsePushInstallation();

            installation.LoadFromStorage();

            CheckInstallation(installation, false);
            Assert.AreNotEqual("abcdefg", installation.DeviceToken);
        }
        public void TestGetCurrentInstallationNormalNotExists()
        {
            NbSsePushInstallation installation = new NbSsePushInstallation();

            // 2回実行
            for (var i = 0; i < 2; i++)
            {
                installation = NbSsePushInstallation.GetCurrentInstallation();
                CheckInstallation(installation, false);
            }
        }
        public void TestMakeRequestBodyNormal()
        {
            // インスタレーションに必須パラメータとオプションをセット
            NbSsePushInstallation installation = SetInstallationParameterAndOption();

            // Main
            NbJsonObject body = installation.MakeRequestBody();

            // Check Response
            CheckBody(body);
        }
        public void TestLoadFromStorageDeviceTokenExists()
        {
            // ストレージにインスタレーション情報を登録
            SaveInstallationToStorage(true);

            // Main
            NbSsePushInstallation installation = new NbSsePushInstallation();

            installation.LoadFromStorage();

            CheckInstallation(installation, true);
        }
        public async void TestSaveExceptionNoDeviceToken()
        {
            // インスタレーションに必須パラメータとオプションをセット
            NbSsePushInstallation installation = SetInstallationParameterAndOption();

            installation.DeviceToken = null;

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

            Assert.Fail("No Exception");
        }
        public async void TestSaveExceptionAllowedSendersNull()
        {
            // インスタレーションに必須パラメータとオプションをセット
            NbSsePushInstallation installation = SetInstallationParameterAndOption();

            installation.AllowedSenders = null;

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

            Assert.Fail("No Exception");
        }
Example #21
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);
        }
Example #22
0
        public async void TestDeleteInstallationNormal()
        {
            // Save Installation
            await ITUtil.UpsertInstallation();

            NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation();

            // Main
            await currentInstallation.DeleteInstallation();

            // Check Delete Storage
            CheckDeleteStorage();
        }
        public void TestGetCurrentInstallationNormalExists()
        {
            NbSsePushInstallation installation = new NbSsePushInstallation();

            SaveInstallationToStorage(true);

            // 2回実行
            for (var i = 0; i < 2; i++)
            {
                installation = NbSsePushInstallation.GetCurrentInstallation();
                CheckInstallation(installation, true);
            }
        }
Example #24
0
        public async void TestRefreshInstallationExceptionNotSaved()
        {
            // Main
            try
            {
                await NbSsePushInstallation.RefreshCurrentInstallation();

                Assert.Fail("No Exception");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual("Null installationId", e.Message);
            }
        }
Example #25
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);
 }
Example #26
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);
        }
        public async void TestSaveNormal()
        {
            // インスタレーションに必須パラメータとオプションをセット
            NbSsePushInstallation installation = SetInstallationParameterAndOption();

            var responseBody = CreateResponseBody(true);
            var response     = new MockRestResponse(HttpStatusCode.OK, responseBody.ToString());

            executor.AddResponse(response);

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

            // Check Response
            CheckInstallation(result);
            // インスタレーション内容チェック
            CheckInstallation(installation);

            // Check Request
            ISet <string> channels = new HashSet <string>();

            channels.Add("chan0");
            ISet <string> allowedSenders = new HashSet <string>();

            allowedSenders.Add("g:group1");

            var req     = executor.LastRequest;
            var reqJson = NbJsonParser.Parse(req.Content.ReadAsStringAsync().Result);

            Assert.AreEqual(HttpMethod.Post, req.Method);
            Assert.IsTrue(req.Uri.EndsWith("/installations"));
            Assert.AreEqual(3, req.Headers.Count);
            Assert.IsTrue(req.Headers.ContainsKey(appKey));
            Assert.IsTrue(req.Headers.ContainsKey(appId));
            Assert.AreEqual(reqJson["_osType"], "dotnet");
            Assert.AreEqual(reqJson["_osVersion"], "Unknown");
            Assert.AreEqual(reqJson["_deviceToken"], "abcdefg");
            Assert.AreEqual(reqJson["_pushType"], "sse");
            Assert.AreEqual(reqJson["_channels"], channels);
            Assert.AreEqual(reqJson["_appVersionCode"], -1);
            // NUnitの場合は"0"が設定される
            Assert.AreEqual(reqJson["_appVersionString"], "0");
            Assert.AreEqual(reqJson["_allowedSenders"], allowedSenders);
            Assert.AreEqual(reqJson["option1"], "option1value");
            Assert.AreEqual(reqJson["option2"], "option2value");

            // ストレージ内のインスタレーション情報存在チェック
            CheckSaveStorage();
        }
Example #28
0
        public async void TestDeleteInstallationExceptionNotSaved()
        {
            NbSsePushInstallation currentInstallation = NbSsePushInstallation.GetCurrentInstallation();

            // Main
            try
            {
                await currentInstallation.DeleteInstallation();

                Assert.Fail("No Exception");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual("Null installationId", e.Message);
            }
        }
        // インスタレーション情報を格納するファイルが保存されたかどうかチェック
        private void CheckSaveStorage()
        {
            try
            {
                System.IO.File.ReadAllText(InstallationFilename);
            }
            catch (System.IO.FileNotFoundException)
            {
                Assert.Fail("Storage Not Found");
            }

            // ストレージに保存されたインスタレーション内容が正しいかどうかチェック
            NbSsePushInstallation installation = new NbSsePushInstallation();

            installation.LoadFromStorage();
            CheckInstallation(installation);
        }
Example #30
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);
        }