Ejemplo n.º 1
0
        public static void UriWorks()
        {
            var uri = new Uri("http://myurl.com");

            Assert.AreEqual(uri.AbsoluteUri, JsonConvert.DeserializeObject <Uri>("\"" + uri.AbsoluteUri + "\"").AbsoluteUri);

            var t1   = new UriContainer(new Uri("http://www.mysite.com"));
            var json = JsonConvert.SerializeObject(t1);
            var t2   = JsonConvert.DeserializeObject <UriContainer>(json);

            Assert.AreEqual("http://www.mysite.com", t2.WebsiteUrl.AbsoluteUri);
            Assert.AreEqual(t1.WebsiteUrl.AbsoluteUri, t2.WebsiteUrl.AbsoluteUri);
        }
        public void CheckCloneUri()
        {
            var model = TypeModel.Create();

            UriContainer c;

            var uri = new Uri("http://localhost");

            c = new UriContainer()
            {
                Uris = Enumerable.Range(0, 10).Select(x => uri).ToArray()
            };
            var clone = model.DeepClone(c);

            Assert.IsTrue(c.Uris.SequenceEqual(clone.Uris));
        }
        public void ExecuteUri()
        {
            var model = TypeModel.Create();

            using (var ms = new MemoryStream())
            {
                UriContainer c;
                var          uri = new Uri("http://localhost");
                c = new UriContainer()
                {
                    Uris = Enumerable.Range(0, 2).Select(x => uri).ToArray()
                };

                model.Serialize(ms, c);

                ms.Position = 0;

                var d = model.Deserialize <UriContainer>(ms);
                Assert.AreSame(c.Uris[0], c.Uris[1]);
                Assert.AreSame(d.Uris[0], d.Uris[1]);
            }
        }