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)); }
/// <summary> /// Gets The model to use for the specified test configuration. /// </summary> /// <param name="testConfiguration">The test configuration to use.</param> /// <returns>The model to use for the test.</returns> protected override IEdmModel GetMetadataProvider(ReaderTestConfiguration testConfiguration) { IEdmModel model = base.GetMetadataProvider(testConfiguration); if (model != null) { return(model); } // NOTE: get the model from the first result (if any) as the model for the message writer. // This message writer will be used to validate the first result only. PayloadKindDetectionResult firstResult = this.ExpectedDetectionResults == null ? null : this.ExpectedDetectionResults(testConfiguration).FirstOrDefault(); return(firstResult == null ? null : firstResult.Model); }
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)); }