示例#1
0
        public void RootUdiTest()
        {
            var stringUdi = new StringUdi(Constants.UdiEntityType.AnyString, string.Empty);

            Assert.IsTrue(stringUdi.IsRoot);
            Assert.AreEqual("umb://any-string/", stringUdi.ToString());

            var guidUdi = new GuidUdi(Constants.UdiEntityType.AnyGuid, Guid.Empty);

            Assert.IsTrue(guidUdi.IsRoot);
            Assert.AreEqual("umb://any-guid/00000000000000000000000000000000", guidUdi.ToString());

            var udi = Udi.Parse("umb://any-string/");

            Assert.IsTrue(udi.IsRoot);
            Assert.IsInstanceOf <StringUdi>(udi);

            udi = Udi.Parse("umb://any-guid/00000000000000000000000000000000");
            Assert.IsTrue(udi.IsRoot);
            Assert.IsInstanceOf <GuidUdi>(udi);

            udi = Udi.Parse("umb://any-guid/");
            Assert.IsTrue(udi.IsRoot);
            Assert.IsInstanceOf <GuidUdi>(udi);
        }
示例#2
0
    public void StringUdiCtorTest()
    {
        var udi = new StringUdi(Constants.UdiEntityType.AnyString, "test-id");

        Assert.AreEqual(Constants.UdiEntityType.AnyString, udi.EntityType);
        Assert.AreEqual("test-id", udi.Id);
        Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/test-id", udi.ToString());
    }
示例#3
0
        public void StringEncodingTest2()
        {
            // reserved = : / ? # [ ] @ ! $ & ' ( ) * + , ; =
            // unreserved = alpha digit - . _ ~
            Assert.AreEqual("%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2B%2C%3B%3D.-_~%25", Uri.EscapeDataString(":/?#[]@!$&'()+,;=.-_~%"));
            Assert.AreEqual(":/?#[]@!$&'()+,;=.-_~%25", Uri.EscapeUriString(":/?#[]@!$&'()+,;=.-_~%"));

            // we cannot have reserved chars at random places
            // we want to keep the / in string udis
            var r = string.Join("/", "path/to/View[1].cshtml".Split('/').Select(Uri.EscapeDataString));

            Assert.AreEqual("path/to/View%5B1%5D.cshtml", r);
            Assert.IsTrue(Uri.IsWellFormedUriString("umb://partial-view-macro/" + r, UriKind.Absolute));

            // with the proper fix in StringUdi this should work:
            var udi1 = new StringUdi("partial-view-macro", "path/to/View[1].cshtml");

            Assert.AreEqual("umb://partial-view-macro/path/to/View%5B1%5D.cshtml", udi1.ToString());
            Udi udi2 = UdiParser.Parse("umb://partial-view-macro/path/to/View%5B1%5D.cshtml");

            Assert.AreEqual("path/to/View[1].cshtml", ((StringUdi)udi2).Id);
        }
示例#4
0
        public void StringEncodingTest()
        {
            // absolute path is unescaped
            var uri = new Uri("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test");

            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/this is a test", uri.ToString());
            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test", uri.AbsoluteUri);
            Assert.AreEqual("/this%20is%20a%20test", uri.AbsolutePath);

            Assert.AreEqual("/this is a test", Uri.UnescapeDataString(uri.AbsolutePath));
            Assert.AreEqual("%2Fthis%20is%20a%20test", Uri.EscapeDataString("/this is a test"));
            Assert.AreEqual("/this%20is%20a%20test", Uri.EscapeUriString("/this is a test"));

            var udi = Udi.Parse("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test");

            Assert.AreEqual(Constants.UdiEntityType.AnyString, udi.EntityType);
            Assert.IsInstanceOf <StringUdi>(udi);
            var stringEntityId = udi as StringUdi;

            Assert.IsNotNull(stringEntityId);
            Assert.AreEqual("this is a test", stringEntityId.Id);
            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test", udi.ToString());

            var udi2 = new StringUdi(Constants.UdiEntityType.AnyString, "this is a test");

            Assert.AreEqual(udi, udi2);

            var udi3 = new StringUdi(Constants.UdiEntityType.AnyString, "path to/this is a test.xyz");

            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/path%20to/this%20is%20a%20test.xyz", udi3.ToString());
        }