Exemple #1
0
        /// <summary>
        /// Returns all interesting payloads for a property.
        /// </summary>
        /// <param name="testDescriptor">Test descriptor which will end up writing a single entry with a single property.
        /// The entry is not going to be used, but the property from it will.</param>
        /// <returns>Enumeration of test descriptors which will include the original property in some interesting scenarios.</returns>
        public static IEnumerable <PayloadWriterTestDescriptor <ODataItem> > PropertyPayloads(PayloadWriterTestDescriptor <ODataItem> testDescriptor)
        {
            ODataResource tempEntry = testDescriptor.PayloadItems[0] as ODataResource;

            Debug.Assert(tempEntry != null, "A single entry payload is expected.");
            ODataProperty property = tempEntry.Properties.First();

            // Note - the property can be null - it is a valid test case !!!!

            var payloadCases = new WriterPayloadCase <ODataItem>[] {
                new WriterPayloadCase <ODataItem>()  // Single property on an entry
                {
                    GetPayloadItems = () => {
                        ODataResource entry = ObjectModelUtils.CreateDefaultEntry();
                        entry.Properties = new ODataProperty[] { property };
                        return(new ODataItem[] { entry });
                    },
                    AtomFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(TestAtomUtils.ExtractPropertiesFromEntry(result).Element(TestAtomConstants.ODataXNamespace + property.Name));
                    },
                    //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight
                },

                // TODO: Add other interesting payloads for properties - more properties in an entry, inside a complex property, inside a collection of complex and so on
            };

            return(ApplyPayloadCases <ODataItem>(testDescriptor, payloadCases));
        }
Exemple #2
0
        /// <summary>
        /// Returns all interesting payloads for a value.
        /// </summary>
        /// <param name="testDescriptor">Test descriptor which will end up writing a single entry with a single property.
        /// The entry is not going to be used, the property is not going to be used, but the property value from it will.</param>
        /// <returns>Enumeration of test descriptors which will include the original value in some interesting scenarios.</returns>
        public static IEnumerable <PayloadWriterTestDescriptor <ODataItem> > ValuePayloads(PayloadWriterTestDescriptor <ODataItem> testDescriptor)
        {
            ODataResource tempEntry = testDescriptor.PayloadItems[0] as ODataResource;

            Debug.Assert(tempEntry != null, "A single entry payload is expected.");
            ODataProperty property = tempEntry.Properties.First();

            Debug.Assert(property != null, "A single property is expected.");
            object propertyValue = property.Value;

            var payloadCases = new WriterPayloadCase <ODataItem>[] {
                new WriterPayloadCase <ODataItem>()  // Value of a property
                {
                    GetPayloadItems = () => {
                        ODataResource entry = ObjectModelUtils.CreateDefaultEntry();
                        entry.Properties = new ODataProperty[] { new ODataProperty()
                                                                 {
                                                                     Name = "TestProperty", Value = propertyValue
                                                                 } };
                        return(new ODataItem[] { entry });
                    },
                    AtomFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(TestAtomUtils.ExtractPropertiesFromEntry(result).Element(TestAtomConstants.ODataXNamespace + property.Name));
                    },
                    //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight
                },
                new WriterPayloadCase <ODataItem>()  // Value as item in a collection
                {
                    ShouldSkip      = testConfiguration => propertyValue is ODataCollectionValue,
                    GetPayloadItems = () => {
                        ODataResource entry = ObjectModelUtils.CreateDefaultEntry();
                        entry.Properties = new ODataProperty[] { new ODataProperty()
                                                                 {
                                                                     Name = "TestProperty", Value = new ODataCollectionValue()
                                                                     {
                                                                         Items = new object[] { propertyValue }
                                                                     }
                                                                 } };
                        return(new ODataItem[] { entry });
                    },
                    AtomFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(TestAtomUtils.ExtractPropertiesFromEntry(result).Element(TestAtomConstants.ODataXNamespace + property.Name));
                    },
                    //ToDo: Fix places where we've lost JsonVerbose coverage to add JsonLight
                },

                // TODO: Add other interesting payloads for property values
            };

            // Combine with property payloads to get interesting places where the property itself is used.
            return(ApplyPayloadCases <ODataItem>(testDescriptor, payloadCases).PayloadCases(PropertyPayloads));
        }
