Example #1
0
        public void DefaultEntryTests()
        {
            ODataEntry entry = ObjectModelUtils.CreateDefaultEntryWithAtomMetadata();

            PayloadWriterTestDescriptor<ODataItem>.WriterTestExpectedResultCallback expectedCallback = (testConfiguration) =>
                {
                    if (testConfiguration.Format == ODataFormat.Atom)
                    {
                        return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                        {
                            Xml = string.Join(
                                "$(NL)",
                                @"<entry xmlns=""" + TestAtomConstants.AtomNamespace + @""">",
                                @"  <id>" + ObjectModelUtils.DefaultEntryId + "</id>",
                                @"  <link rel=""self"" href=""" + ObjectModelUtils.DefaultEntryReadLink + @""" />",
                                @"  <title />",
                                @"  <updated>" + ObjectModelUtils.DefaultEntryUpdated + "</updated>",
                                @"  <author>",
                                @"    <name />",
                                @"  </author>",
                                @"  <content type=""application/xml"" />",
                                @"</entry>"),
                            FragmentExtractor = (element) => element
                        };
                    }
                    else
                    {
                        var jsonResult = string.Join("$(NL)",
                            "{",
                            "\"@odata.id\":\"http://www.odata.org/entryid\",\"@odata.readLink\":\"http://www.odata.org/entry/readlink\"",
                            "}"
                        );

                        return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                        {
                            Json = jsonResult,
                            FragmentExtractor = (result) => result.RemoveAllAnnotations(true)
                        };
                    }
                };

            var testCases = new[]
            {
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, entry, expectedCallback)
            };

            // TODO: Fix places where we've lost JsonVerbose coverage to add JsonLight
            this.CombinatorialEngineProvider.RunCombinations(
                testCases.PayloadCases(WriterPayloads.EntryPayloads),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.Format == ODataFormat.Atom),
                (testCase, testConfiguration) =>
                {
                    testConfiguration = testConfiguration.Clone();
                    testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                    TestWriterUtils.WriteAndVerifyODataPayload(testCase, testConfiguration, this.Assert, this.Logger);
                });
        }
Example #2
0
        public void NoEntryIdTests()
        {
            ODataEntry noIdEntry = ObjectModelUtils.CreateDefaultEntry();
            noIdEntry.Id = null;

            PayloadWriterTestDescriptor<ODataItem>.WriterTestExpectedResultCallback noIdExpectedCallback = (testConfiguration) =>
            {
                if (testConfiguration.Format == ODataFormat.Atom)
                {
                    return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                    {
                        Xml = @"<id xmlns=""" + TestAtomConstants.AtomNamespace + @"""/>",
                        FragmentExtractor = (element) => element
                            .Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomIdElementName)
                            .Single()
                    };
                }
                else
                {
                    var jsonResult = string.Join("$(NL)",
                           "{",
                           "\"@odata.readLink\":\"http://www.odata.org/entry/readlink\"",
                           "}"
                       );

                    return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                    {
                        Json = jsonResult,
                        FragmentExtractor = (result) => result.RemoveAllAnnotations(true)
                    };
                }
            };

            var testCases = new[]
            {
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, noIdEntry, noIdExpectedCallback),
            };

            // TODO: Fix places where we've lost JsonVerbose coverage to add JsonLight
            this.CombinatorialEngineProvider.RunCombinations(
                testCases.PayloadCases(WriterPayloads.EntryPayloads),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.Format == ODataFormat.Atom),
                (testCase, testConfiguration) =>
                {
                    testConfiguration = testConfiguration.Clone();
                    testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                    TestWriterUtils.WriteAndVerifyODataPayload(testCase, testConfiguration, this.Assert, this.Logger);
                });
        }
Example #3
0
        public void SelfAndEditLinkTests()
        {
            const string editLink = "http://www.odata.org/entry/editlink";
            ODataEntry selfLinkEntry = ObjectModelUtils.CreateDefaultEntry();
            this.Assert.IsNotNull(selfLinkEntry.ReadLink, "ReadLink property of default entry must not be null.");

            ODataEntry editLinkEntry = ObjectModelUtils.CreateDefaultEntry();
            editLinkEntry.ReadLink = null;
            editLinkEntry.EditLink = new Uri(editLink);

            ODataEntry selfAndEditLinkEntry = ObjectModelUtils.CreateDefaultEntry();
            this.Assert.IsNotNull(selfLinkEntry.ReadLink, "ReadLink property of default entry must not be null.");
            selfAndEditLinkEntry.EditLink = new Uri(editLink);

            ODataEntry noSelfOrEditLinkEntry = ObjectModelUtils.CreateDefaultEntryWithAtomMetadata();
            noSelfOrEditLinkEntry.ReadLink = null;
            this.Assert.IsNull(noSelfOrEditLinkEntry.ReadLink, "noSelfOrEditLinkEntry.ReadLink");
            this.Assert.IsNull(noSelfOrEditLinkEntry.EditLink, "noSelfOrEditLinkEntry.EditLink");

            Func<WriterTestConfiguration, bool, WriterTestExpectedResults> selfLinkExpectedCallback = (testConfiguration, editLinkExpected) =>
                {
                    if (testConfiguration.Format == ODataFormat.Atom)
                    {
                        return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                        {
                            Xml = @"<link rel=""" + TestAtomConstants.AtomSelfRelationAttributeValue + @""" href=""" + ObjectModelUtils.DefaultEntryReadLink + @"""  xmlns=""" + TestAtomConstants.AtomNamespace + @"""/>",
                            FragmentExtractor = (element) =>
                            {
                                if (!editLinkExpected)
                                {
                                    this.Assert.IsFalse(element.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
                                        .Where(e => e.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value == TestAtomConstants.AtomEditRelationAttributeValue)
                                        .Any(), "No edit link should have been found.");
                                }
                                return element
                                    .Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
                                    .Where(e => e.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value == TestAtomConstants.AtomSelfRelationAttributeValue)
                                    .Single();
                            }
                        };
                    }
                    else
                    {
                        return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                        {
                            Json = "\"uri\":\"" + ObjectModelUtils.DefaultEntryReadLink + "\"",
                            FragmentExtractor = (result) => result.Object().PropertyObject("__metadata").Property("uri").RemoveAllAnnotations(true)
                        };
                    }
                };

            Func<WriterTestConfiguration, bool, WriterTestExpectedResults> editLinkExpectedCallback = (testConfiguration, selfLinkExpected) =>
                {
                    if (testConfiguration.Format == ODataFormat.Atom)
                    {
                        return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                        {
                            Xml = @"<link rel=""" + TestAtomConstants.AtomEditRelationAttributeValue + @""" href=""" + editLink + @"""  xmlns=""" + TestAtomConstants.AtomNamespace + @"""/>",
                            FragmentExtractor = (element) =>
                            {
                                if (!selfLinkExpected)
                                {
                                    this.Assert.IsFalse(element.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
                                        .Where(e => e.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value == TestAtomConstants.AtomSelfRelationAttributeValue)
                                        .Any(), "No self link should have been found.");
                                }
                                return element
                                    .Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
                                    .Where(e => e.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value == TestAtomConstants.AtomEditRelationAttributeValue)
                                    .Single();
                            }
                        };
                    }
                    else
                    {
                        return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                        {
                            Json = "\"uri\":\"" + editLink + "\"",
                            FragmentExtractor = (result) => result.Object().PropertyObject("__metadata").Property("uri").RemoveAllAnnotations(true)
                        };
                    }
                };

            PayloadWriterTestDescriptor<ODataItem>.WriterTestExpectedResultCallback noLinkExpectedCallback = (testConfiguration) =>
            {
                if (testConfiguration.Format == ODataFormat.Atom)
                {
                    return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                    {
                        Xml = string.Join(
                        "$(NL)",
                        "<entry xmlns=\"" + TestAtomConstants.AtomNamespace + "\" xmlns:" + TestAtomConstants.ODataNamespacePrefix + "=\"" + TestAtomConstants.ODataNamespace + "\" xmlns:" + TestAtomConstants.ODataMetadataNamespacePrefix + "=\"" + TestAtomConstants.ODataMetadataNamespace + "\">",
                        "  <id>http://www.odata.org/entryid</id>",
                        "    <title />",
                        "    <updated>2010-10-12T17:13:00Z</updated>",
                        "    <author>",
                        "    <name />",
                        "  </author>",
                        "  <content type=\"application/xml\" />",
                        "</entry>"),
                        FragmentExtractor = (element) => element
                    };
                }
                else
                {
                    return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                    {
                        Json = string.Join("$(NL)",
                            "{",
                            "\"__metadata\":{",
                            "\"id\":\"http://www.odata.org/entryid\"",
                            "}",
                            "}"
                        ),
                        FragmentExtractor = (result) => result.RemoveAllAnnotations(true)
                    };
                }
            };

            var testCases = new[]
            {
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, selfLinkEntry, (testConfiguration) => selfLinkExpectedCallback(testConfiguration, false)),
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, editLinkEntry, (testConfiguration) => editLinkExpectedCallback(testConfiguration, false)),
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, selfAndEditLinkEntry, (testConfiguration) => testConfiguration.Format == ODataFormat.Atom ? selfLinkExpectedCallback(testConfiguration, true) : editLinkExpectedCallback(testConfiguration, true)),
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, selfAndEditLinkEntry, (testConfiguration) => editLinkExpectedCallback(testConfiguration, true)),
                new PayloadWriterTestDescriptor<ODataItem>(this.Settings, noSelfOrEditLinkEntry, noLinkExpectedCallback),
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases.PayloadCases(WriterPayloads.EntryPayloads),
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => tc.Format == ODataFormat.Atom),
                (testCase, testConfiguration) =>
                {
                    testConfiguration = testConfiguration.Clone();
                    testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                    TestWriterUtils.WriteAndVerifyODataPayload(testCase, testConfiguration, this.Assert, this.Logger);
                });
        }
Example #4
0
        public void FeedTests()
        {
            PayloadWriterTestDescriptor<ODataItem>[] testPayloads = new[]
                {
                    this.CreateDefaultFeedMetadataDescriptor(/*withModel*/false),
                    this.CreateDefaultFeedMetadataDescriptor(/*withModel*/true),
                    this.CreateDefaultFeedWithAtomMetadataDescriptor(/*withModel*/false),
                    this.CreateDefaultFeedWithAtomMetadataDescriptor(/*withModel*/true),
                };

            this.CombinatorialEngineProvider.RunCombinations(
                testPayloads.PayloadCases(WriterPayloads.FeedPayloads),
                this.WriterTestConfigurationProvider.JsonLightFormatConfigurationsWithIndent,
                (testDescriptor, testConfiguration) =>
                {
                    if (testDescriptor.IsGeneratedPayload && (testConfiguration.Format == ODataFormat.Json || testDescriptor.Model != null))
                    {
                        return;
                    }

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