private IEnumerable<PayloadReaderTestDescriptor> CreateCrossReferenceTestDescriptors(CrossReferenceTestCase testCase, ReaderTestConfiguration testConfiguration)
        {
            ExceptionUtilities.CheckArgumentNotNull(testCase, "testCase");

            var emptyPayload = new OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = new EdmModel().Fixup()
            };

            IEnumerable<OData.Common.PayloadTestDescriptor> operationPayloads = new[] { emptyPayload };

            // One of the operations in the test case may specify a reference link value to use to generate payloads
            string payloadReferenceLink = testCase.ChangeSets.SelectMany(cset => cset.Operations).Select(o => o.PayloadCrossReferenceLink).SingleOrDefault(s => !string.IsNullOrEmpty(s));
            if (payloadReferenceLink != null)
            {
                EdmModel testModel = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
                operationPayloads =
                    GeneratePayloadElementsWithCrossReferenceLinks(payloadReferenceLink, testConfiguration).Select(
                        p => new OData.Common.PayloadTestDescriptor
                        {
                            PayloadElement = p,
                            PayloadEdmModel = testModel,
                        });
            }

            var testDescriptors = new List<PayloadReaderTestDescriptor>();
            foreach (var payload in operationPayloads)
            {
                IEnumerable<IMimePart> requestChangesets = testCase.ChangeSets.Select(
                    c => (IMimePart)BatchUtils.GetRequestChangeset(
                        c.Operations.Select(o =>
                            {
                                // check whether we need to inject a payload into this operation
                                var operationPayload = string.IsNullOrEmpty(o.PayloadCrossReferenceLink) ? emptyPayload : payload;

                                ODataUri operationUri = new ODataUri(new[] { ODataUriBuilder.Unrecognized(o.Uri.OriginalString) });
                                var requestOperation = operationPayload.InRequestOperation(HttpVerb.Post, operationUri, this.RequestManager);
                                requestOperation.Headers.Add(HttpHeaders.ContentId, o.ContentId);

                                return (IMimePart)requestOperation;
                            }).ToArray(),
                        this.RequestManager));

                var testDescriptor = new PayloadReaderTestDescriptor(this.PayloadReaderSettings)
                {
                    DebugDescription = testCase.DebugDescription,
                    PayloadElement = PayloadBuilder.BatchRequestPayload(requestChangesets.ToArray()).AddAnnotation(new BatchBoundaryAnnotation("batch_foo")),
                    ExpectedException = testCase.ExpectedException,
                    SkipTestConfiguration = (testConfig) => !testConfig.IsRequest,
                };

                testDescriptors.Add(testDescriptor);
            }

            return testDescriptors;
        }
Beispiel #2
0
        private IEnumerable <PayloadReaderTestDescriptor> CreateCrossReferenceTestDescriptors(CrossReferenceTestCase testCase, ReaderTestConfiguration testConfiguration)
        {
            ExceptionUtilities.CheckArgumentNotNull(testCase, "testCase");

            var emptyPayload = new OData.Common.PayloadTestDescriptor()
            {
                PayloadEdmModel = new EdmModel().Fixup()
            };

            IEnumerable <OData.Common.PayloadTestDescriptor> operationPayloads = new[] { emptyPayload };

            // One of the operations in the test case may specify a reference link value to use to generate payloads
            string payloadReferenceLink = testCase.ChangeSets.SelectMany(cset => cset.Operations).Select(o => o.PayloadCrossReferenceLink).SingleOrDefault(s => !string.IsNullOrEmpty(s));

            if (payloadReferenceLink != null)
            {
                EdmModel testModel = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
                operationPayloads =
                    GeneratePayloadElementsWithCrossReferenceLinks(payloadReferenceLink, testConfiguration).Select(
                        p => new OData.Common.PayloadTestDescriptor
                {
                    PayloadElement  = p,
                    PayloadEdmModel = testModel,
                });
            }

            var testDescriptors = new List <PayloadReaderTestDescriptor>();

            foreach (var payload in operationPayloads)
            {
                IEnumerable <IMimePart> requestChangesets = testCase.ChangeSets.Select(
                    c => (IMimePart)BatchUtils.GetRequestChangeset(
                        c.Operations.Select(o =>
                {
                    // check whether we need to inject a payload into this operation
                    var operationPayload = string.IsNullOrEmpty(o.PayloadCrossReferenceLink) ? emptyPayload : payload;

                    ODataUri operationUri = new ODataUri(new[] { ODataUriBuilder.Unrecognized(o.Uri.OriginalString) });
                    var requestOperation  = operationPayload.InRequestOperation(HttpVerb.Post, operationUri, this.RequestManager);
                    requestOperation.Headers.Add(HttpHeaders.ContentId, o.ContentId);

                    return((IMimePart)requestOperation);
                }).ToArray(),
                        this.RequestManager));

                var testDescriptor = new PayloadReaderTestDescriptor(this.PayloadReaderSettings)
                {
                    DebugDescription      = testCase.DebugDescription,
                    PayloadElement        = PayloadBuilder.BatchRequestPayload(requestChangesets.ToArray()).AddAnnotation(new BatchBoundaryAnnotation("batch_foo")),
                    ExpectedException     = testCase.ExpectedException,
                    SkipTestConfiguration = (testConfig) => !testConfig.IsRequest,
                };

                testDescriptors.Add(testDescriptor);
            }

            return(testDescriptors);
        }