Ejemplo n.º 1
0
        public void TypedMetaTest(IEnumerable <UriPathDescriptor> linkDescriptors, string url, UriMetadata expectedResult)
        {
            // Arrange
            var urlParser = new UriPathScanf(linkDescriptors);

            // Act
            var result      = urlParser.ScanAll(url);
            var resultTyped = urlParser.Scan <UriPathScanfTestSource.TestTypedMetadata>(url);

            // Assert
            if (expectedResult != null)
            {
                result.UriType.Should().BeEquivalentTo(expectedResult.UriType);
                result.Type.Should().Be(expectedResult.Type);

                result.TryCast <UriPathScanfTestSource.TestTypedMetadata>(out var resultCasted);
                resultCasted.Should().BeEquivalentTo(expectedResult.Meta);

                resultTyped.Meta.Should().BeEquivalentTo(expectedResult.Meta);
            }
            else
            {
                result.Should().BeNull();
                resultTyped.Should().BeNull();
            }
        }
Ejemplo n.º 2
0
        public void NonScanTypeTest()
        {
            // Arrange
            const string uri = "/xxx/";

            var urlParser = new UriPathScanf(new []
            {
                new UriPathDescriptor(uri, "xxx", typeof(UriPathScanfTestSource.TestTypedMetadata)),
            });

            // Act
            var resultTyped     = urlParser.Scan <UriPathScanfTestSource.TestTypedMetadataFake>(uri);
            var resultDictTyped = urlParser.Scan(uri);

            // Assert
            resultTyped.Should().BeNull();
            resultDictTyped.Should().BeNull();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Example using <see cref="UriPathScanf.ScanAll"/>, <see cref="UriPathScanf.ScanAll{T}"/> and <see cref="UriPathScanf.Scan"/>
        /// </summary>
        public static void Go()
        {
            var descriptors = new[]
            {
                new UriPathDescriptor("/path/some/{varOne}", "varOneLink"),
                new UriPathDescriptor("/path/some/{someVar}/{someVar2}", "varTwoLink", typeof(Meta)),
                new UriPathDescriptor("/path/some/{someVar}/{someVar2}/{someVar3}", "varTwoLink", typeof(Meta)),
            };

            var uriPathScanf = new UriPathScanf(descriptors);

            // typed scan
            foreach (var u in new []
            {
                "/path/some/12314/xxx/",
                "/path/some/1/2/3x/",
            })
            {
                var result = uriPathScanf.Scan <Meta>(u);

                Debug.Assert(!string.IsNullOrEmpty(result.Meta.SomeVar));
                Debug.Assert(!string.IsNullOrEmpty(result.Meta.SomeVar2));
                Debug.Assert(string.IsNullOrEmpty(result.Meta.SomeVarQueryString));
            }

            // typed scan and not found
            var resultNonMeta = uriPathScanf.Scan <Meta>("/path/some/3");

            Debug.Assert(resultNonMeta == null);

            // dict scan and found
            var resultMetaDict = uriPathScanf.Scan("/path/some/3");

            Debug.Assert(resultMetaDict.Meta["varOne"] == "3");

            // dict scan and not found
            var resultNotDict = uriPathScanf.Scan("/path/some/3/4");

            Debug.Assert(resultNotDict == null);
        }