public void TestStronglyTyped() { ToastArguments args = new ToastArguments() .Add("isAdult", true) .Add("isPremium", false) .Add("age", 22) .Add("level", 0) .Add("gpa", 3.97) .Add("percent", 97.3f); #if !WINRT args.Add("activationKind", ToastActivationType.Background); #endif AssertEqual( new ToastArguments() { { "isAdult", "1" }, { "isPremium", "0" }, { "age", "22" }, { "level", "0" }, { "gpa", "3.97" }, { "percent", "97.3" }, #if !WINRT { "activationKind", "1" } #endif }, args); Assert.AreEqual(true, args.GetBool("isAdult")); Assert.AreEqual("1", args.Get("isAdult")); Assert.AreEqual(false, args.GetBool("isPremium")); Assert.AreEqual("0", args.Get("isPremium")); Assert.AreEqual(22, args.GetInt("age")); Assert.AreEqual(22d, args.GetDouble("age")); Assert.AreEqual(22f, args.GetFloat("age")); Assert.AreEqual("22", args.Get("age")); Assert.AreEqual(0, args.GetInt("level")); Assert.AreEqual(3.97d, args.GetDouble("gpa")); Assert.AreEqual(97.3f, args.GetFloat("percent")); #if !WINRT Assert.AreEqual(ToastActivationType.Background, args.GetEnum <ToastActivationType>("activationKind")); if (args.TryGetValue("activationKind", out ToastActivationType activationType)) { Assert.AreEqual(ToastActivationType.Background, activationType); } else { Assert.Fail("TryGetValue as enum failed"); } // Trying to get enum that isn't an enum should return false Assert.IsFalse(args.TryGetValue("percent", out activationType)); #endif // After serializing and deserializing, the same should work args = ToastArguments.Parse(args.ToString()); Assert.AreEqual(true, args.GetBool("isAdult")); Assert.AreEqual("1", args.Get("isAdult")); Assert.AreEqual(false, args.GetBool("isPremium")); Assert.AreEqual("0", args.Get("isPremium")); Assert.AreEqual(22, args.GetInt("age")); Assert.AreEqual(22d, args.GetDouble("age")); Assert.AreEqual(22f, args.GetFloat("age")); Assert.AreEqual("22", args.Get("age")); Assert.AreEqual(0, args.GetInt("level")); Assert.AreEqual(3.97d, args.GetDouble("gpa")); Assert.AreEqual(97.3f, args.GetFloat("percent")); #if !WINRT Assert.AreEqual(ToastActivationType.Background, args.GetEnum <ToastActivationType>("activationKind")); if (args.TryGetValue("activationKind", out activationType)) { Assert.AreEqual(ToastActivationType.Background, activationType); } else { Assert.Fail("TryGetValue as enum failed"); } // Trying to get enum that isn't an enum should return false Assert.IsFalse(args.TryGetValue("percent", out activationType)); #endif }