public void ParseGraphV1RequestUriWithKeysWorks()
        {
            var segments = PathParser.ParsePath("/drives/{drive-id}/items/{item-id}/permissions/{perm-id}", _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(6, segments.Count);
        }
        public void ParseGraphV1RequestUriWithKeysWorks2()
        {
            var segments = PathParser.ParsePath("/me/calendar/{id}/events/{id}/attachments/{id}", _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(6, segments.Count);
        }
        public int TestClosestWireFollow(string wire1Input, string wire2Input)
        {
            var wire1 = PathParser.ParsePath(wire1Input);
            var wire2 = PathParser.ParsePath(wire2Input);

            return(ClosestCrossSectionFinder.FindClosestViaWireCross(wire1, wire2));
        }
        public void ParseGraphV1RequestUriWorks(string requestUri, int count)
        {
            var segments = PathParser.ParsePath(requestUri, _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(count, segments.Count);
        }
        public int TestClosestManhattan(string wire1Input, string wire2Input)
        {
            var wire1 = PathParser.ParsePath(wire1Input);
            var wire2 = PathParser.ParsePath(wire2Input);

            return(ClosestCrossSectionFinder.FindClosestManhattanCross(wire1, wire2));
        }
        public void ParseGraphV1RequestUriWithKeysWorks6()
        {
            var segments = PathParser.ParsePath("me/drive/root/workbook/worksheets/{id}/range(address={address})/visibleView/rows", _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(9, segments.Count);
            Assert.Equal(PathKind.CollectionNavigation, segments.Kind);
        }
        public void ParseGraphV1RequestUriWithKeysWorks5()
        {
            var segments = PathParser.ParsePath("/users/{id | userPrincipalName}/reminderView(startDateTime=startDateTime-value,endDateTime=endDateTime-value)", _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(3, segments.Count);
            Assert.Equal(PathKind.Operation, segments.Kind);
        }
        public void ParseGraphV1RequestUriWithKeysWorks4()
        {
            var segments = PathParser.ParsePath("/me/drive/root/workbook/worksheets/{id}/range/resizedRange(deltaRows={n}, deltaColumns={n})", _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(8, segments.Count);
            Assert.Equal(PathKind.Operation, segments.Kind);
        }
        public void ParseGraphV1RequestUriWithKeysWorks3()
        {
            var segments = PathParser.ParsePath("/me/calendar", _edmModel);

            Assert.NotNull(segments);
            Assert.Equal(2, segments.Count);
            Assert.Equal(PathKind.SingleNavigation, segments.Kind);
        }
        /// <summary>
        /// Process the permissions by the IEdmModel.
        /// </summary>
        /// <param name="model">The Edm Model.</param>
        public void Process(IEdmModel model)
        {
            IDictionary <UriPath, IList <ApiPermissionType> > processed = new Dictionary <UriPath, IList <ApiPermissionType> >(new UriPathEqualityComparer());
            PathParserSettings settings = new PathParserSettings
            {
                EnableCaseInsensitive = true
            };

            foreach (var permission in ApiPermissions)
            {
                // Do Uri parser & save the invalid Uri into dictionary
                UriPath path;
                try
                {
                    path = PathParser.ParsePath(permission.Key, model, settings);
                }
                catch (Exception innerEx)
                {
                    UriParserError[permission.Key] = innerEx;
                    path = null;
                }

                if (path == null)
                {
                    continue;
                }

                if (processed.TryGetValue(path, out IList <ApiPermissionType> value))
                {
                    MergePermissions(value, permission.Value);
                    MergedRequests.Add(permission.Key);
                }
                else
                {
                    processed[path] = permission.Value;
                }
            }

            int index = 0;

            // for each property, navigation property segment
            foreach (var item in processed)
            {
                index++;

                PathSegment lastSegment = item.Key.LastSegment;
                if (lastSegment.Kind == SegmentKind.Property || lastSegment.Kind == SegmentKind.Navigation)
                {
                    // only process the property
                    TryFindPreviousPath(item, processed);
                }
            }

            ApiPermissionsProcessed = processed;
        }
        public void ParseEntitySetWorks()
        {
            string requestUri = "users";
            var    path       = PathParser.ParsePath(requestUri, _edmModel);

            Assert.NotNull(path);
            var pathSegment      = Assert.Single(path.Segments);
            var entitySetSegment = Assert.IsType <EntitySetSegment>(pathSegment);

            Assert.Same(entitySetSegment.EntitySet, _users);
        }
        public void StartsWithTwoRequestUriSame()
        {
            var path1 = PathParser.ParsePath("/users/{user-id}", _edmModel);
            var path2 = PathParser.ParsePath("/users/{user-id}/photo", _edmModel);

            Assert.False(path1.StartsWith(path2));
            Assert.True(path2.StartsWith(path1));
            Assert.True(path1.StartsWith(path1));

            Assert.Equal("~/users/{id}", path1.ToString());
            Assert.Equal("~/users/{id}/photo", path2.ToString());
        }
 public void ProcessByEdmModel(IEdmModel model, PathParserSettings settings)
 {
     RequestPath = null;
     try
     {
         RequestPath = PathParser.ParsePath(RequestUri, model, settings);
     }
     catch (Exception innerEx)
     {
         PaserError  = innerEx.Message;
         RequestPath = null;
     }
 }
        public void ParseAndCompareTwoRequestUriSame(string requestUri1, string requestUri2)
        {
            var path1 = PathParser.ParsePath(requestUri1, _edmModel);
            var path2 = PathParser.ParsePath(requestUri2, _edmModel);

            Assert.NotSame(path1, path2);
            Assert.False(path1.EqualsTo(null));
            Assert.False(path2.EqualsTo(null));

            Assert.True(path1.EqualsTo(path1));
            Assert.True(path2.EqualsTo(path2));
            Assert.True(path1.EqualsTo(path2));

            Assert.Equal("~/users/{id}", path1.ToString());
            Assert.Equal("~/users/{id}", path2.ToString());
        }