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

            var res          = new Mock <HttpWebResponse>();
            var responseBody = CreateBody(true, true);
            var response     = new MockRestResponse(HttpStatusCode.OK, responseBody.ToString());

            executor.AddResponse(response);

            // Main
            client.AutoRecovery(HttpStatusCode.Unauthorized, res.Object);

            // Check Request
            CheckRequest();

            // ストレージ内のインスタレーション情報存在チェック
            CheckSaveStorage();

            // Check ReleaseLock
            try
            {
                // AcquireLock()でExceptionが起きないことを確認
                NbSsePushReceiveClient.AcquireLock();
            }
            catch (Exception)
            {
                Assert.Fail("Exception");
            }

            NbSsePushReceiveClient.ReleaseLock();
        }
        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();
        }
        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();
        }
Exemplo n.º 4
0
        public async void TestSendRequestForRefreshNormal()
        {
            SaveInstallationToStorage(true);
            installation.LoadFromStorage();
            var installationId = installation.InstallationId;

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

            executor.AddResponse(response);

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

            // Check Response
            Assert.AreEqual(result, responseBody);

            // Check Request
            var req = executor.LastRequest;

            Assert.AreEqual(HttpMethod.Get, req.Method);
            Assert.IsTrue(req.Uri.EndsWith("/installations/" + installationId));
            Assert.AreEqual(3, req.Headers.Count);
            Assert.IsTrue(req.Headers.ContainsKey(appKey));
            Assert.IsTrue(req.Headers.ContainsKey(appId));
        }
        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);
        }
Exemplo n.º 6
0
        public async void TestSendRequestForSaveNormal()
        {
            SaveInstallationToStorage(false);
            installation.LoadFromStorage();

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

            executor.AddResponse(response);

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

            // Check Response
            Assert.AreEqual(result, responseBody);

            // Check Request
            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["_channels"], installation.Channels);
            Assert.AreEqual(reqJson["_allowedSenders"], installation.AllowedSenders);
            Assert.AreEqual(reqJson["_osType"], installation.OsType);
            Assert.AreEqual(reqJson["_osVersion"], installation.OsVersion);
            Assert.AreEqual(reqJson["_deviceToken"], installation.DeviceToken);
            Assert.AreEqual(reqJson["_appVersionCode"], installation.AppVersionCode);
            // NUnitの場合は"0"が設定される
            Assert.AreEqual(reqJson["_appVersionString"], "0");
        }
Exemplo n.º 7
0
        public async void TestDeleteInstallationExceptionNoInstallationOnServer()
        {
            SaveInstallationToStorage(true);
            installation.LoadFromStorage();

            var response = new MockRestResponse(HttpStatusCode.NotFound);

            executor.AddResponse(response);

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

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

                // Check Delete Storage
                CheckDeleteStorage();

                // Check Delete Installation
                CheckDeleteInstallation(installation);
            }
        }
Exemplo n.º 8
0
        public async void TestDeleteInstallationNormal()
        {
            SaveInstallationToStorage(true);
            installation.LoadFromStorage();
            var installationId = installation.InstallationId;

            var response = new MockRestResponse(HttpStatusCode.OK);

            executor.AddResponse(response);

            // Main
            await installation.DeleteInstallation();

            // Check Request
            var req = executor.LastRequest;

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

            // Check Delete Storage
            CheckDeleteStorage();

            // Check Delete Installation
            CheckDeleteInstallation(installation);
        }
        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();
        }
Exemplo n.º 10
0
        public async void TestSendRequestForRefreshExceptionFailer()
        {
            SaveInstallationToStorage(true);
            installation.LoadFromStorage();

            var response = new MockRestResponse(HttpStatusCode.Forbidden);

            executor.AddResponse(response);

            try
            {
                // Main
                var result = await installation.SendRequestForRefresh();

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