public virtual bool IsApplicable <T1>(Factory <T1> factory) where T1 : Org.Neo4j.Collection.primitive.PrimitiveCollection { using (PrimitiveCollection coll = factory.NewInstance()) { return(ApplicableType.IsInstanceOfType(coll)); } }
/// <summary> /// Normalizes complex properties, potentially replacing them with collections if the metadata indicates the payload is from a service operation /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(ComplexProperty payloadElement) { var replaced = base.Visit(payloadElement); if (replaced.ElementType == ODataPayloadElementType.ComplexProperty) { payloadElement = (ComplexProperty)replaced; // if the payload looks like // <Foo> // <element m:type="Edm.Int32">3</element> // </Foo> // or // <Foo> // <element m:type="Complex"> // <Bar>3</Bar> // </element> // </Foo> // then it may be deserialized as a complex instance with exactly 1 property, when it should be a collection of size 1 // if (this.ShouldReplaceWithCollection(payloadElement, payloadElement.Value.IsNull, payloadElement.Value.FullTypeName)) { // only replace if there is exactly 1 property if (payloadElement.Value.Properties.Count() == 1) { // get the single property and check to see if its name is 'element' var property = payloadElement.Value.Properties.Single(); if (property.Name == ODataConstants.CollectionItemElementName) { // determine whether it is a primitive or complex value based on the kind of property ODataPayloadElementCollection collection = null; if (property.ElementType == ODataPayloadElementType.PrimitiveProperty) { var primitiveProperty = (PrimitiveProperty)property; collection = new PrimitiveCollection(primitiveProperty.Value); } else if (property.ElementType == ODataPayloadElementType.ComplexProperty) { var complexProperty = (ComplexProperty)property; collection = new ComplexInstanceCollection(complexProperty.Value); } // if it was primitive or complex, replace it if (collection != null) { return(payloadElement .ReplaceWith(collection) .WithAnnotations(new CollectionNameAnnotation() { Name = payloadElement.Name })); } } } } } return(replaced); }
/// <summary> /// Visits the payload element and removes the collection name if it is present. /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(PrimitiveCollection payloadElement) { CollectionNameAnnotation collectionNameAnnotation = payloadElement.GetAnnotation<CollectionNameAnnotation>(); if (payloadElement != null && collectionNameAnnotation != null) { collectionNameAnnotation.Name = string.Empty; } base.Visit(payloadElement); }
/// <summary> /// Visits a payload element whose root is an <see cref="PrimitiveCollection"/>. /// </summary> /// <param name="payloadElement">The root node of the payload element being visited.</param> public override void Visit(PrimitiveCollection payloadElement) { base.Visit(payloadElement); // Collections use a different format in JSON for V2 (and higher) payloads (in responses) if (!this.requestPayload) { this.AddVersionAnnotation(payloadElement); } }
/// <summary> /// Visits a payload element whose root is a PrimitiveCollection. /// </summary> /// <param name="expected">The root node of payload element being visited.</param> public void Visit(PrimitiveCollection expected) { ExceptionUtilities.CheckArgumentNotNull(expected, "expected"); var observed = this.GetNextObservedElement <PrimitiveCollection>(); using (this.Assert.WithMessage("Primitive collection did not match expectation")) { this.CompareCollection(expected, observed); } }
private static PrimitiveCollection GetPrimitiveCollection(IRandomNumberGenerator random) { TestValues.CreatePrimitiveValuesWithMetadata(true); PrimitiveValue val = random.ChooseFrom(TestValues.CreatePrimitiveValuesWithMetadata(true)); int numItems = random.NextFromRange(1, 3); var newItems = Enumerable.Range(0, numItems).Select(x => TestValues.GetDifferentPrimitiveValue(val)); var payload = new PrimitiveCollection(newItems.ToArray()); return(payload); }
/// <summary> /// Visits the payload element and removes the collection name if it is present. /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(PrimitiveCollection payloadElement) { CollectionNameAnnotation collectionNameAnnotation = payloadElement.GetAnnotation<CollectionNameAnnotation>(); if (payloadElement != null && collectionNameAnnotation != null) { payloadElement.Annotations.Remove(collectionNameAnnotation); } base.Visit(payloadElement); }
/// <summary> /// Visits the payload element and removes the collection name if it is present. /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(PrimitiveCollection payloadElement) { CollectionNameAnnotation collectionNameAnnotation = payloadElement.GetAnnotation <CollectionNameAnnotation>(); if (payloadElement != null && collectionNameAnnotation != null) { collectionNameAnnotation.Name = string.Empty; } base.Visit(payloadElement); }
/// <summary> /// Visits the payload element and removes the collection name if it is present. /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(PrimitiveCollection payloadElement) { CollectionNameAnnotation collectionNameAnnotation = payloadElement.GetAnnotation <CollectionNameAnnotation>(); if (payloadElement != null && collectionNameAnnotation != null) { payloadElement.Annotations.Remove(collectionNameAnnotation); } base.Visit(payloadElement); }
/// <summary> /// Calls the base class method to process the primitive collection. /// </summary> /// <param name="payloadElement">The primitive collection to process.</param> public override void Visit(PrimitiveCollection payloadElement) { ODataCollectionStart collectionStart = new ODataCollectionStart(); var annotation = new ODataCollectionItemsObjectModelAnnotation(); foreach (var primitive in payloadElement) { annotation.Add(primitive.ClrValue); } collectionStart.SetAnnotation <ODataCollectionItemsObjectModelAnnotation>(annotation); }
/// <summary> /// Visits the children of the given payload element and replaces it with a copy if any child changes /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public virtual ODataPayloadElement Visit(PrimitiveCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var replaced = this.VisitCollection(payloadElement); if (!this.ShouldReplace(replaced, payloadElement)) { return(payloadElement); } return(payloadElement.ReplaceWith(new PrimitiveCollection(replaced.ToArray()))); }
public void CollectionMessageSizeLimitReadTest() { EdmModel model = Test.OData.Utils.Metadata.TestModels.BuildTestModel() as EdmModel; var itemTypeAnnotationType = MetadataUtils.GetPrimitiveTypeReference(typeof(string)).Definition; var collectionTypeAnnotationType = MetadataUtils.GetPrimitiveTypeReference(typeof(string)).ToCollectionTypeReference().Definition; ODataPayloadElement payload = new PrimitiveCollection( PayloadBuilder.PrimitiveValue("Vienna").WithTypeAnnotation(itemTypeAnnotationType), PayloadBuilder.PrimitiveValue("Prague").WithTypeAnnotation(itemTypeAnnotationType), PayloadBuilder.PrimitiveValue("Redmond").WithTypeAnnotation(itemTypeAnnotationType)) .WithTypeAnnotation(collectionTypeAnnotationType) .ExpectedCollectionItemType(itemTypeAnnotationType).CollectionName("PrimitiveCollection"); var testCases = new MessageSizeLimitTestCase[] { // Single byte size should fail new MessageSizeLimitTestCase { MaxMessageSize = 1, AtomSizes = new RequestResponseSizes { RequestSize = 411, ResponseSize = 411 }, JsonLightSizes = new RequestResponseSizes { RequestSize = 123, ResponseSize = 123 }, }, // Small number should fail new MessageSizeLimitTestCase { MaxMessageSize = 20, AtomSizes = new RequestResponseSizes { RequestSize = 411, ResponseSize = 411 }, JsonLightSizes = new RequestResponseSizes { RequestSize = 123, ResponseSize = 123 }, }, // Large number should work new MessageSizeLimitTestCase { MaxMessageSize = 10000, }, // Default should work new MessageSizeLimitTestCase { MaxMessageSize = -1, }, }; this.RunAtomJsonMessageSizeLimitTests(model, payload, testCases); }
/// <summary> /// Visits a payload element whose root is a PrimitiveCollection. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public void Visit(PrimitiveCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); ExceptionUtilities.Assert(this.isRootElement, "Primitive collection is only supported as the root element"); this.isRootElement = false; this.writer.StartArrayScope(); foreach (var item in payloadElement) { this.Recurse(item); } this.writer.EndScope(); }
/// <summary> /// Visits a collection start. /// </summary> /// <param name="collection">The collection start to visit.</param> protected override ODataPayloadElement VisitCollectionStart(ODataCollectionStart collection) { ExceptionUtilities.CheckArgumentNotNull(collection, "collection"); // NOTE the Taupo OM does not currently support heterogenous collections; we determine the // type of the collection by looking at the first non-null item ODataCollectionItemsObjectModelAnnotation itemsAnnotation = collection.GetAnnotation <ODataCollectionItemsObjectModelAnnotation>(); ExceptionUtilities.Assert(itemsAnnotation != null, "itemsAnnotation != null"); // NOTE we assume that it is a primitive collection; if we find a collection of only null items we treat it as primitive bool isComplexCollection = false; foreach (object item in itemsAnnotation) { if (item != null) { isComplexCollection = item is ODataComplexValue; break; } } if (isComplexCollection) { ComplexInstanceCollection complexCollection = PayloadBuilder.ComplexCollection(collection.Name); foreach (object item in itemsAnnotation) { ComplexInstance complexInstance = item == null ? new ComplexInstance(null, /*isNull*/ true) : (ComplexInstance)this.Visit((ODataComplexValue)item); complexCollection.Add(complexInstance); } return(complexCollection); } else { PrimitiveCollection primitiveCollection = PayloadBuilder.PrimitiveCollection(collection.Name); foreach (object item in itemsAnnotation) { PrimitiveValue primitiveValue = (PrimitiveValue)this.Visit(item); primitiveCollection.Add(primitiveValue); } return(primitiveCollection); } }
/// <summary> /// Build QueryValue from action response payload /// </summary> /// <param name="payload">response payload element</param> /// <param name="queryType">query type to build</param> /// <returns>query value that represents the payload</returns> private QueryValue BuildQueryValueForActionResponse(ODataPayloadElement payload, QueryType queryType) { EntitySetInstance entitySetInstance = payload as EntitySetInstance; PrimitiveProperty primitiveProperty = payload as PrimitiveProperty; ComplexProperty complexProperty = payload as ComplexProperty; PrimitiveMultiValueProperty primitiveMultiValueProperty = payload as PrimitiveMultiValueProperty; ComplexMultiValueProperty complexMultiValueProperty = payload as ComplexMultiValueProperty; PrimitiveCollection primitiveCollection = payload as PrimitiveCollection; ComplexInstanceCollection complexInstanceCollection = payload as ComplexInstanceCollection; if (entitySetInstance != null) { var xmlBaseAnnotations = payload.Annotations.OfType <XmlBaseAnnotation>(); var collectionType = this.currentExpression.ExpressionType as QueryCollectionType; ExceptionUtilities.CheckObjectNotNull(collectionType, "Cannot cast expression type to QueryCollectionType."); var elementType = collectionType.ElementType as QueryEntityType; return(this.BuildFromEntitySetInstance(entitySetInstance, elementType, xmlBaseAnnotations)); } else if (primitiveProperty != null) { return(this.PayloadElementToQueryValueConverter.Convert(primitiveProperty.Value, queryType)); } else if (complexProperty != null) { return(this.PayloadElementToQueryValueConverter.Convert(complexProperty.Value, queryType)); } else if (primitiveMultiValueProperty != null) { return(this.PayloadElementToQueryValueConverter.Convert(primitiveMultiValueProperty.Value, queryType)); } else if (complexMultiValueProperty != null) { return(this.PayloadElementToQueryValueConverter.Convert(complexMultiValueProperty.Value, queryType)); } else if (primitiveCollection != null) { return(this.PayloadElementToQueryValueConverter.Convert(primitiveCollection, queryType)); } else if (complexInstanceCollection != null) { return(this.PayloadElementToQueryValueConverter.Convert(complexInstanceCollection, queryType)); } else { ExceptionUtilities.CheckArgumentNotNull(payload as EntityInstance, "Unexpected response payload type: " + payload.ElementType + "."); return(this.PayloadElementToQueryValueConverter.Convert(payload, queryType)); } }
/// <summary> /// Normalizes primitive properties, potentially replacing them with collections if the metadata indicates the payload is from a service operation /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(PrimitiveProperty payloadElement) { var replaced = base.Visit(payloadElement); if (replaced.ElementType == ODataPayloadElementType.PrimitiveProperty) { payloadElement = (PrimitiveProperty)replaced; // if the payload looks like // <Foo /> // then it will be deserialized as a primitive property, when it could be an empty collection // if (this.ShouldReplaceWithCollection(payloadElement, payloadElement.Value.IsNull, payloadElement.Value.FullTypeName)) { // if the value is an empty string var stringValue = payloadElement.Value.ClrValue as string; if (stringValue != null && stringValue.Length == 0) { // get the element data type. Note that this must succeed based on the checks performed earlier var dataType = ((CollectionDataType)payloadElement.Annotations.OfType <DataTypeAnnotation>().Single().DataType).ElementDataType; // determine whether to return a complex or primitive collection based on the data type ODataPayloadElementCollection collection; if (dataType is PrimitiveDataType) { collection = new PrimitiveCollection(); } else { ExceptionUtilities.Assert(dataType is ComplexDataType, "Data type was neither primitive nor complex"); collection = new ComplexInstanceCollection(); } // return the replacement return(payloadElement .ReplaceWith(collection) .WithAnnotations(new CollectionNameAnnotation() { Name = payloadElement.Name })); } } } return(replaced); }
/// <summary> /// Visits a collection start. /// </summary> /// <param name="collection">The collection start to visit.</param> protected override ODataPayloadElement VisitCollectionStart(ODataCollectionStart collection) { ExceptionUtilities.CheckArgumentNotNull(collection, "collection"); // NOTE the Taupo OM does not currently support heterogenous collections; we determine the // type of the collection by looking at the first non-null item ODataCollectionItemsObjectModelAnnotation itemsAnnotation = collection.GetAnnotation <ODataCollectionItemsObjectModelAnnotation>(); ExceptionUtilities.Assert(itemsAnnotation != null, "itemsAnnotation != null"); PrimitiveCollection primitiveCollection = PayloadBuilder.PrimitiveCollection(collection.Name); foreach (object item in itemsAnnotation) { PrimitiveValue primitiveValue = (PrimitiveValue)this.Visit(item); primitiveCollection.Add(primitiveValue); } return(primitiveCollection); }
/// <summary> /// Converts the given payload into a series of named value pairs /// </summary> /// <param name="element">The payload to convert</param> /// <param name="queryTypeToBuild">Query Type to build</param> /// <returns>The queryValue that represents the ODataPayload</returns> public QueryValue Convert(ODataPayloadElement element, QueryType queryTypeToBuild) { var typedValue = element as ITypedValue; if (typedValue != null && typedValue.IsNull) { return(queryTypeToBuild.NullValue); } var queryCollectionType = queryTypeToBuild as QueryCollectionType; // return empty QueryCollectionValue for all types of empty collections PrimitiveCollection primitiveCollection = element as PrimitiveCollection; ComplexInstanceCollection complexInstanceCollection = element as ComplexInstanceCollection; PrimitiveMultiValue primitiveMultiValue = element as PrimitiveMultiValue; ComplexMultiValue complexMultiValue = element as ComplexMultiValue; if ((primitiveCollection != null && primitiveCollection.Count == 0) || (complexInstanceCollection != null && complexInstanceCollection.Count == 0) || (primitiveMultiValue != null && primitiveMultiValue.Count == 0) || (complexMultiValue != null && complexMultiValue.Count == 0)) { return(queryCollectionType.CreateCollectionWithValues(new QueryValue[] { })); } if (element.ElementType == ODataPayloadElementType.PrimitiveValue) { return(CreateQueryScalarValue(element, queryTypeToBuild)); } else if (queryCollectionType != null && element.ElementType == ODataPayloadElementType.PrimitiveMultiValue) { return(queryCollectionType.CreateCollectionWithValues(primitiveMultiValue.Select(p => CreateQueryScalarValue(p, queryCollectionType.ElementType)))); } var namedValues = this.PayloadElementToNamedValuesConverter.ConvertToNamedValues(element); return(this.NamedValueToQueryValueConverter.Convert(namedValues, queryTypeToBuild)); }
/// <summary> /// Calls the base class method to process the primitive collection. /// </summary> /// <param name="payloadElement">The primitive collection to process.</param> public override void Visit(PrimitiveCollection payloadElement) { ODataCollectionStart collectionStart = new ODataCollectionStart(); var annotation = new ODataCollectionItemsObjectModelAnnotation(); foreach (var primitive in payloadElement) { annotation.Add(primitive.ClrValue); } collectionStart.SetAnnotation<ODataCollectionItemsObjectModelAnnotation>(annotation); }
/// <summary> /// Normalizes primitive properties, potentially replacing them with collections if the metadata indicates the payload is from a service operation /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(PrimitiveProperty payloadElement) { var replaced = base.Visit(payloadElement); if (replaced.ElementType == ODataPayloadElementType.PrimitiveProperty) { payloadElement = (PrimitiveProperty)replaced; // if the payload looks like // <Foo /> // then it will be deserialized as a primitive property, when it could be an empty collection // if (this.ShouldReplaceWithCollection(payloadElement, payloadElement.Value.IsNull, payloadElement.Value.FullTypeName)) { // if the value is an empty string var stringValue = payloadElement.Value.ClrValue as string; if (stringValue != null && stringValue.Length == 0) { // get the element data type. Note that this must succeed based on the checks performed earlier var dataType = ((CollectionDataType)payloadElement.Annotations.OfType<DataTypeAnnotation>().Single().DataType).ElementDataType; // determine whether to return a complex or primitive collection based on the data type ODataPayloadElementCollection collection; if (dataType is PrimitiveDataType) { collection = new PrimitiveCollection(); } else { ExceptionUtilities.Assert(dataType is ComplexDataType, "Data type was neither primitive nor complex"); collection = new ComplexInstanceCollection(); } // return the replacement return payloadElement .ReplaceWith(collection) .WithAnnotations(new CollectionNameAnnotation() { Name = payloadElement.Name }); } } } return replaced; }
/// <summary> /// Normalizes complex properties, potentially replacing them with collections if the metadata indicates the payload is from a service operation /// </summary> /// <param name="payloadElement">The payload element to potentially replace</param> /// <returns>The original element or a copy to replace it with</returns> public override ODataPayloadElement Visit(ComplexProperty payloadElement) { var replaced = base.Visit(payloadElement); if (replaced.ElementType == ODataPayloadElementType.ComplexProperty) { payloadElement = (ComplexProperty)replaced; // if the payload looks like // <Foo> // <element m:type="Edm.Int32">3</element> // </Foo> // or // <Foo> // <element m:type="Complex"> // <Bar>3</Bar> // </element> // </Foo> // then it may be deserialized as a complex instance with exactly 1 property, when it should be a collection of size 1 // if (this.ShouldReplaceWithCollection(payloadElement, payloadElement.Value.IsNull, payloadElement.Value.FullTypeName)) { // only replace if there is exactly 1 property if (payloadElement.Value.Properties.Count() == 1) { // get the single property and check to see if its name is 'element' var property = payloadElement.Value.Properties.Single(); if (property.Name == ODataConstants.CollectionItemElementName) { // determine whether it is a primitive or complex value based on the kind of property ODataPayloadElementCollection collection = null; if (property.ElementType == ODataPayloadElementType.PrimitiveProperty) { var primitiveProperty = (PrimitiveProperty)property; collection = new PrimitiveCollection(primitiveProperty.Value); } else if (property.ElementType == ODataPayloadElementType.ComplexProperty) { var complexProperty = (ComplexProperty)property; collection = new ComplexInstanceCollection(complexProperty.Value); } // if it was primitive or complex, replace it if (collection != null) { return payloadElement .ReplaceWith(collection) .WithAnnotations(new CollectionNameAnnotation() { Name = payloadElement.Name }); } } } } } return replaced; }
/// <summary> /// Visits a payload element whose root is a PrimitiveCollection. /// </summary> /// <param name="payloadElement">The root node of the payload element being visited.</param> public override void Visit(PrimitiveCollection payloadElement) { base.Visit(payloadElement); this.AddExpectedFunctionImportToCollection(payloadElement); }
/// <summary> /// Calls the base class method to process the primitive collection. /// </summary> /// <param name="payloadElement">The primitive collection to process.</param> public override void Visit(PrimitiveCollection payloadElement) { base.Visit(payloadElement); }
/// <summary> /// Converts the given name/value pair into a property element. /// And infers the type of property from the converted value. /// </summary> /// <param name="jsonProperty">the property value</param> /// <returns>the converted property</returns> private PropertyInstance ConvertProperty(JsonProperty jsonProperty) { if (jsonProperty.Value.JsonType == JsonValueType.JsonPrimitiveValue && ((JsonPrimitiveValue)jsonProperty.Value).Value == null) { return(new NullPropertyInstance() { Name = jsonProperty.Name }); } else { ODataPayloadElement elem = this.ConvertValue(jsonProperty.Value); ExceptionUtilities.CheckObjectNotNull(elem, "Converted property value was null"); if (elem.ElementType == ODataPayloadElementType.PrimitiveValue) { return(new PrimitiveProperty(jsonProperty.Name, (PrimitiveValue)elem)); } else if (elem.ElementType == ODataPayloadElementType.ComplexInstance) { return(new ComplexProperty(jsonProperty.Name, (ComplexInstance)elem)); } else if (elem.ElementType == ODataPayloadElementType.EntityInstance) { return(new NavigationPropertyInstance(jsonProperty.Name, new ExpandedLink(elem))); } else if (elem.ElementType == ODataPayloadElementType.DeferredLink) { DeferredLink deferredLink = (DeferredLink)elem; return(new NavigationPropertyInstance(jsonProperty.Name, deferredLink)); } else if (elem.ElementType == ODataPayloadElementType.EntitySetInstance) { return(new NavigationPropertyInstance(jsonProperty.Name, elem)); } else if (elem.ElementType == ODataPayloadElementType.ComplexMultiValue) { ComplexMultiValue complexMultiValue = (ComplexMultiValue)elem; return(new ComplexMultiValueProperty(jsonProperty.Name, complexMultiValue)); } else if (elem.ElementType == ODataPayloadElementType.PrimitiveMultiValue) { PrimitiveMultiValue primitiveMultiValue = (PrimitiveMultiValue)elem; return(new PrimitiveMultiValueProperty(jsonProperty.Name, primitiveMultiValue)); } else if (elem.ElementType == ODataPayloadElementType.ComplexInstanceCollection) { ComplexInstanceCollection complexCollection = (ComplexInstanceCollection)elem; return(new ComplexMultiValueProperty(jsonProperty.Name, new ComplexMultiValue(null, false, complexCollection.ToArray()))); } else if (elem.ElementType == ODataPayloadElementType.PrimitiveCollection) { PrimitiveCollection primitiveCollection = (PrimitiveCollection)elem; return(new PrimitiveMultiValueProperty(jsonProperty.Name, new PrimitiveMultiValue(null, false, primitiveCollection.ToArray()))); } else if (elem.ElementType == ODataPayloadElementType.NamedStreamInstance) { NamedStreamInstance nsi = (NamedStreamInstance)elem; nsi.Name = jsonProperty.Name; return(nsi); } else { ExceptionUtilities.Assert(elem.ElementType == ODataPayloadElementType.EmptyUntypedCollection, "Do not know how to handle element of type" + elem.ElementType); return(new EmptyCollectionProperty(jsonProperty.Name, (EmptyUntypedCollection)elem)); } } }
/// <summary> /// Visits a payload element whose root is a PrimitiveCollection. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public void Visit(PrimitiveCollection payloadElement) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); var current = this.expectedValueStack.Peek(); var value = current as QueryCollectionValue; ExceptionUtilities.CheckObjectNotNull(value, "Value was not a collection. Value was: '{0}'", current.ToString()); this.parent.Assert.AreEqual(value.Elements.Count, payloadElement.Count, "Primitive collection count did not match expectation"); for (int i = 0; i < value.Elements.Count; i++) { this.RecurseWithMessage(payloadElement[i], value.Elements[i], "Primitive value at position {0} did not match expectation", i + 1); } }
private static PrimitiveCollection GetPrimitiveCollection(IRandomNumberGenerator random) { TestValues.CreatePrimitiveValuesWithMetadata(true); PrimitiveValue val = random.ChooseFrom(TestValues.CreatePrimitiveValuesWithMetadata(true)); int numItems = random.NextFromRange(1, 3); var newItems = Enumerable.Range(0, numItems).Select(x => TestValues.GetDifferentPrimitiveValue(val)); var payload = new PrimitiveCollection(newItems.ToArray()); return payload; }
/// <summary> /// Visits the payload element. /// </summary> /// <param name="payloadElement">The payload element to visit.</param> public override void Visit(PrimitiveCollection payloadElement) { var observed = this.GetNextObservedElement <PrimitiveCollection>(); this.VisitEnumerable(payloadElement, observed); }
/// <summary> /// Visits the payload element /// </summary> /// <param name="payloadElement">The payload element to visit</param> public virtual void Visit(PrimitiveCollection payloadElement) { this.VisitCollection(payloadElement); }
/// <summary> /// Visits the payload element and removes the collection name if it is present. /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(PrimitiveCollection payloadElement) { payloadElement.RemoveAnnotations(typeof(CollectionNameAnnotation)); base.Visit(payloadElement); }
/// <summary> /// Visits a payload element whose root is a PrimitiveCollection. /// </summary> /// <param name="payloadElement">The root node of payload element being visited.</param> public override void Visit(PrimitiveCollection payloadElement) { RemoveChangeAnnotations(payloadElement); base.Visit(payloadElement); }
/// <summary> /// Visits the payload element /// </summary> /// <param name="payloadElement">The payload element to visit</param> public override void Visit(PrimitiveCollection payloadElement) { this.SerializeTypedValueCollection(payloadElement); }