private void CheckRequest()
        {
            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);
            NbJsonObject reqFullUpdateJson = (NbJsonObject)reqJson["$full_update"];

            Assert.AreEqual(HttpMethod.Put, 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));
            Assert.AreEqual(reqFullUpdateJson["_osType"], "dotnet");
            Assert.AreEqual(reqFullUpdateJson["_osVersion"], "Unknown");
            Assert.AreEqual(reqFullUpdateJson["_deviceToken"], "abcdefg");
            Assert.AreEqual(reqFullUpdateJson["_pushType"], "sse");
            Assert.AreEqual(reqFullUpdateJson["_channels"], channels);
            Assert.AreEqual(reqFullUpdateJson["_appVersionCode"], -1);
            // NUnitの場合は"0"が設定される
            Assert.AreEqual(reqFullUpdateJson["_appVersionString"], "0");
            Assert.AreEqual(reqFullUpdateJson["_allowedSenders"], allowedSenders);
            Assert.AreEqual(reqFullUpdateJson["option1"], "option1value");
            Assert.AreEqual(reqFullUpdateJson["option2"], "option2value");
        }
Пример #2
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");
        }
        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();
        }