Esempio n. 1
0
        private MatcherEndpoint CreateEndpoint(
            string template,
            object defaults       = null,
            object requiredValues = null,
            int order             = 0,
            string routeName      = null,
            EndpointMetadataCollection metadataCollection = null)
        {
            if (metadataCollection == null)
            {
                var metadata = new List <object>();
                if (!string.IsNullOrEmpty(routeName) || requiredValues != null)
                {
                    metadata.Add(new RouteValuesAddressMetadata(routeName, new RouteValueDictionary(requiredValues)));
                }
                metadataCollection = new EndpointMetadataCollection(metadata);
            }

            return(new MatcherEndpoint(
                       MatcherEndpoint.EmptyInvoker,
                       RoutePatternFactory.Parse(template, defaults, constraints: null),
                       order,
                       metadataCollection,
                       null));
        }
        private MatcherEndpoint CreateEndpoint(
            string template,
            object defaults       = null,
            object requiredValues = null,
            int order             = 0,
            string routeName      = null,
            EndpointMetadataCollection metadataCollection = null)
        {
            if (metadataCollection == null)
            {
                metadataCollection = EndpointMetadataCollection.Empty;
                if (!string.IsNullOrEmpty(routeName))
                {
                    metadataCollection = new EndpointMetadataCollection(new[] { new RouteNameMetadata(routeName) });
                }
            }

            return(new MatcherEndpoint(
                       MatcherEndpoint.EmptyInvoker,
                       RoutePatternFactory.Parse(template, defaults, constraints: null),
                       new RouteValueDictionary(requiredValues),
                       order,
                       metadataCollection,
                       null));
        }
        private RouteEndpoint CreateEndpoint(
            string template,
            object defaults = null,
            object metadataRequiredValues = null,
            int order        = 0,
            string routeName = null,
            EndpointMetadataCollection metadataCollection = null)
        {
            if (metadataCollection == null)
            {
                var metadata = new List <object>();
                if (!string.IsNullOrEmpty(routeName))
                {
                    metadata.Add(new RouteNameMetadata(routeName));
                }
                metadataCollection = new EndpointMetadataCollection(metadata);
            }

            return(new RouteEndpoint(
                       TestConstants.EmptyRequestDelegate,
                       RoutePatternFactory.Parse(template, defaults, parameterPolicies: null, requiredValues: metadataRequiredValues),
                       order,
                       metadataCollection,
                       null));
        }
