/// <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)); }
/// <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)); }