示例#1
0
        public virtual void CompareSingleValue(object expected, bool stripQuotes, bool valueUri)
        {
            if (this.Resources == null && expected == null)
            {
                return;
            }

            PayloadSimpleProperty simpleProperty = this.Resources as PayloadSimpleProperty;

            if (simpleProperty == null)
            {
                AstoriaTestLog.FailAndThrow("Payload did not represent a single value");
            }

            if (expected == null)
            {
                if (!simpleProperty.IsNull)
                {
                    AstoriaTestLog.FailAndContinue(new TestFailedException("Compare failed - Expected: null, got: " + simpleProperty.Value));
                }
            }
            else
            {
                ComparePrimitiveValuesObjectAndString(expected, expected.GetType(), simpleProperty.Value, valueUri, this.Format, false);
            }
        }
示例#2
0
 internal bool CompareProperties(PayloadObject payloadObject, object element, bool throwOnFailure)
 {
     // Verify resource properties and navigation
     foreach (PayloadProperty property in payloadObject.PayloadProperties)
     {
         if (property is PayloadComplexProperty)
         {
             PayloadComplexProperty payloadProperty = (PayloadComplexProperty)property;
             if (!this.CompareComplexType(payloadProperty, element, true))
             {
                 if (throwOnFailure)
                 {
                     throw new TestFailedException("Value for complex property '" + property.Name + "' does not batch baseline");
                 }
                 return(false);
             }
         }
         else if (property is PayloadSimpleProperty)
         {
             PayloadSimpleProperty payloadProperty = (PayloadSimpleProperty)property;
             if (!this.CompareSimpleType(payloadProperty, element, true))
             {
                 if (throwOnFailure)
                 {
                     throw new TestFailedException("Value for simple property '" + property.Name + "' does not batch baseline");
                 }
                 return(false);
             }
         }
     }
     return(true);
 }
示例#3
0
        private static ResourceInstanceComplexProperty ConvertComplexPayloadObjectToComplexProperty(ResourceProperty rp, PayloadComplexProperty payloadComplexProperty)
        {
            List <ResourceInstanceProperty> properties = new List <ResourceInstanceProperty>();

            foreach (ResourceProperty childProperty in (rp.Type as ComplexType).Properties.OfType <ResourceProperty>())
            {
                if (childProperty.IsComplexType)
                {
                    PayloadComplexProperty fromPayload = payloadComplexProperty.PayloadProperties[childProperty.Name] as PayloadComplexProperty;
                    properties.Add(ConvertComplexPayloadObjectToComplexProperty(childProperty, fromPayload));
                }
                else
                {
                    PayloadSimpleProperty fromPayload = payloadComplexProperty.PayloadProperties[childProperty.Name] as PayloadSimpleProperty;
                    if (fromPayload != null)
                    {
                        ResourceInstanceProperty newProperty = null;
                        object val = CommonPayload.DeserializeStringToObject(fromPayload.Value, childProperty.Type.ClrType, false, fromPayload.ParentObject.Format);
                        newProperty = new ResourceInstanceSimpleProperty(childProperty.Name, new NodeValue(val, childProperty.Type));
                        properties.Add(newProperty);
                    }
                }
            }
            ComplexResourceInstance complexResourceInstance = new ComplexResourceInstance(rp.Type.Name, properties.ToArray());

            return(new ResourceInstanceComplexProperty(rp.Type.Name, rp.Name, complexResourceInstance));
        }
