コード例 #1
0
        public void Write_Values_Success()
        {
            var jsonEntityChannel = new JsonEntity("Channel", "1", Json);

            Assert.IsTrue(string.Equals(jsonEntityChannel.GetProperty <string>("link"), "http://www.starwars.com", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityChannel.GetProperty <string>("description"), "Star Wars blog.", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityChannel.GetProperty <string>("title"), "Star Wars", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(jsonEntityChannel.GetCollection("item").Count == 0);

            jsonEntityChannel.SetProperty("link", "http://www.starwars.org");
            jsonEntityChannel.SetProperty("description", "Star Wars best blog.");
            jsonEntityChannel.SetProperty("title", "Star Wars is the best");

            Assert.IsTrue(string.Equals(jsonEntityChannel.GetProperty <string>("link"), "http://www.starwars.org", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityChannel.GetProperty <string>("description"), "Star Wars best blog.", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityChannel.GetProperty <string>("title"), "Star Wars is the best", StringComparison.OrdinalIgnoreCase));


            var jsonEntityAddress = jsonEntityChannel.GetEntity("address");

            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("line1"), "123 Main St", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("city"), "Los Angeles", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("state"), "CA", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("country"), "USA", StringComparison.OrdinalIgnoreCase));

            jsonEntityAddress.SetProperty("line1", "123 Strip St");
            jsonEntityAddress.SetProperty("city", "Las Vegas");
            jsonEntityAddress.SetProperty("state", "NV");

            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("line1"), "123 Strip St", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("city"), "Las Vegas", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(string.Equals(jsonEntityAddress.GetProperty <string>("state"), "NV", StringComparison.OrdinalIgnoreCase));
        }
コード例 #2
0
        public void Read_Values_MissingProperty()
        {
            var jsonEntityChannel = new JsonEntity("Channel", "1", Json);

            Assert.Throws <Exception>(() => jsonEntityChannel.GetCollection("missing"));
            Assert.Throws <Exception>(() => jsonEntityChannel.GetEntity("missing"));
            Assert.Throws <Exception>(() => jsonEntityChannel.GetProperty <string>("missing"));
        }