public void WritePropertyWithoutOwningType()
        {
            var model = new EdmModel();
            var container = new EdmEntityContainer("DefaultNamespace", "DefaultContainer");
            model.AddElement(container);

            var testDescriptor = new PayloadWriterTestDescriptor<ODataProperty>(
                this.Settings,
                new ODataProperty() { Name = "PropertyName", Value = null },
                tc => new JsonWriterTestExpectedResults(this.ExpectedResultSettings)
                {
                })
                {
                    Model = model
                };

            this.CombinatorialEngineProvider.RunCombinations(
                this.WriterTestConfigurationProvider.JsonLightFormatConfigurations,
                (testConfiguration) =>
                {
                    testDescriptor.RunTopLevelPropertyPayload(testConfiguration, baselineLogger: this.Logger);
                });
        }
Exemplo n.º 2
0
        public void PreserveSpaceTests()
        {
            ODataProperty property = ObjectModelUtils.CreateDefaultPrimitiveProperties().First(p => p.Name == "String");
            this.Assert.AreEqual("String", property.Name, "Expected string property to be the primitive property at position 16.");

            string[] whiteSpaces = new string[] 
            {
                " ",
                "\t",
                "\n",
                "\r",
                "\r\n",
            };
            string[] stringValues = whiteSpaces.SelectMany(s => new[] { string.Format("{0}foo", s), string.Format("foo{0}", s), string.Format("{0}foo{1}", s, s) }).ToArray();

            this.CombinatorialEngineProvider.SetBaselineCallback(() =>
            {
                // In this case the newline is the check point, but the diff reporter don't support this
                string payload = this.Logger.GetBaseline();
                payload = payload.Replace(Environment.NewLine, "@@Environment.NewLine@@");
                payload = payload.Replace("\r\n", "\\r\\n");
                payload = payload.Replace("\n", "\\n");
                payload = payload.Replace("\r", "\\r");
                payload = payload.Replace("@@Environment.NewLine@@", Environment.NewLine);

                return payload;
            });

            this.CombinatorialEngineProvider.RunCombinations(
                stringValues,
                this.WriterTestConfigurationProvider.AtomFormatConfigurationsWithIndent,
                (stringValue, testConfiguration) =>
                {
                    string atomResult = @"<{5} xmlns:{0}=""{1}"" xml:space=""preserve"" xmlns=""{1}"">{4}</{5}>";
                    atomResult = string.Format(atomResult,
                        TestAtomConstants.ODataMetadataNamespacePrefix,
                        TestAtomConstants.ODataMetadataNamespace,
                        TestAtomConstants.ODataNamespacePrefix,
                        TestAtomConstants.ODataNamespace,
                        stringValue.Replace("\r", "&#xD;"),
                        TestAtomConstants.ODataValueElementName);

                    property.Value = stringValue;
                    PayloadWriterTestDescriptor.WriterTestExpectedResultCallback expectedResultCallback =
                        (testConfig) =>
                        {
                            return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                            {
                                FragmentExtractor = null,
                                Xml = atomResult
                            };
                        };

                    var testDescriptor = new PayloadWriterTestDescriptor<ODataProperty>(this.Settings, property, expectedResultCallback);
                    testConfiguration = testConfiguration.Clone();
                    testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);
                    testDescriptor.RunTopLevelPropertyPayload(testConfiguration, baselineLogger: this.Logger);
                });                        
        }