示例#4
0
        protected bool EquivalentValues(NodeType firstType, PayloadProperty first, NodeType secondType, PayloadProperty second)
        {
            PayloadSimpleProperty firstSimple  = first as PayloadSimpleProperty;
            PayloadSimpleProperty secondSimple = second as PayloadSimpleProperty;

            if (firstSimple == null || secondSimple == null)
            {
                return(false);
            }

            if ((firstType == Clr.Types.Double || firstType == Clr.Types.Float))
            {
                if (second.ParentObject.Format == SerializationFormatKind.JSON)
                {
                    if (secondType == Clr.Types.Int16 || secondType == Clr.Types.Int32 || secondType == Clr.Types.Int64)
                    {
                        if (((long)double.Parse(firstSimple.Value)) == long.Parse(secondSimple.Value))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#5
0
        internal PayloadObject ParseUriNode(XElement node)
        {
            PayloadObject         po       = new PayloadObject(this);
            PayloadSimpleProperty property = new PayloadSimpleProperty(po);

            property.Value = node.Value;
            property.Name  = node.Name.LocalName;
            po.Name        = node.Name.LocalName;
            po.PayloadProperties.Add(property);
            return(po);
        }
示例#6
0
        internal static KeyedResourceInstance CreateKeyedResourceInstanceFromPayloadObject(ResourceContainer container, ResourceType resourceType, PayloadObject payloadObject)
        {
            List <ResourceInstanceProperty> properties    = new List <ResourceInstanceProperty>();
            List <ResourceInstanceProperty> keyProperties = new List <ResourceInstanceProperty>();

            foreach (ResourceProperty property in resourceType.Properties.OfType <ResourceProperty>())
            {
                if (property.IsNavigation)
                {
                    continue;
                }

                if (property.IsComplexType)
                {
                    PayloadComplexProperty fromPayload = payloadObject[property.Name] as PayloadComplexProperty;
                    properties.Add(ConvertComplexPayloadObjectToComplexProperty(property, fromPayload));
                }
                else
                {
                    string stringValue;
                    if (payloadObject.PayloadProperties.Any(p => p.Name == property.Name))
                    {
                        PayloadSimpleProperty fromPayload = payloadObject[property.Name] as PayloadSimpleProperty;
                        stringValue = fromPayload.Value;
                    }
                    else
                    {
                        if (!payloadObject.CustomEpmMappedProperties.TryGetValue(property.Name, out stringValue))
                        {
                            stringValue = null;
                        }
                    }

                    ResourceInstanceProperty newProperty = null;
                    object val = CommonPayload.DeserializeStringToObject(stringValue, property.Type.ClrType, false, payloadObject.Format);
                    newProperty = new ResourceInstanceSimpleProperty(property.Name, new NodeValue(val, property.Type));

                    if (property.PrimaryKey != null)
                    {
                        keyProperties.Add(newProperty);
                    }
                    else
                    {
                        properties.Add(newProperty);
                    }
                }
            }

            ResourceInstanceKey key = new ResourceInstanceKey(container, resourceType, keyProperties.ToArray());

            return(new KeyedResourceInstance(key, properties.ToArray()));
        }
示例#7
0
        public static KeyExpression ConstructKey(ResourceContainer container, PayloadObject entity)
        {
            Dictionary <string, object> properties = new Dictionary <string, object>();

            ResourceType type = container.BaseType;

            if (entity.Type != type.Namespace + "." + type.Name)
            {
                type = container.ResourceTypes.SingleOrDefault(rt => rt.Namespace + "." + rt.Name == entity.Type);
                if (type == null)
                {
                    AstoriaTestLog.FailAndThrow("Could not find resource type for payload type value: " + entity.Type);
                }
            }

            foreach (ResourceProperty property in type.Properties.OfType <ResourceProperty>())
            {
                if (property.IsNavigation || property.IsComplexType)
                {
                    continue;
                }

                string propertyName = property.Name;
                string valueString;
                if (entity.PayloadProperties.Any(p => p.Name == propertyName))
                {
                    PayloadSimpleProperty simpleProperty = entity[propertyName] as PayloadSimpleProperty;
                    if (simpleProperty == null)
                    {
                        continue;
                    }

                    valueString = simpleProperty.Value;
                }
                else
                {
                    continue;
                }

                object value = CommonPayload.DeserializeStringToObject(valueString, property.Type.ClrType, false, entity.Format);
                if (value is DateTime && entity.Format == SerializationFormatKind.JSON)
                {
                    // TODO: this is because the server will make any JSON datetime into UTC, and currently we always send 'unspecified' values
                    value = new DateTime(((DateTime)value).Ticks, DateTimeKind.Unspecified);
                }

                properties[propertyName] = value;
            }

            return(new KeyExpression(container, type, properties));
        }
示例#8
0
        public virtual void Compare(IQueryable baseline)
        {
            System.Collections.ArrayList baseLineEntities = CommonPayload.CreateList(baseline);

            if (this.Resources is PayloadComplexProperty)
            {
                PayloadComplexProperty complexProperty = (PayloadComplexProperty)this.Resources;
                this.CompareComplexType(complexProperty, baseLineEntities[0], false);
            }
            else if (this.Resources is PayloadSimpleProperty)
            {
                PayloadSimpleProperty simpleProperty = (PayloadSimpleProperty)this.Resources;
                this.CompareSimpleType(simpleProperty, baseLineEntities[0], false);
            }
            else if (this.Resources is List <PayloadObject> )
            {
                List <PayloadObject> payloadObjects = (List <PayloadObject>) this.Resources;
                Compare(baseLineEntities.OfType <object>().ToList(), payloadObjects, false);
            }
        }
示例#9
0
        internal PayloadSimpleProperty parseSimpleObject(PayloadObject parent, JSField field)
        {
            PayloadSimpleProperty payloadProperty = new PayloadSimpleProperty(parent);

            payloadProperty.Name = field.Name;

            object val = field.GetValue(field);

            if (val is System.DBNull)
            {
                payloadProperty.Value  = null;
                payloadProperty.Type   = null;
                payloadProperty.IsNull = true;
            }
            else
            {
                payloadProperty.Type   = AstoriaUnitTests.Data.TypeData.FindForType(val.GetType()).GetEdmTypeName();
                payloadProperty.Value  = ConvertJsonValue(val);
                payloadProperty.IsNull = false;
            }

            return(payloadProperty);
        }
示例#10
0
        internal PayloadSimpleProperty ParseSimpleProperty(PayloadObject parent, XElement xmlData)
        {
            PayloadSimpleProperty payloadProperty = new PayloadSimpleProperty(parent);

            payloadProperty.Name  = xmlData.Name.LocalName;
            payloadProperty.Value = xmlData.Value;

            XAttribute nullAttribute = xmlData.Attribute(m + "null");

            if (nullAttribute != null && nullAttribute.Value == "true")
            {
                payloadProperty.Value  = null;
                payloadProperty.IsNull = true;
            }

            XAttribute typeAttribute = xmlData.Attribute(m + "type");

            if (typeAttribute != null)
            {
                payloadProperty.Type = typeAttribute.Value;
            }

            return(payloadProperty);
        }
示例#11
0
        internal PayloadSimpleProperty ParseSimpleProperty(PayloadObject parent, XElement xmlData)
        {
            PayloadSimpleProperty payloadProperty = new PayloadSimpleProperty(parent);
            payloadProperty.Name = xmlData.Name.LocalName;
            payloadProperty.Value = xmlData.Value;

            XAttribute nullAttribute = xmlData.Attribute(m + "null");
            if (nullAttribute != null && nullAttribute.Value == "true")
            {
                payloadProperty.Value = null;
                payloadProperty.IsNull = true;
            }

            XAttribute typeAttribute = xmlData.Attribute(m + "type");
            if (typeAttribute != null)
                payloadProperty.Type = typeAttribute.Value;

            return payloadProperty;
        }
示例#12
0
        private void Verify(AstoriaRequest request)
        {
            RequestVerb verb  = request.EffectiveVerb;
            bool        merge = verb == RequestVerb.Patch;

            PayloadObject entityBefore;

            if (!TryGetSingleObjectFromPayload(request.BeforeUpdatePayload, out entityBefore))
            {
                AstoriaTestLog.FailAndThrow("Pre-update payload did not contain a single entity");
            }

            // determine the type based on what was there (doing .Single() doesn't work for MEST, because the type shows up twice)
            ResourceType type = request.Workspace.ServiceContainer.ResourceTypes.First(rt => entityBefore.Type.Equals(rt.Namespace + "." + rt.Name));

            PayloadObject entityAfter;

            if (!TryGetSingleObjectFromPayload(request.AfterUpdatePayload, out entityAfter))
            {
                AstoriaTestLog.FailAndThrow("Post-update payload did not contain a single entity");
            }

            CommonPayload updatePayload = request.CommonPayload;
            PayloadObject entityUpdate  = null;

            if (request.URI.EndsWith("$value"))
            {
                Match match = Regex.Match(request.URI, @".*/(.+)/\$value");
                if (!match.Success)
                {
                    AstoriaTestLog.FailAndThrow("Could not determine property name for $value request");
                }

                string propertyValue = null;
                if (request.ContentType.Equals(SerializationFormatKinds.MimeApplicationOctetStream, StringComparison.InvariantCultureIgnoreCase))
                {
                    object value = (request.UpdateTree as ResourceInstanceSimpleProperty).PropertyValue;
                    if (updatePayload.Format == SerializationFormatKind.JSON)
                    {
                        propertyValue = JSONPayload.ConvertJsonValue(value);
                    }
                    else
                    {
                        AstoriaTestLog.FailAndThrow("Unsure how to fake property value");
                    }
                }
                else
                {
                    propertyValue = request.Payload;
                }

                entityUpdate = new PayloadObject(updatePayload);
                PayloadSimpleProperty propertyUpdate = new PayloadSimpleProperty(entityUpdate);
                propertyUpdate.Name  = match.Groups[1].Value;
                propertyUpdate.Value = propertyValue;
                entityUpdate.PayloadProperties.Add(propertyUpdate);
                merge = true; //PUT to a single property doesn't reset the resource
            }
            else if (!TryGetSingleObjectFromPayload(updatePayload, out entityUpdate))
            {
                // must be a single property update
                PayloadProperty propertyUpdate = updatePayload.Resources as PayloadProperty;
                if (propertyUpdate == null)
                {
                    AstoriaTestLog.FailAndThrow("Expected either a property or an entity in the update payload");
                }
                entityUpdate = new PayloadObject(updatePayload);
                entityUpdate.PayloadProperties.Add(propertyUpdate);
                propertyUpdate.ParentObject = entityUpdate;
                merge = true; //PUT to a single property doesn't reset the resource
            }

            List <string> allPropertyNames = entityBefore.PayloadProperties
                                             .Union(entityAfter.PayloadProperties)
                                             .Union(entityUpdate.PayloadProperties)
                                             .Select(p => p.Name)
                                             .ToList();

            allPropertyNames.AddRange(entityBefore.CustomEpmMappedProperties.Keys);
            allPropertyNames.AddRange(entityUpdate.CustomEpmMappedProperties.Keys);
            allPropertyNames.AddRange(entityAfter.CustomEpmMappedProperties.Keys);

            foreach (string propertyName in allPropertyNames.Distinct())
            {
                PayloadProperty original            = null;
                bool            originalHadProperty = entityBefore.PayloadProperties.Any(p => (original = p).Name == propertyName);

                PayloadProperty update            = null;
                bool            updateHadProperty = entityUpdate.PayloadProperties.Any(p => (update = p).Name == propertyName);

                PayloadProperty final            = null;
                bool            finalHadProperty = entityAfter.PayloadProperties.Any(p => (final = p).Name == propertyName);

                if (type.Properties.Any(p => p.Name == propertyName && p.Facets.IsDeclaredProperty))
                {
                    // declared property

                    if (!finalHadProperty)
                    {
                        AstoriaTestLog.FailAndThrow("Final version of entity is missing declared property '" + propertyName + "'");
                    }

                    ResourceProperty property = type.Properties[propertyName] as ResourceProperty;

                    if (property.IsNavigation)
                    {
                        continue;
                    }

                    if (!originalHadProperty)
                    {
                        AstoriaTestLog.FailAndThrow("Original version of entity is missing declared property '" + propertyName + "'");
                    }

                    bool checkValue = property.PrimaryKey == null && !property.Facets.ServerGenerated;

                    // if we changed it, we don't care what it was
                    if (updateHadProperty)
                    {
                        ComparePropertyValues(property, update, final, checkValue);
                    }
                    else if (merge)
                    {
                        ComparePropertyValues(property, original, final, checkValue);
                    }
                    else if (checkValue)
                    {
                        CompareResetProperty(property, final);
                    }
                }
                else
                {
                    // dynamic property
                    if (updateHadProperty)
                    {
                        if (!finalHadProperty)
                        {
                            AstoriaTestLog.FailAndThrow("Final version of entity is missing dynamic property '" + propertyName + "'");
                        }
                        CompareDynamicPropertyValues(update, final);
                    }
                    else if (merge)
                    {
                        if (!finalHadProperty)
                        {
                            AstoriaTestLog.FailAndThrow("Final version of entity is missing dynamic property '" + propertyName + "'");
                        }
                        CompareDynamicPropertyValues(original, final);
                    }
                    else if (finalHadProperty)
                    {
                        AstoriaTestLog.FailAndThrow("Dynamic property '" + propertyName + "' was not cleared after reset");
                    }
                }
            }
        }
示例#13
0
        internal bool CompareSimpleType(PayloadSimpleProperty payloadProperty, object element, bool isEntity)
        {
            Object expectedResult, actualResult = null;

            // Verify property data
            string propertyName = payloadProperty.Name;

            if (isEntity)
            {
#if !ClientSKUFramework
                if (element is RowEntityType)
                {
                    expectedResult = ((RowEntityType)element).Properties[propertyName];
                }

                else if (element is RowComplexType)
                {
                    expectedResult = ((RowComplexType)element).Properties[propertyName];
                }

                else
#endif

                {
                    PropertyInfo propertyInfo = element.GetType().GetProperty(propertyName);

                    if (propertyInfo == null)
                    {
                        AstoriaTestLog.TraceInfo(String.Format("Couldn't find property {0}", propertyName));
                        return(true);
                    }

                    expectedResult = propertyInfo.GetValue(element, null);
                }
            }
            else
            {
                expectedResult = element;
            }

            if (expectedResult is System.Byte[])
            {
                int    actualInt32Result;
                object newExpectedResult;

                // If prop value is int, then it just contains the length, not the acutally binary data so compare that
                if (Int32.TryParse(payloadProperty.Value, out actualInt32Result))
                {
                    actualResult      = actualInt32Result;
                    newExpectedResult = ((byte[])expectedResult).Length;
                }
                else
                {
                    actualResult      = payloadProperty.Value;
                    newExpectedResult = System.Convert.ToBase64String((System.Byte[])expectedResult);
                }

                return(this.InternalEquals(actualResult, newExpectedResult));
            }
            else
            {
                if (expectedResult == null)
                {
                    actualResult = payloadProperty.Value;
                }
                else if (expectedResult is System.DateTime)
                {
                    switch (((DateTime)expectedResult).Kind)
                    {
                    case DateTimeKind.Local:
                        expectedResult = ((DateTime)expectedResult).ToUniversalTime();
                        break;

                    case DateTimeKind.Unspecified:
                        expectedResult = new DateTime(((DateTime)expectedResult).Ticks, DateTimeKind.Utc);
                        break;

                    case DateTimeKind.Utc:
                        break;
                    }
                    actualResult = this.ParseDate(payloadProperty.Value);
                }
                else if (expectedResult is System.Guid)
                {
                    expectedResult = ((Guid)expectedResult).ToString();
                    actualResult   = payloadProperty.Value;
                }
#if !ClientSKUFramework
                else if (expectedResult is System.Data.Linq.Binary || expectedResult is System.Xml.Linq.XElement)
                {
                    actualResult   = StripQuotes(payloadProperty.Value);
                    expectedResult = StripQuotes(expectedResult.ToString());
                }
#endif
                else
                {
                    if (payloadProperty.Value == null)
                    {
                        actualResult = null;
                    }
                    else
                    {
#if !ClientSKUFramework
                        actualResult = AstoriaUnitTests.Data.TypeData.ObjectFromXmlValue(payloadProperty.Value, expectedResult.GetType());
#endif
                    }
                }

                return(this.InternalEquals(actualResult, expectedResult));
            }
        }
示例#14
0
        protected NodeType GetDynamicPropertyType(PayloadProperty property)
        {
            string typeName = property.Type;

            if (typeName == null)
            {
                if (property.ParentObject.Format == SerializationFormatKind.JSON)
                {
                    if (property is PayloadComplexProperty)
                    {
                        PayloadComplexProperty complexProperty = property as PayloadComplexProperty;
                        PayloadProperty        metadata;
                        if (!complexProperty.PayloadProperties.TryGetValue("__metadata", out metadata) || !(metadata is PayloadComplexProperty))
                        {
                            AstoriaTestLog.FailAndThrow("Complex type properties did not contain __metadata complex property");
                        }
                        PayloadProperty metadataType;
                        if (!(metadata as PayloadComplexProperty).PayloadProperties.TryGetValue("type", out metadataType) || !(metadataType is PayloadSimpleProperty))
                        {
                            AstoriaTestLog.FailAndThrow("__metadata property did not contain complex type's name");
                        }
                        typeName = (metadataType as PayloadSimpleProperty).Value;
                    }

                    if (typeName == null)
                    {
                        typeName = "String";
                    }
                }
                else
                {
                    typeName = "String";
                }
            }
            else if (typeName.StartsWith("Edm."))
            {
                typeName = typeName.Replace("Edm.", null);
            }

            if (typeName == "Binary")
            {
                typeName = "Byte[]";
            }

            // json datetime check
            if (typeName == "String" && property.ParentObject.Format == SerializationFormatKind.JSON && property is PayloadSimpleProperty)
            {
                PayloadSimpleProperty simpleProperty = property as PayloadSimpleProperty;
                if (Util.JsonPrimitiveTypesUtil.DateTimeRegex.IsMatch(simpleProperty.Value))
                {
                    typeName = "DateTime";
                }
            }

            NodeType type = Clr.Types.SingleOrDefault(t => t.Name.Equals(typeName));

            if (type == null)
            {
                type = Response.Workspace.ServiceContainer.ComplexTypes.SingleOrDefault(ct => typeName.Equals(ct.Namespace + "." + ct.Name));
            }

            if (type == null)
            {
                AstoriaTestLog.FailAndThrow("Could not find type '" + typeName + "'");
            }

            return(type);
        }
示例#15
0
        protected void ComparePropertyValues(NodeType type, PayloadProperty first, PayloadProperty second, bool checkValue)
        {
            if (type is ComplexType)
            {
                if (first.IsNull)
                {
                    if (!second.IsNull)
                    {
                        AstoriaTestLog.FailAndThrow("Second property is unexpectedly non-null");
                    }
                    return;
                }
                else if (second.IsNull)
                {
                    AstoriaTestLog.FailAndThrow("Second property is unexpectedly null");
                }

                PayloadComplexProperty firstComplex  = first as PayloadComplexProperty;
                PayloadComplexProperty secondComplex = second as PayloadComplexProperty;

                if (firstComplex == null)
                {
                    AstoriaTestLog.FailAndThrow("First property was not a complex property");
                }
                if (secondComplex == null)
                {
                    AstoriaTestLog.FailAndThrow("Second property was not a complex property");
                }

                foreach (string propertyName in firstComplex.PayloadProperties.Keys.Union(secondComplex.PayloadProperties.Keys))
                {
                    // TODO: verify typing
                    if (propertyName == "__metadata")
                    {
                        continue;
                    }

                    PayloadProperty firstProperty;
                    bool            firstHadProperty = firstComplex.PayloadProperties.TryGetValue(propertyName, out firstProperty);

                    PayloadProperty secondProperty;
                    bool            secondHadProperty = secondComplex.PayloadProperties.TryGetValue(propertyName, out secondProperty);

                    // so that we can ignore this case later on, check it now
                    if (!firstHadProperty && !secondHadProperty)
                    {
                        AstoriaTestLog.FailAndThrow("Property list contained property '" + propertyName + "' despite neither complex property containing it");
                    }

                    // since a complex type is never open, there shouldnt be any unexpected properties
                    NodeProperty property = (type as ComplexType).Properties.SingleOrDefault(p => p.Name == propertyName);
                    if (property == null)
                    {
                        if (firstHadProperty && secondHadProperty)
                        {
                            AstoriaTestLog.FailAndThrow("Both complex properties contained sub-property '" + propertyName + "' which is not defined on type '" + type.Name + "'");
                        }
                        else if (firstHadProperty)
                        {
                            AstoriaTestLog.FailAndThrow("First complex property contained sub-property '" + propertyName + "' which is not defined on type '" + type.Name + "'");
                        }
                        else if (secondHadProperty)
                        {
                            AstoriaTestLog.FailAndThrow("Second complex property contained sub-property '" + propertyName + "' which is not defined on type '" + type.Name + "'");
                        }
                    }

                    if (!firstHadProperty)
                    {
                        AstoriaTestLog.FailAndThrow("First complex property property missing sub-property '" + propertyName + "'");
                    }
                    else if (!secondHadProperty)
                    {
                        AstoriaTestLog.FailAndThrow("Second complex property property missing sub-property '" + propertyName + "'");
                    }

                    ComparePropertyValues(property, firstProperty, secondProperty, checkValue && !property.Facets.ServerGenerated);
                }
            }
            else
            {
                PayloadSimpleProperty firstSimple  = first as PayloadSimpleProperty;
                PayloadSimpleProperty secondSimple = second as PayloadSimpleProperty;

                if (firstSimple == null)
                {
                    AstoriaTestLog.FailAndThrow("First property was not a simple property");
                }
                if (secondSimple == null)
                {
                    AstoriaTestLog.FailAndThrow("Second property was not a simple property");
                }

                object expectedObject = CommonPayload.DeserializeStringToObject(firstSimple.Value, type.ClrType, false, first.ParentObject.Format);
                if (checkValue)
                {
                    CommonPayload.ComparePrimitiveValuesObjectAndString(expectedObject, type.ClrType, secondSimple.Value, false, second.ParentObject.Format, true);
                }
                else
                {
                    CommonPayload.DeserializeStringToObject(secondSimple.Value, type.ClrType, false, second.ParentObject.Format);
                }
            }
        }
示例#16
0
        internal bool CompareComplexType(PayloadComplexProperty payloadProperty, object element, bool isEntity)
        {
            bool         passResult = true;
            PropertyInfo propertyInfo;
            Object       complexType;

            string propertyName = payloadProperty.Name;

            if (propertyName == "__metadata" || propertyName == "__deferred")
            {
                return(true); // TODO: single objects should be payloadobjects
            }
            if (isEntity)
            {
                if (element is System.Collections.ArrayList)
                {
                    propertyInfo = element.GetType().GetProperty("Item");
                    complexType  = propertyInfo.GetValue(element, new object[] { 0 });
                }
#if !ClientSKUFramework
                else if (element is RowEntityType)
                {
                    propertyInfo = null;
                    complexType  = ((RowEntityType)element).Properties[propertyName];
                }
                else if (element is RowComplexType)
                {
                    propertyInfo = null;
                    complexType  = ((RowComplexType)element).Properties[propertyName];
                }
#endif

                else if (element.GetType().Name.Contains("Anonymous"))
                {
                    //mfrintu
                    complexType = element;
                }
                else
                {
                    propertyInfo = element.GetType().GetProperty(propertyName);
                    complexType  = propertyInfo.GetValue(element, null);
                }

                if (complexType == null)
                {
                    complexType = LoadReference(element, propertyName);
                    if (complexType == null)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                complexType = element;
            }

            foreach (KeyValuePair <string, PayloadProperty> pair in payloadProperty.PayloadProperties)
            {
                if (pair.Value is PayloadComplexProperty)
                {
                    PayloadComplexProperty complexProperty = (PayloadComplexProperty)pair.Value;
                    if (!this.CompareComplexType(complexProperty, complexType, true))
                    {
                        passResult = false;
                    }
                }
                else if (pair.Value is PayloadSimpleProperty)
                {
                    PayloadSimpleProperty simpleProperty = (PayloadSimpleProperty)pair.Value;
                    if (!this.CompareSimpleType(simpleProperty, complexType, true))
                    {
                        passResult = false;
                    }
                }
            }

            return(passResult);
        }
示例#17
0
 internal PayloadObject ParseUriNode(XElement node)
 {
     PayloadObject po = new PayloadObject(this);
     PayloadSimpleProperty property = new PayloadSimpleProperty(po);
     property.Value = node.Value;
     property.Name = node.Name.LocalName;
     po.Name = node.Name.LocalName;
     po.PayloadProperties.Add(property);
     return po;
 }
示例#18
0
        internal PayloadSimpleProperty parseSimpleObject(PayloadObject parent, JSField field)
        {
            PayloadSimpleProperty payloadProperty = new PayloadSimpleProperty(parent);
            payloadProperty.Name = field.Name;

            object val = field.GetValue(field);

            if (val is System.DBNull)
            {
                payloadProperty.Value = null;
                payloadProperty.Type = null;
                payloadProperty.IsNull = true;
            }
            else
            {
                payloadProperty.Type = AstoriaUnitTests.Data.TypeData.FindForType(val.GetType()).GetEdmTypeName();
                payloadProperty.Value = ConvertJsonValue(val);
                payloadProperty.IsNull = false;
            }

            return payloadProperty;
        }
示例#19
0
        private void CompareResetProperty(NodeProperty property, PayloadProperty value)
        {
            bool complexType = property.Type is ComplexType;

            Workspace w          = value.ParentObject.Payload.Workspace;
            bool      expectNull = false;

            if (w.DataLayerProviderKind == DataLayerProviderKind.NonClr && (!property.Facets.IsClrProperty || complexType))
            {
                expectNull = true;
            }
            if (w.DataLayerProviderKind == DataLayerProviderKind.InMemoryLinq && complexType)
            {
                expectNull = true;
            }
            if (!property.Facets.IsDeclaredProperty)
            {
                expectNull = true;
            }
            if (property.Facets.Nullable)
            {
                expectNull = true;
            }

            if (property.Type is ComplexType)
            {
                if (value.IsNull)
                {
                    if (!expectNull)
                    {
                        AstoriaTestLog.FailAndThrow("Complex property '" + property.Name + " is unexpectedly null after reset");
                    }
                }
                else
                {
                    if (!(value is PayloadComplexProperty))
                    {
                        AstoriaTestLog.FailAndThrow("Property '" + property.Name + "' is complex, but a simple property was found instead");
                    }

                    ComplexType            ct = property.Type as ComplexType;
                    PayloadComplexProperty complexProperty = value as PayloadComplexProperty;
                    foreach (NodeProperty subProperty in ct.Properties)
                    {
                        PayloadProperty subValue;
                        if (!complexProperty.PayloadProperties.TryGetValue(subProperty.Name, out subValue))
                        {
                            AstoriaTestLog.FailAndThrow("Property of complex type '" + ct.Name + "' missing sub-property '" + subProperty.Name + "'");
                        }

                        CompareResetProperty(subProperty, subValue);
                    }
                }
            }
            else
            {
                PayloadSimpleProperty simpleProperty = value as PayloadSimpleProperty;
                if (simpleProperty == null)
                {
                    AstoriaTestLog.FailAndThrow("Property was unexpectedly not a simple property");
                }

                Type   propertyType = property.Type.ClrType;
                object expected     = null;
                if (!expectNull)
                {
                    expected = DefaultValue(propertyType);
                }
                CommonPayload.ComparePrimitiveValuesObjectAndString(expected, propertyType, simpleProperty.Value, false, value.ParentObject.Format, true);
            }
        }