Esempio n. 4
0
 protected Endpoint(
     EndpointMetadataCollection metadata,
     string displayName)
 {
     // All are allowed to be null
     Metadata    = metadata ?? EndpointMetadataCollection.Empty;
     DisplayName = displayName;
 }
        public void GetOrderedMetadata_CanReturnEmptyCollection()
        {
            // Arrange
            var metadata = new EndpointMetadataCollection(1, 2, 3);

            // Act
            var ordered = metadata.GetOrderedMetadata <string>();

            Assert.Same(Array.Empty <string>(), ordered);
        }
        public void GetOrderedMetadata_CanReturnNonEmptyCollection()
        {
            // Arrange
            var metadata = new EndpointMetadataCollection("1", "2");

            // Act
            var ordered1 = metadata.GetOrderedMetadata <string>();
            var ordered2 = metadata.GetOrderedMetadata <string>();

            Assert.Same(ordered1, ordered2);
            Assert.Equal(new string[] { "1", "2" }, ordered1);
        }
        public void Constructor_ParamsArray_ContainsValues()
        {
            // Arrange & Act
            var metadata = new EndpointMetadataCollection(1, 2, 3);

            // Assert
            Assert.Equal(3, metadata.Count);

            Assert.Collection(metadata,
                              value => Assert.Equal(1, value),
                              value => Assert.Equal(2, value),
                              value => Assert.Equal(3, value));
        }
        public void Constructor_Enumeration_ContainsValues()
        {
            // Arrange & Act
            var metadata = new EndpointMetadataCollection(new List <object>
            {
                1,
                2,
                3,
            });

            // Assert
            Assert.Equal(3, metadata.Count);

            Assert.Collection(metadata,
                              value => Assert.Equal(1, value),
                              value => Assert.Equal(2, value),
                              value => Assert.Equal(3, value));
        }
        public void GetMetadata_NoMatch_ReturnsNull()
        {
            // Arrange
            var items = new object[]
            {
                new Metadata3(),
                new Metadata3(),
                new Metadata3(),
            };

            var metadata = new EndpointMetadataCollection(items);

            // Act
            var result = metadata.GetMetadata <IMetadata5>();

            // Assert
            Assert.Null(result);
        }
        public void GetMetadata_Match_ReturnsLastMatchingEntry()
        {
            // Arrange
            var items = new object[]
            {
                new Metadata1(),
                new Metadata2(),
                new Metadata3(),
            };

            var metadata = new EndpointMetadataCollection(items);

            // Act
            var result = metadata.GetMetadata <IMetadata5>();

            // Assert
            Assert.Same(items[1], result);
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RouteEndpoint"/> class.
        /// </summary>
        /// <param name="requestDelegate">The delegate used to process requests for the endpoint.</param>
        /// <param name="routePattern">The <see cref="RoutePattern"/> to use in URL matching.</param>
        /// <param name="order">The order assigned to the endpoint.</param>
        /// <param name="metadata">
        /// The <see cref="EndpointMetadataCollection"/> or metadata associated with the endpoint.
        /// </param>
        /// <param name="displayName">The informational display name of the endpoint.</param>
        public RouteEndpoint(
            RequestDelegate requestDelegate,
            RoutePattern routePattern,
            int order,
            EndpointMetadataCollection metadata,
            string displayName)
            : base(requestDelegate, metadata, displayName)
        {
            if (requestDelegate == null)
            {
                throw new ArgumentNullException(nameof(requestDelegate));
            }

            if (routePattern == null)
            {
                throw new ArgumentNullException(nameof(routePattern));
            }

            RoutePattern = routePattern;
            Order        = order;
        }
        public void GetOrderedMetadata_Match_ReturnsItemsInAscendingOrder()
        {
            // Arrange
            var items = new object[]
            {
                new Metadata1(),
                new Metadata2(),
                new Metadata3(),
            };

            var metadata = new EndpointMetadataCollection(items);

            // Act
            var result = metadata.GetOrderedMetadata <IMetadata5>();

            // Assert
            Assert.Collection(
                result,
                i => Assert.Same(items[0], i),
                i => Assert.Same(items[1], i));
        }
        public void Setup()
        {
            var seeds = new Type[]
            {
                typeof(Metadata1),
                typeof(Metadata2),
                typeof(Metadata3),
                typeof(Metadata4),
                typeof(Metadata5),
                typeof(Metadata6),
                typeof(Metadata7),
                typeof(Metadata8),
                typeof(Metadata9),
            };

            _items = new object[Count];
            for (var i = 0; i < _items.Length; i++)
            {
                _items[i] = seeds[i % seeds.Length];
            }

            _collection = new EndpointMetadataCollection(_items);
        }
Esempio n. 14
0
        public static MatcherEndpoint CreateMatcherEndpoint(
            string template,
            object defaults       = null,
            object constraints    = null,
            object requiredValues = null,
            int order             = 0,
            string displayName    = null,
            params object[] metadata)
        {
            var metadataCollection = EndpointMetadataCollection.Empty;

            if (metadata != null)
            {
                metadataCollection = new EndpointMetadataCollection(metadata);
            }

            return(new MatcherEndpoint(
                       MatcherEndpoint.EmptyInvoker,
                       RoutePatternFactory.Parse(template, defaults, constraints),
                       new RouteValueDictionary(requiredValues),
                       order,
                       metadataCollection,
                       displayName));
        }