示例#1
0
        public static void InitializeAndValidate_ThrowsOnRelativeUri()
        {
            Uri           uri    = new Uri("foo", UriKind.Relative);
            TestUriParser parser = new TestUriParser();

            Assert.Throws <InvalidOperationException>(() => parser.DangerousExposed_InitializeAndValidate(uri, out _));
        }
示例#2
0
        public static void InitializeAndValidate_ThrowsOnUriOfDifferentScheme()
        {
            Uri           uri    = new Uri(FullHttpUri);
            TestUriParser parser = new TestUriParser();

            Assert.Throws <InvalidOperationException>(() => parser.DangerousExposed_InitializeAndValidate(uri, out _));
        }
示例#3
0
        public static void InitializeAndValidate_ThrowsIfCalledOutsideOfConstructorOrMultipleTimes()
        {
            TestUriParser parser = new TestUriParser();

            UriParser.Register(parser, "test-scheme", 12345);

            // Does not throw if called once from the constructor
            parser.BaseInitializeAndValidateCallCount = 1;
            Uri uri = new Uri("test-scheme://foo.bar");

            // Throws if called multiple times
            parser.BaseInitializeAndValidateCallCount = 2;
            Assert.Throws <InvalidOperationException>(() => new Uri("test-scheme://foo.bar"));

            // Throws if called after the constructor
            parser.BaseInitializeAndValidateCallCount = 0;
            uri = new Uri("test-scheme://foo.bar");
            parser.BaseInitializeAndValidateCallCount = 1;
            Assert.Throws <InvalidOperationException>(() => parser.DangerousExposed_InitializeAndValidate(uri, out _));
        }