private void CreateTestDescriptorsAndRunTests(FeedMetadataTestCase[] testCases, Func <PayloadWriterTestDescriptor <ODataItem>, IEnumerable <PayloadWriterTestDescriptor <ODataItem> > > payloads)
        {
            // Convert test cases to test descriptions
            IEnumerable <Func <ODataFeed> > feedCreators = new Func <ODataFeed>[] { () => ObjectModelUtils.CreateDefaultFeed(), () => ObjectModelUtils.CreateDefaultFeedWithAtomMetadata(), };
            var testDescriptors = testCases.SelectMany(testCase => feedCreators.Select(feedCreator =>
            {
                ODataFeed feed            = feedCreator();
                AtomFeedMetadata metadata = feed.Atom();
                this.Assert.IsNotNull(metadata, "Expected default feed metadata on a default feed.");
                testCase.CustomizeMetadata(metadata);
                ODataItem[] payloadItems = testCase.CustomizePayload == null ? new ODataItem[] { feed } : testCase.CustomizePayload(feed);
                return(new PayloadWriterTestDescriptor <ODataItem>(this.Settings, payloadItems, testConfiguration =>
                {
                    if (testCase.SkipTestConfiguration != null && testCase.SkipTestConfiguration(testConfiguration))
                    {
                        return null;
                    }
                    return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                    {
                        Xml = testCase.Xml, FragmentExtractor = testCase.Extractor, ExpectedException2 = testCase.ExpectedException
                    };
                }));
            }));

            this.CombinatorialEngineProvider.RunCombinations(testDescriptors.PayloadCases(WriterPayloads.TopLevelValuePayload), this.WriterTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) =>
            {
                testConfiguration = testConfiguration.Clone();
                testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger);
            });
        }
            public override ODataFeed CreateODataFeed(IEnumerable feedInstance, ODataSerializerContext writeContext)
            {
                ODataFeed feed = base.CreateODataFeed(feedInstance, writeContext);

                feed.Atom().Title = new AtomTextConstruct {
                    Kind = AtomTextConstructKind.Text, Text = "My amazing feed"
                };
                return(feed);
            }
Example #3
0
        public void GeneratorMetadataWriterTest()
        {
            string testName    = "Test generator";
            string testUri     = "http://odata.org/generator";
            string testVersion = "3.0";

            var testCases = new[]
            {
                new
                {
                    Generator = new AtomGeneratorMetadata()
                    {
                        Name    = testName,
                        Uri     = new Uri(testUri),
                        Version = testVersion
                    },
                    Xml = @"<generator uri=""" + testUri + @""" version=""" + testVersion + @""" xmlns=""" + TestAtomConstants.AtomNamespace + @""">" + testName + @"</generator>",
                    ExpectedException = (string)null
                },
                new
                {
                    Generator = new AtomGeneratorMetadata()
                    {
                        Name    = testName,
                        Uri     = null,
                        Version = null
                    },
                    Xml = @"<generator xmlns=""" + TestAtomConstants.AtomNamespace + @""">" + testName + @"</generator>",
                    ExpectedException = (string)null
                },
                new
                {
                    Generator = new AtomGeneratorMetadata()
                    {
                        Name    = string.Empty,
                        Uri     = null,
                        Version = null
                    },
                    Xml = @"<generator xmlns=""" + TestAtomConstants.AtomNamespace + @"""></generator>",
                    ExpectedException = (string)null
                },
                new
                {
                    Generator = new AtomGeneratorMetadata()
                    {
                        Name    = null,
                        Uri     = null,
                        Version = null
                    },
                    Xml = @"<generator xmlns=""" + TestAtomConstants.AtomNamespace + @""" />",
                    ExpectedException = (string)null
                },
                new
                {
                    Generator = new AtomGeneratorMetadata()
                    {
                        Name    = "\n\t ",
                        Uri     = null,
                        Version = null
                    },
                    Xml = @"<generator xml:space=""preserve"" xmlns=""" + TestAtomConstants.AtomNamespace + "\">\n\t </generator>",
                    ExpectedException = (string)null
                },
            };

            Func <XElement, XElement> fragmentExtractor = (e) => e.Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomGeneratorElementName);

            // Convert test cases to test descriptions
            var testDescriptors = testCases.Select(testCase =>
            {
                ODataFeed feed            = ObjectModelUtils.CreateDefaultFeedWithAtomMetadata();
                AtomFeedMetadata metadata = feed.Atom();
                this.Assert.IsNotNull(metadata, "Expected default feed metadata on a default feed.");
                metadata.Generator = testCase.Generator;
                return(new PayloadWriterTestDescriptor <ODataItem>(this.Settings, feed, testConfiguration =>
                                                                   new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                {
                    Xml = testCase.Xml, ExpectedODataExceptionMessage = testCase.ExpectedException, FragmentExtractor = fragmentExtractor, PreserveWhitespace = true
                }));
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors.PayloadCases(WriterPayloads.FeedPayloads),
                this.WriterTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testConfiguration = testConfiguration.Clone();
                testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, testConfiguration, this.Assert, this.Logger);
            });
        }