Esempio n. 1
0
        /// <summary>
        /// Fix up expected collection parameter payload element for comparison.
        /// </summary>
        /// <param name="expectedResultPayloadElement"></param>
        /// <returns>Modified expected collection payload element</returns>
        internal static ODataPayloadElement FixupExpectedCollectionParameterPayloadElement(ODataPayloadElement expectedResultPayloadElement)
        {
            ComplexInstance expected = expectedResultPayloadElement as ComplexInstance;

            if (expected != null)
            {
                List <ComplexMultiValueProperty>   propertiesToReplace   = new List <ComplexMultiValueProperty>();
                List <PrimitiveMultiValueProperty> replacementProperties = new List <PrimitiveMultiValueProperty>();
                foreach (PropertyInstance pi in expected.Properties)
                {
                    PrimitiveMultiValueProperty primitiveCollectionProperty = pi as PrimitiveMultiValueProperty;
                    ComplexMultiValueProperty   complexCollectionProperty   = pi as ComplexMultiValueProperty;
                    if (primitiveCollectionProperty != null)
                    {
                        // collection parameter is an array of element without type name or result wrapper
                        if (primitiveCollectionProperty.Value.Annotations.OfType <JsonCollectionResultWrapperAnnotation>().Any(a => !a.Value))
                        {
                            primitiveCollectionProperty.Value.FullTypeName = null;
                        }
                    }
                    else if (complexCollectionProperty != null)
                    {
                        if (complexCollectionProperty.Value.Annotations.OfType <JsonCollectionResultWrapperAnnotation>().Any(a => !a.Value))
                        {
                            // collection parameter is an array of element without type name or result wrapper
                            complexCollectionProperty.Value.FullTypeName = null;

                            // replace empty ComplexMultiValueProperty with empty PrimitiveMultiValueProperty for comparison since they have the same payload
                            if (complexCollectionProperty.Value.Count == 0)
                            {
                                PrimitiveMultiValueProperty replacementProperty = new PrimitiveMultiValueProperty(complexCollectionProperty.Name, null);
                                replacementProperty.Value.IsNull = complexCollectionProperty.Value.IsNull;
                                foreach (var annotation in complexCollectionProperty.Annotations)
                                {
                                    replacementProperty.Annotations.Add(annotation);
                                }

                                propertiesToReplace.Add(complexCollectionProperty);
                                replacementProperties.Add(replacementProperty);
                            }
                        }
                    }
                }

                for (int i = 0; i < propertiesToReplace.Count; i++)
                {
                    expected.Replace(propertiesToReplace[i], replacementProperties[i]);
                }

                return(expected);
            }

            return(expectedResultPayloadElement);
        }
 /// <summary>
 /// Removes duplicate properties from the specified complex or entity value.
 /// </summary>
 /// <param name="payloadElement"></param>
 private void DeduplicateProperties(ComplexInstance payloadElement)
 {
     Dictionary<string, PropertyInstance> properties = new Dictionary<string, PropertyInstance>();
     foreach (PropertyInstance propertyInstance in payloadElement.Properties.ToList())
     {
         PropertyInstance firstPropertyInstance;
         if (properties.TryGetValue(propertyInstance.Name, out firstPropertyInstance))
         {
             payloadElement.Remove(propertyInstance);
             payloadElement.Replace(firstPropertyInstance, propertyInstance);
             properties[propertyInstance.Name] = propertyInstance;
         }
         else
         {
             properties.Add(propertyInstance.Name, propertyInstance);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Removes duplicate properties from the specified complex or entity value.
        /// </summary>
        /// <param name="payloadElement"></param>
        private void DeduplicateProperties(ComplexInstance payloadElement)
        {
            Dictionary <string, PropertyInstance> properties = new Dictionary <string, PropertyInstance>();

            foreach (PropertyInstance propertyInstance in payloadElement.Properties.ToList())
            {
                PropertyInstance firstPropertyInstance;
                if (properties.TryGetValue(propertyInstance.Name, out firstPropertyInstance))
                {
                    payloadElement.Remove(propertyInstance);
                    payloadElement.Replace(firstPropertyInstance, propertyInstance);
                    properties[propertyInstance.Name] = propertyInstance;
                }
                else
                {
                    properties.Add(propertyInstance.Name, propertyInstance);
                }
            }
        }