Ejemplo n.º 1
0
        public void XmlBaseUriHandlingTest()
        {
            var testCases = new XmlBaseUriTestCase[]
            {
                new XmlBaseUriTestCase
                {
                    RelativeUri = "relative",
                    XmlBaseUri = "http://odata.org/base",
                    SettingsBaseUri = (string)null,
                    ResultUri = "http://odata.org/relative",
                },
                new XmlBaseUriTestCase
                {
                    RelativeUri = "relative",
                    XmlBaseUri = (string)null,
                    SettingsBaseUri = (string)null,
                    ResultUri = "http://odata.org/relative",
                },
                new XmlBaseUriTestCase
                {
                    RelativeUri = "relative",
                    XmlBaseUri = "/baserelative/",
                    SettingsBaseUri = "http://odata.org/base",
                    ResultUri = "http://odata.org/baserelative/relative"
                },
                new XmlBaseUriTestCase
                {
                    RelativeUri = "relative",
                    XmlBaseUri = string.Empty,
                    SettingsBaseUri = "http://odata.org/",
                    ResultUri = "http://odata.org/relative"
                },
                new XmlBaseUriTestCase
                {
                    RelativeUri = "relative",
                    XmlBaseUri = "/baserelative/",
                    SettingsBaseUri = "http://odata.org/base/",
                    ResultUri = "http://odata.org/baserelative/relative"
                },
                new XmlBaseUriTestCase
                {
                    RelativeUri = "relative",
                    XmlBaseUri = string.Empty,
                    SettingsBaseUri = "http://odata.org/base/",
                    ResultUri = "http://odata.org/base/relative"
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                TestReaderUtils.ODataBehaviorKinds,
                (testCase, testConfiguration, behavior) =>
                {
                    IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
                    {
                        // MLE with relative media source link
                        new PayloadReaderTestDescriptor(this.Settings)
                        {
                            PayloadElement = PayloadBuilder.Entity().AsMediaLinkEntry().StreamSourceLink(testCase.ComputeExpectedResultUri(behavior, testConfiguration.Version, /*ignoredOnServer*/ true))
                                .XmlRepresentation("<entry xml:base='" + testCase.XmlBaseUri + "'><content src='" + testCase.RelativeUri +"'/></entry>"),
                            ExpectedException = testCase.ComputeExpectedException(behavior, testConfiguration.Version, /*ignoredOnServer*/ true)
                        },

                        // Navigation link with relative href
                        new PayloadReaderTestDescriptor(this.Settings)
                        {
                            PayloadElement = PayloadBuilder.Entity()
                                .NavigationProperty("NavLink", testCase.ComputeExpectedResultUri(behavior, testConfiguration.Version, /*ignoredOnServer*/ false))
                                .XmlRepresentation("<entry xml:base='" + testCase.XmlBaseUri + "'><content /><link rel='http://docs.oasis-open.org/odata/ns/related/NavLink' type='application/atom+xml;type=entry' title='NavLink' href='" + testCase.RelativeUri + "' /></entry>"),
                            ExpectedException = testCase.ComputeExpectedException(behavior, testConfiguration.Version, /*ignoredOnServer*/ false)
                        },

                        // TODO: Add tests like this for all URLs we can process, including ATOM Metadata ones!
                    };

                    this.CombinatorialEngineProvider.RunCombinations(
                        testDescriptors,
                        testDescriptor =>
                        {
                            // Clone the test configuration and set base URI and behavior.
                            testConfiguration = new ReaderTestConfiguration(testConfiguration);
                            testConfiguration.MessageReaderSettings.BaseUri = testCase.SettingsBaseUri == null ? null : new Uri(testCase.SettingsBaseUri);
                            testConfiguration = testConfiguration.CloneAndApplyBehavior(behavior);

                            testDescriptor.RunTest(testConfiguration);
                        });
                });
        }
Ejemplo n.º 2
0
        public void SpatialPropertyWithDisabledPrimitiveTypeConversionTest()
        {
            IEdmModel testModel = TestModels.BuildTestModel();

            var testValues = new object[]
                {
                    GeographyFactory.Point(10, 20).Build(),
                    GeometryFactory.Point(10, 20).Build()
                };

            IEnumerable<PayloadReaderTestDescriptor> testDescriptors =
                TestValues.PrimitiveTypes.SelectMany(primitiveTypes => testValues.Select(testValue =>
                {
                    PrimitiveDataType targetType = EntityModelUtils.GetPrimitiveEdmType(primitiveTypes);
                    ODataPayloadElement payloadElement = PayloadBuilder
                        .Property(null, PayloadBuilder.PrimitiveValue(testValue))
                        .ExpectedPropertyType(targetType);
                    return new PayloadReaderTestDescriptor(this.Settings)
                    {
                        PayloadElement = payloadElement,
                        PayloadEdmModel = testModel
                    };
                }));

            // TODO: Task 1429690:Fix places where we've lost JsonVerbose coverage to add JsonLight
            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                new bool[] { false, true },
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => tc.Format == ODataFormat.Atom),
                (testDescriptor, disableStrictValidation, testConfig) =>
                {
                    testConfig = new ReaderTestConfiguration(testConfig);
                    testConfig.MessageReaderSettings.DisablePrimitiveTypeConversion = true;
                    if (disableStrictValidation)
                    {
                        testConfig = testConfig.CloneAndApplyBehavior(TestODataBehaviorKind.WcfDataServicesServer);
                    }
                    testDescriptor.RunTest(testConfig);
                });
        }