/// <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 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 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 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); }
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); }
public async void TestSaveInstallationExceptionNoDeviceToken() { 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; // Set DeviceToken Null currentInstallation.DeviceToken = null; // Main try { await currentInstallation.Save(); Assert.Fail("No Exception"); } catch (InvalidOperationException e) { Assert.AreEqual("Null DeviceToken.", e.Message); } }
// インスタレーションに必須パラメータとオプションを設定 private NbSsePushInstallation SetInstallationParameterAndOption() { NbSsePushInstallation installation = new NbSsePushInstallation(); ISet <string> channels = new HashSet <string>(); channels.Add("chan0"); installation.Channels = channels; ISet <string> allowedSenders = new HashSet <string>(); allowedSenders.Add("g:group1"); installation.AllowedSenders = allowedSenders; installation.DeviceToken = "abcdefg"; NbJsonObject options = new NbJsonObject(); options.Add("option1", "option1value"); options.Add("option2", "option2value"); installation.Options = options; return(installation); }
/// <summary> /// オプションフィールドを検索し、"options"キーに入れる /// </summary> /// <param name="json">NbJsonObject</param> /// <returns>修正されたNbJsonObject</returns> protected NbJsonObject ConvertJsonToOptionsIncluded(NbJsonObject json) { var modifiedJson = new NbJsonObject(); var option = new NbJsonObject(); //キーをListに変換する List <string> keysList = json.Keys.ToList(); foreach (string key in keysList) { if (IsKeyForOption(key)) { // オプションに格納 option.Add(key, json[key]); } else { // modifiedJsonにコピー modifiedJson.Add(key, json[key]); } } // オプションが存在する場合 if (option.Count() > 0) { // "options"キーに入れる modifiedJson[KeyOptions] = option; // 元のキー/値を削除 List <string> list = option.Keys.ToList(); foreach (string key in list) { modifiedJson.Remove(key); } } return(modifiedJson); }
private void FindOptions(string key, NbJsonObject json, NbJsonObject option) { switch (key) { case KeyOsType: case KeyOsVersion: case KeyDeviceToken: case KeyPushType: case KeyAppVersionString: case KeyId: case KeyOwner: case KeyAppVersionCode: case KeyChannels: case KeyAllowedSenders: case KeySse: // そのまま break; default: // それ以外はオプションとしてセット option.Add(key, json[key]); break; } }