public void BatchReaderPayloadKindDetectionAtomTest() { // TODO: once we can register custom formats for content type multipart/mixed add more tests here // since currently we will never hit the actual payload kind detection code. // Test cases PayloadKindDetectionResult batchResult = new PayloadKindDetectionResult(ODataPayloadKind.Batch, ODataFormat.Batch); Func <ReaderTestConfiguration, IEnumerable <PayloadKindDetectionResult> > batchDetectionResult = testConfig => new PayloadKindDetectionResult[] { batchResult }; // NOTE: we currently only use the content type header to determine whether something is a batch payload or not. // We require a 'multipart/mixed' content type and a 'boundary' parameter var testDescriptors = new PayloadKindDetectionTestDescriptor[] { // Correct content type header new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "multipart/mixed;boundary=b", PayloadString = "Does not matter", ExpectedDetectionResults = batchDetectionResult, }, // Correct content type header with additional parameters after boundary new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "multipart/mixed;boundary=b;a=c;d=e", PayloadString = "Does not matter", ExpectedDetectionResults = batchDetectionResult, }, // Correct content type header with additional parameters before boundary new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "multipart/mixed;a=c;d=e;boundary=b", PayloadString = "Does not matter", ExpectedDetectionResults = batchDetectionResult, }, // Unsupported content type new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "multipart/invalid", PayloadString = "Does not matter", ExpectedDetectionResults = testConfig => Enumerable.Empty <PayloadKindDetectionResult>(), }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.DefaultFormatConfigurations, (testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration)); }
public void PayloadKindDetectionInServerBehaviorAtomTest() { var testDescriptors = new PayloadKindDetectionTestDescriptor[] { // Arbitrary payload string; in WCF DS server mode we should always throw. new PayloadKindDetectionTestDescriptor(this.Settings) { ContentType = "application/atom+xml", PayloadString = "<" + TestAtomConstants.AtomEntryElementName + " xmlns=\"" + TestAtomConstants.AtomNamespace + "\" />", ExpectedException = ODataExpectedExceptions.ODataException("ODataMessageReader_PayloadKindDetectionInServerMode") }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration.CloneAndApplyBehavior(TestODataBehaviorKind.WcfDataServicesServer))); }
public void PayloadKindDetectionRequestJsonLightTest() { IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel(); var testDescriptors = new PayloadKindDetectionTestDescriptor[] { new PayloadKindDetectionTestDescriptor(this.Settings) { DebugDescription = "Simple entry; but since in request it will fail.", ContentType = "application/json;odata.metadata=minimal", PayloadEdmModel = model, PayloadString = string.Format("{{ \"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\": \"{0}\" }}", metadataDocumentUri + "#TestModel.DefaultContainer.Persons/$entity"), ExpectedDetectionResults = emptyDetectionResult, ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_PayloadKindDetectionForRequest") }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => tc.IsRequest), (testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration)); }
public void MetadataDocumentReaderPayloadKindDetectionTest() { // Test cases PayloadKindDetectionResult metadataResult = new PayloadKindDetectionResult(ODataPayloadKind.MetadataDocument, ODataFormat.Metadata); IEnumerable <PayloadKindDetectionResult> metadataDetectionResult = new PayloadKindDetectionResult[] { metadataResult }; IEnumerable <PayloadKindDetectionResult> emptyDetectionResult = Enumerable.Empty <PayloadKindDetectionResult>(); var testDescriptors = new PayloadKindDetectionTestDescriptor[] { // Correct element new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "application/xml", PayloadString = "<edmx:" + ODataCommon.EdmConstants.EdmxName + " xmlns:edmx = \"" + ODataCommon.EdmConstants.EdmxOasisNamespace + "\" />", ExpectedDetectionResults = testConfig => testConfig.IsRequest ? emptyDetectionResult : metadataDetectionResult, }, // Non-metadata top-level element new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "application/xml", PayloadString = "<metadata />", ExpectedDetectionResults = testConfig => emptyDetectionResult, }, // Top-level element in correct namespace but with wrong name new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "application/xml", PayloadString = "<edmx:metadata xmlns:edmx = \"" + ODataCommon.EdmConstants.EdmxOasisNamespace + "\" />", ExpectedDetectionResults = testConfig => emptyDetectionResult, }, // Non-Xml content new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "application/xml", PayloadString = "Some non-Xml content", ExpectedDetectionResults = testConfig => emptyDetectionResult, }, // Unsupported content type new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "application/invalid", PayloadString = "<edmx:" + ODataCommon.EdmConstants.EdmxName + " xmlns:edmx = \"" + ODataCommon.EdmConstants.EdmxOasisNamespace + "\" />", ExpectedDetectionResults = testConfig => emptyDetectionResult, }, // Correct element with leading nodes that should be ignored new PayloadKindDetectionTestDescriptor(this.PayloadKindDetectionSettings) { ContentType = "application/xml", PayloadString = "<!-- Comment -->" + "<?pi Ignore this?>" + "<edmx:" + ODataCommon.EdmConstants.EdmxName + " xmlns:edmx = \"" + ODataCommon.EdmConstants.EdmxOasisNamespace + "\" />", ExpectedDetectionResults = testConfig => testConfig.IsRequest ? emptyDetectionResult : metadataDetectionResult, }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations.Where(tc => tc.Synchronous), (testDescriptor, testConfiguration) => testDescriptor.RunTest(testConfiguration)); }