Exemple #3
0
        /// <summary>
        /// Returns all interesting payloads for a named stream.
        /// </summary>
        /// <param name="testDescriptor">Test descriptor which will end up writing a single entry with a single named stream.
        /// The entry is not going to be used, but the named stream from it will.</param>
        /// <returns>Enumeration of test descriptors which will include the original named stream in some interesting scenarios.</returns>
        public static IEnumerable <PayloadWriterTestDescriptor <ODataItem> > NamedStreamPayloads(PayloadWriterTestDescriptor <ODataItem> testDescriptor)
        {
            ODataResource tempEntry = testDescriptor.PayloadItems[0] as ODataResource;

            Debug.Assert(tempEntry != null, "A single entry payload is expected.");
            ODataProperty namedStreamProperty = tempEntry.Properties.FirstOrDefault(p => p != null && p.Value is ODataStreamReferenceValue);

            // Note - the named stream can be null - it is a valid test case !!!!

            var payloadCases = new WriterPayloadCase <ODataItem>[] {
                new WriterPayloadCase <ODataItem>()  // Single named stream on an entry
                {
                    GetPayloadItems = () => {
                        ODataResource entry = ObjectModelUtils.CreateDefaultEntry();
                        entry.TypeName   = "TestModel.EntityWithStreamProperty";
                        entry.Properties = new ODataProperty[] { namedStreamProperty };
                        return(new ODataItem[] { entry });
                    },
                    ModelBuilder = (model) =>
                    {
                        model = model.Clone();
                        model.EntityType("EntityWithStreamProperty", "TestModel")
                        .StreamProperty(namedStreamProperty.Name);
                        return(model);
                    },
                    AtomFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(TestAtomUtils.ExtractNamedStreamLinksFromEntry(result, namedStreamProperty.Name));
                    },
                    JsonLightFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(new JsonObject().AddProperties(result.Object().GetPropertyAnnotationsAndProperty(namedStreamProperty.Name)));
                    },
                },

                new WriterPayloadCase <ODataItem>()  // Single named stream on an entry with other properties before/after it
                {
                    GetPayloadItems = () => {
                        ODataResource entry = ObjectModelUtils.CreateDefaultEntry();
                        entry.TypeName   = "TestModel.EntityWithStreamPropertyAndOtherProperties";
                        entry.Properties = new ODataProperty[]
                        {
                            new ODataProperty {
                                Name = "Id", Value = 1
                            },
                            new ODataProperty {
                                Name = "Name", Value = "Clemens"
                            },
                            namedStreamProperty,
                            new ODataProperty {
                                Name  = "Address",
                                Value = new ODataComplexValue
                                {
                                    TypeName   = "TestModel.AddressType",
                                    Properties = new ODataProperty[]
                                    {
                                        new ODataProperty {
                                            Name = "Street", Value = "Am Euro Platz"
                                        },
                                        new ODataProperty {
                                            Name = "City", Value = "Vienna"
                                        }
                                    }
                                }
                            }
                        };
                        return(new ODataItem[] { entry });
                    },
                    ModelBuilder = (model) =>
                    {
                        model = model.Clone();
                        var addressType = model.ComplexType("AddressType", "TestModel")
                                          .Property("Street", EdmPrimitiveTypeKind.String)
                                          .Property("City", EdmPrimitiveTypeKind.String);
                        model.EntityType("EntityWithStreamPropertyAndOtherProperties", "TestModel")
                        .KeyProperty("Id", (EdmTypeReference)EdmCoreModel.Instance.GetInt32(false))
                        .Property("Name", EdmPrimitiveTypeKind.String)
                        .StreamProperty(namedStreamProperty.Name)
                        .Property("Address", new EdmComplexTypeReference(addressType, false));
                        return(model);
                    },
                    AtomFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(TestAtomUtils.ExtractNamedStreamLinksFromEntry(result, namedStreamProperty.Name));
                    },
                    JsonLightFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(new JsonObject().AddProperties(result.Object().GetPropertyAnnotationsAndProperty(namedStreamProperty.Name)));
                    },
                },

                new WriterPayloadCase <ODataItem>()  // Multiple named stream properties on an entry
                {
                    GetPayloadItems = () => {
                        ODataResource entry = ObjectModelUtils.CreateDefaultEntry();
                        entry.TypeName   = "TestModel.EntityWithSeveralStreamProperties";
                        entry.Properties = new ODataProperty[]
                        {
                            new ODataProperty {
                                Name = "Id", Value = 1
                            },
                            new ODataProperty {
                                Name = "__Stream1", Value = new ODataStreamReferenceValue {
                                    ReadLink = new Uri("http://odata.org/stream1/readlink")
                                }
                            },
                            new ODataProperty {
                                Name = "__Stream2", Value = new ODataStreamReferenceValue {
                                    EditLink = new Uri("http://odata.org/stream2/editlink")
                                }
                            },
                            namedStreamProperty,
                            new ODataProperty {
                                Name = "__Stream3", Value = new ODataStreamReferenceValue {
                                    ReadLink = new Uri("http://odata.org/stream3/readlink"), ContentType = "stream3:contenttype"
                                }
                            },
                        };
                        return(new ODataItem[] { entry });
                    },
                    ModelBuilder = (model) =>
                    {
                        model = model.Clone();
                        model.EntityType("EntityWithSeveralStreamProperties", "TestModel")
                        .KeyProperty("Id", (EdmTypeReference)EdmCoreModel.Instance.GetInt32(false))
                        .StreamProperty("__Stream1")
                        .StreamProperty("__Stream2")
                        .StreamProperty(namedStreamProperty.Name)
                        .StreamProperty("__Stream3");
                        return(model);
                    },
                    AtomFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(TestAtomUtils.ExtractNamedStreamLinksFromEntry(result, namedStreamProperty.Name));
                    },
                    JsonLightFragmentExtractor = (testConfiguration, result) =>
                    {
                        return(new JsonObject().AddProperties(result.Object().GetPropertyAnnotationsAndProperty(namedStreamProperty.Name)));
                    },
                },
            };

            return(ApplyPayloadCases <ODataItem>(testDescriptor, payloadCases));
        }