Exemplo n.º 1
0
        /// <summary>
        /// Create new instance of <see cref="GraphUri"/>
        /// </summary>
        /// <param name="identity">Identity.</param>
        /// <param name="subEntity">Sub entity.</param>
        /// <param name="beta">Connect to beta endpoint.</param>
        internal GraphUri(IGraphIdentity identity, EntityPath subEntity, bool beta)
        {
            identity.ThrowIfNull(nameof(identity));
            subEntity.ThrowIfNull(nameof(subEntity));

            this.IsBeta   = beta;
            this.Identity = identity;
            this.restUri  = new HttpRestUri(
                $"{GraphUri.baseGraphUri}/{this.GetServiceInstance()}/{this.Identity.GetSubEntityFullPath(subEntity)}");
        }
Exemplo n.º 2
0
        public void Test_HttpRestUri()
        {
            HttpRestUri restUri = new HttpRestUri("https://localhost");

            Uri cast = restUri;
            Assert.AreEqual(
                "https://localhost/",
                cast.ToString());

            restUri.AddQueryParameter(
                "param1",
                10);

            cast = restUri;
            Assert.AreEqual(
                "https://localhost/?param1=10",
                cast.ToString());

            restUri.AddSegment("seg1");

            restUri.RemoveQueryParameter("param1");
            cast = restUri;
            Assert.AreEqual(
                "https://localhost/seg1",
                cast.ToString());

            restUri.AddSegment("seg2");
            restUri.AddSegment("seg3");
            restUri.RemoveSegment("seg1");

            restUri.AddQueryParameter("p1", "abc");
            restUri.AddQueryParameter("p2", 11);

            cast = restUri;
            Assert.AreEqual(
                "https://localhost/seg2/seg3?p1=abc&p2=11",
                cast.ToString());

            restUri.AddSegment("seg4");
            cast = restUri;
            Assert.AreEqual(
                "https://localhost/seg2/seg3/seg4?p1=abc&p2=11",
                cast.ToString());

            // Test 'immutability' of submitted url
            restUri = new HttpRestUri("https://localhost/seg1?p17=10");

            restUri.AddQueryParameter("test", "fff");
            restUri.AddQueryParameter("p17", 20);
            restUri.RemoveSegment("seg1");

            cast = restUri;
            Assert.AreEqual(
                "https://localhost/seg1?p17=10&test=fff",
                cast.ToString());

            restUri = new HttpRestUri("https://localhost/beta/me/u");

            string segment;
            Assert.IsTrue(
                restUri.TryGetSegment(
                    1,
                    out segment));

            Assert.AreEqual("beta", segment);

            Assert.IsFalse(
                restUri.TryGetSegment(
                    4,
                    out segment));

            restUri.AddSegment("tttt");

            Assert.IsTrue(
                restUri.TryGetSegment(
                    4,
                    out segment));

            Assert.AreEqual("tttt", segment);
        }