Exemplo n.º 1
0
            public void UpdateBindToCollection_SimpleScenario()
            {
                var payloadBuilder = new PayloadBuilder() { Uri = "/Orders(0) "};

                var atomUriAndXPaths = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>(
                        "/Customers(1)/Orders(0)/$ref",
                        new string[] { "/adsm:ref[@id='http://host/Orders(0)']" }),
                    new KeyValuePair<string, string[]>(
                        "/Customers(1)/Orders(0)",
                        new string[] { "/atom:entry[atom:category/@term='#" + typeof(Order).FullName + 
                            "' and atom:id='http://host/Orders(0)' and atom:content/adsm:properties[ads:ID='0' and ads:DollarAmount='20.1']]" })
                };

                var jsonLiteUriAndXPaths = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>(
                        "/Customers(1)/Orders(0)/$ref",
                        new string[] { String.Format("/{0}[odata.id='http://host/Orders(0)']", JsonValidator.ObjectString) }),
                    new KeyValuePair<string, string[]>(
                        "/Customers(1)/Orders(0)",
                        new string[] { String.Format("/{0}[ID=0 and DollarAmount=20.1]",
                                       JsonValidator.ObjectString) })
                };

                UnitTestsUtil.DoInsertsForVariousProviders("/Customers(1)/Orders/$ref", UnitTestsUtil.AtomFormat, payloadBuilder, atomUriAndXPaths, false/*verifyETag*/);
                UnitTestsUtil.DoInsertsForVariousProviders("/Customers(1)/Orders/$ref", UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteUriAndXPaths, false/*verifyETag*/);
            }
Exemplo n.º 2
0
 protected abstract void GenerateJson(PayloadBuilder payloadBuilder, bool topLevel = false);
Exemplo n.º 3
0
            public void UpdatePostInsertResourceToCollection()
            {
                #region Payload
                var payloadBuilder = new PayloadBuilder() { TypeName = typeof(Order).FullName }
                    .AddProperty("ID", 151)
                    .AddProperty("DollarAmount", 1500.00);
                #endregion

                #region AtomPayload And XPaths
                var atomXPath1 = new KeyValuePair<string, string[]>(
                    "/Customers(1)/Orders",
                    new string[] { "/atom:entry[atom:category/@term='#" + typeof(Order).FullName + "' and atom:id='http://host/Orders(151)' and atom:content/adsm:properties[ads:ID='151' and ads:DollarAmount='1500']]" });

                var atomXPath2 = new KeyValuePair<string, string[]>(
                    "/Orders",
                    new string[] { "/atom:feed/atom:entry[atom:category/@term='#" + typeof(Order).FullName + "' and atom:id='http://host/Orders(151)' and atom:content/adsm:properties[ads:ID='151' and ads:DollarAmount='1500']]" });
                #endregion //AtomPayload And XPaths

                #region JsonXPaths
                var jsonLiteXPath1 = new KeyValuePair<string, string[]>(
                    "/Customers(1)/Orders",
                    new string[] { String.Format("/{0}[ID=151 and DollarAmount=1500]", JsonValidator.ObjectString) });

                var jsonLiteXPath2 = new KeyValuePair<string, string[]>(
                    "/Orders",
                    new string[] { String.Format("//{0}/{1}[ID=151 and DollarAmount=1500]",
                                    JsonValidator.ArrayString, JsonValidator.ObjectString) });
                #endregion //JsonXPaths

                UnitTestsUtil.DoInsertsForVariousProviders("/Customers(1)/Orders", UnitTestsUtil.AtomFormat, payloadBuilder, new KeyValuePair<string, string[]>[] { atomXPath1, atomXPath2 }, false/*verifyETag*/);
                UnitTestsUtil.DoInsertsForVariousProviders("/Customers(1)/Orders", UnitTestsUtil.JsonLightMimeType, payloadBuilder, new KeyValuePair<string, string[]>[] { jsonLiteXPath1, jsonLiteXPath2}, false/*verifyETag*/);
            }
Exemplo n.º 4
0
            public void UpdatePostInsertAndBindReferenceResource()
            {
                #region Payload
                PayloadBuilder payloadGenerator = new PayloadBuilder() { TypeName = typeof(Customer).FullName }
                    .AddProperty("Name", "Bar")
                    .AddProperty("ID", 125)
                    .AddProperty("BestFriend", new PayloadBuilder()
                        {
                            TypeName = typeof(CustomerWithBirthday).FullName,
                            Uri = "/Customers(1)",
                        });

                #endregion // Payload

                #region Atom XPaths
                var atomXPaths1 = new KeyValuePair<string, string[]>(
                    "/Customers",
                    new string[] { "/atom:entry[atom:category/@term='#AstoriaUnitTests.Stubs.Customer' and atom:id='http://host/Customers(125)' and atom:content/adsm:properties[ads:Name='Bar' and ads:ID='125']]" });

                var atomXPaths2 = new KeyValuePair<string, string[]>(
                    "/Customers(125)/BestFriend",
                    new string[] { "/atom:entry[atom:category/@term='#AstoriaUnitTests.Stubs.CustomerWithBirthday' and atom:id='http://host/Customers(1)' and atom:content/adsm:properties/ads:ID='1']" });
                #endregion

                #region JsonLite XPaths
                var jsonLiteXPaths1 = new KeyValuePair<string, string[]>(
                    "/Customers",
                    new string[] { String.Format("/{0}[ID=125 and Name='Bar']", JsonValidator.ObjectString)});

                var jsonLiteXPaths2 = new KeyValuePair<string, string[]>(
                    "/Customers(125)/BestFriend",
                    new string[] { String.Format("/{0}[odata.type='#{1}' and ID=1]", JsonValidator.ObjectString, typeof(CustomerWithBirthday).FullName)});
                #endregion

                UnitTestsUtil.DoInsertsForVariousProviders("/Customers", UnitTestsUtil.AtomFormat, payloadGenerator, new KeyValuePair<string, string[]>[] { atomXPaths1, atomXPaths2 }, true/*verifyETag*/);
                UnitTestsUtil.DoInsertsForVariousProviders("/Customers", UnitTestsUtil.JsonLightMimeType, payloadGenerator, new KeyValuePair<string, string[]>[] { jsonLiteXPaths1, jsonLiteXPaths2 }, true/*verifyETag*/);
            }
Exemplo n.º 5
0
 internal static void VerifyInvalidRequestForVariousProviders1(PayloadBuilder payloadBuilder, string uri, string contentFormat, string httpMethodName, int expectedHttpErrorCode, string errorMessage = null)
 {
     UnitTestsUtil.VerifyInvalidRequest(PayloadGenerator.Generate(payloadBuilder, contentFormat), uri, typeof(CustomDataContext), contentFormat, httpMethodName, expectedHttpErrorCode, errorMessage);
 }
Exemplo n.º 6
0
 internal static void DoUpdatesForVariousProviders(
     string method,
     string uri,
     string responseFormat,
     PayloadBuilder payloadBuilder,
     KeyValuePair<string, string[]>[] uriAndXPathsToVerify,
     bool verifyETag,
     bool includeOpenTypesProvider = true,
     bool verifyResponsePreference = true)
 {
     TestUtil.RunCombinations(
             UnitTestsUtil.ProviderTypes.Where(providerType => includeOpenTypesProvider || providerType != typeof(CustomRowBasedOpenTypesContext)),
             (providerType) =>
             {
                 using (UnitTestsUtil.AppendTypesForOpenProperties(providerType, payloadBuilder, responseFormat))
                 {
                     DoUpdatesForVariousProviders(
                         providerType,
                         method,
                         uri,
                         responseFormat,
                         PayloadGenerator.Generate(payloadBuilder, responseFormat),
                         uriAndXPathsToVerify,
                         verifyETag,
                         includeOpenTypesProvider,
                         verifyResponsePreference);
                 }
             });
 }
Exemplo n.º 7
0
 internal static void DoUpdatesForVariousProvidersWithOpenMissing(string method, string uri, string responseFormat, PayloadBuilder payloadBuilder, string[] xPaths, bool verifyETag, bool verifyResponsePreference = true)
 {
     KeyValuePair<string, string[]>[] uriAndXPathsToVerify = new KeyValuePair<string, string[]>[] { new KeyValuePair<string, string[]>(uri, xPaths) };
     DoUpdatesForVariousProvidersWithOpenMissing(method, uri, responseFormat, payloadBuilder, uriAndXPathsToVerify, verifyETag, verifyResponsePreference);
 }
Exemplo n.º 8
0
            public void UpdateSetReferencePropertyToNullViaAValidUri()
            {
                string uri = "/Customers(1)";
                string instanceTypeName = typeof(CustomerWithBirthday).FullName;
                PayloadBuilder payloadBuilder = new PayloadBuilder() { TypeName = instanceTypeName }
                    .AddProperty("BestFriend", new PayloadBuilder() { Uri = "/Customers(0)/BestFriend" });

                var atomUriAndXPaths = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(1)", new string[] { "/atom:entry[atom:category/@term='#" + instanceTypeName + "' and atom:id='http://host/Customers(1)']" }),
                    new KeyValuePair<string, string[]>("/Customers(1)?$expand=BestFriend",
                        new string[] { String.Format("/atom:entry/atom:link[@href='Customers(1)/{0}/BestFriend' and adsm:inline[string()='']]", instanceTypeName) } ) };

                var jsonLiteUriAndXPaths = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(1)?$expand=BestFriend",
                        new string[] { String.Format("/{0}/BestFriend[@IsNull='true']", JsonValidator.ObjectString) })};

                DoUpdatesForVariousProviders("PATCH", uri, UnitTestsUtil.AtomFormat, payloadBuilder, atomUriAndXPaths, true, true /*verifyUpdateResponse*/);
                DoUpdatesForVariousProviders("PATCH", uri, UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteUriAndXPaths, true, true /*verifyUpdateResponse*/);
            }
Exemplo n.º 9
0
        private void GeneratePayload(XmlWriter writer, PayloadBuilder builder)
        {
            if (builder.IsComplex)
            {
                GeneratePropertiesPayload(writer, builder);
                return;
            }

            writer.WriteStartElement("entry", AtomUpdatePayloadBuilder.AtomXmlNamespace);
            WriteCommonNamespaces(writer);

            if (!String.IsNullOrEmpty(builder.Id))
            {
                writer.WriteStartElement("id", AtomUpdatePayloadBuilder.AtomXmlNamespace);
                writer.WriteValue(builder.Id);
                writer.WriteEndElement();
            }

            if (!String.IsNullOrEmpty(builder.TypeName))
            {
                writer.WriteStartElement("category", AtomUpdatePayloadBuilder.AtomXmlNamespace);
                writer.WriteAttributeString("term", builder.TypeName);
                writer.WriteAttributeString("scheme", AtomUpdatePayloadBuilder.DataWebSchemeNamespace);
                writer.WriteEndElement();
            }

            var navProperties = new List<PropertyPayloadBuilder>();
            if (builder.Properties != null && builder.Properties.Count() != 0)
            {
                writer.WriteStartElement("content", AtomUpdatePayloadBuilder.AtomXmlNamespace);
                writer.WriteAttributeString("type", "application/xml");
                writer.WriteStartElement("properties", AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace);
                navProperties = this.GeneratePropertiesPayload(writer, builder);
                writer.WriteEndElement(); //properties
                writer.WriteEndElement(); //content
            }

            // write the nav properties
            foreach (var pi in navProperties)
            {
                PayloadBuilder referenceNavProperty = pi.Value as PayloadBuilder;
                if (pi.PropertyKind == PayloadBuilderPropertyKind.EntityReference || referenceNavProperty != null)
                {
                    writer.WriteStartElement("link", AtomUpdatePayloadBuilder.AtomXmlNamespace);

                    writer.WriteAttributeString("rel", AtomUpdatePayloadBuilder.DataWebRelatedXmlNamespace + pi.Name);
                    writer.WriteAttributeString("title", pi.Name);

                    // If there is only uri element specified, then its a binding case and we need to emit
                    // an href attribute, otherwise it might be deep insert and we need to specify the whole entity
                    if ((pi.PropertyKind == PayloadBuilderPropertyKind.EntityReference && pi.Value == null) || IsEntityBindingPayload(referenceNavProperty))
                    {
                        writer.WriteAttributeString("href", pi.Value == null ? string.Empty : referenceNavProperty.Uri);
                    }
                    else
                    {
                        writer.WriteStartElement("inline", AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace);
                        this.GeneratePayload(writer, referenceNavProperty);
                        writer.WriteEndElement(); // inline
                    }

                    writer.WriteEndElement(); // link
                }
                else
                {
                    PayloadBuilder[] navCollectionProperty = (PayloadBuilder[])pi.Value;

                    foreach (var bindProperty in navCollectionProperty.Where(p => IsEntityBindingPayload(p)))
                    {
                        writer.WriteStartElement("link", AtomUpdatePayloadBuilder.AtomXmlNamespace);

                        writer.WriteAttributeString("rel", AtomUpdatePayloadBuilder.DataWebRelatedXmlNamespace + pi.Name);
                        writer.WriteAttributeString("title", pi.Name);
                        writer.WriteAttributeString("href", bindProperty.Uri);
                        writer.WriteEndElement(); // link
                    }

                    var insertPayloads = navCollectionProperty.Where(p => IsEntityInsertPayload(p)).ToList();
                    if (insertPayloads.Count > 0)
                    {
                        writer.WriteStartElement("link", AtomUpdatePayloadBuilder.AtomXmlNamespace);

                        writer.WriteAttributeString("rel", AtomUpdatePayloadBuilder.DataWebRelatedXmlNamespace + pi.Name);
                        writer.WriteAttributeString("title", pi.Name);

                        writer.WriteStartElement("inline", AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace);
                        writer.WriteStartElement("feed", AtomUpdatePayloadBuilder.AtomXmlNamespace);

                        foreach (var element in insertPayloads)
                        {
                            this.GeneratePayload(writer, element);
                        }

                        writer.WriteEndElement(); //feed
                        writer.WriteEndElement(); //inline
                        writer.WriteEndElement(); // link
                    }
                }
            }

            // Write the operations
            foreach (var operation in builder.Operations)
            {
                var operationKind = operation.PropertyKind == PayloadBuilderPropertyKind.Action ? "action" : "function";
                writer.WriteStartElement(operationKind, AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace);

                if (operation.Title != null)
                {
                    writer.WriteAttributeString("title", operation.Title);
                }

                if (operation.Metadata != null)
                {
                    writer.WriteAttributeString("metadata", operation.Metadata);
                }

                if (operation.Target != null)
                {
                    writer.WriteAttributeString("target", operation.Target);
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement(); // entry
        }
Exemplo n.º 10
0
        public override string Generate(PayloadBuilder payloadBuilder)
        {
            StringBuilder stringBuilder = new StringBuilder();
            using (XmlWriter writer = CreateXmlWriterAndWriteProcessingInstruction(stringBuilder))
            {
                this.GeneratePayload(writer, payloadBuilder);
            }

            return stringBuilder.ToString();
        }
Exemplo n.º 11
0
        public override string GenerateLinkPayload(PayloadBuilder payloadBuilder)
        {
            StringBuilder stringBuilder = new StringBuilder();
            using (XmlWriter writer = CreateXmlWriterAndWriteProcessingInstruction(stringBuilder))
            {
                writer.WriteStartElement("ref", AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace);
                writer.WriteAttributeString("id", payloadBuilder.Uri);
                writer.WriteEndElement();
            }

            return stringBuilder.ToString();
        }
Exemplo n.º 12
0
        protected override void GenerateJson(PayloadBuilder builder, bool topLevel = false)
        {
            this.WriteStartObject();
            this.WriteMetadata(builder.TypeName, builder.Uri);

            if (builder.Properties != null)
            {
                foreach (var pi in builder.Properties)
                {
                    if (pi.Value == null || pi.PropertyKind == PayloadBuilderPropertyKind.Primitive)
                    {
                        this.WriteKeyValuePair(pi.Name, JsonPrimitiveTypesUtil.PrimitiveToString(pi.Value, null));
                    }
                    else
                    {
                        this.WriteKey(pi.Name);
                        PayloadBuilder structuredPayload = pi.Value as PayloadBuilder;
                        if (structuredPayload != null)
                        {
                            this.GenerateJson(structuredPayload);
                        }
                        else if (pi.PropertyKind == PayloadBuilderPropertyKind.Collection)
                        {
                            this.WriteCollectionValue((CollectionPropertyPayloadBuilder)pi, writeCollectionTypeName: true);
                        }
                        else
                        {
                            PayloadBuilder[] collectionProperties = pi.Value as PayloadBuilder[];
                            this.WriteStartArray();
                            bool firstElement = true;
                            foreach (var element in collectionProperties)
                            {
                                if (!firstElement) this.WriteValue(",");
                                this.GenerateJson(element);
                                firstElement = false;
                            }

                            this.WriteEndArray();
                        }
                    }
                }
            }

            this.WriteEndObject();
        }
Exemplo n.º 13
0
 public sealed override string GenerateLinkPayload(PayloadBuilder payloadBuilder)
 {
     this.WriteStartObject();
     this.WriteKeyValuePair("uri", this.GetQuotedString(payloadBuilder.Uri));
     this.WriteEndObject();
     return stringBuilder.ToString();
 }
Exemplo n.º 14
0
        private void GeneratePropertyPayload(PayloadBuilder builder)
        {
            Assert.IsTrue(builder.Properties.Count() == 1, "There must be exactly one property specified");
            var property = builder.Properties.Single();

            var propertyValue = property.Value as PayloadBuilder;
            if (propertyValue != null)
            {
                this.GenerateJson(propertyValue);
            }
            else
            {
                this.WriteStartObject();

                // For open properties, we need to write the type name first as property annotation
                if (builder.OpenProperties != null && builder.OpenProperties.Exists(n => n == property.Name) && property.Value != null)
                {
                    PayloadGenerator payloadGenerator = property.Value as PayloadGenerator;
                    if (payloadGenerator == null)
                    {
                        // Write the type annotation
                        // TODO: make this work for byte[] and System.Linq.Binary types
                        string typeName = property.Value.GetType().ToString().Replace("System", "Edm");
                        this.WriteKeyValuePair("@odata.type", this.GetQuotedString(GetPrefixTypeName(RemoveEdmPrefixFromTypeName(typeName))));
                    }
                }

                if (property.Value == null)
                {
                    this.WriteKeyValuePair("@odata.null", "true");
                }
                else if (property.PropertyKind == PayloadBuilderPropertyKind.Primitive || property.Value == null)
                {
                    // Write primitive property value
                    this.WriteKeyValuePair("value", JsonPrimitiveTypesUtil.PrimitiveToString(property.Value, null));
                }

                this.WriteEndObject();
            }
        }
Exemplo n.º 15
0
        protected override void GenerateJson(PayloadBuilder builder, bool topLevel = false)
        {
            if (builder.IsComplex && topLevel)
            {
                this.GeneratePropertyPayload(builder);
                return;
            }

            this.WriteStartObject();

            if (!String.IsNullOrEmpty(builder.Metadata))
            {
                this.WriteKeyValuePair("@odata.context", this.GetQuotedString(builder.Metadata));
            }

            if (!String.IsNullOrEmpty(builder.TypeName))
            {
                this.WriteTypeMetadata(builder.TypeName);
            }

            if (!builder.IsComplex && !String.IsNullOrEmpty(builder.Uri))
            {
                this.WriteKeyValuePair("@odata.editLink", this.GetQuotedString(builder.Uri));
            }

            // Write the operations
            foreach (var operation in builder.Operations)
            {
                this.WriteKey(this.GetQuotedString(operation.Metadata));

                this.WriteStartObject();

                if (!String.IsNullOrEmpty(operation.Title))
                {
                    this.WriteKeyValuePair("title", this.GetQuotedString(operation.Title));
                }

                if (!String.IsNullOrEmpty(operation.Target))
                {
                    this.WriteKeyValuePair("target", this.GetQuotedString(operation.Target));
                }

                this.WriteEndObject();
            }

            if (builder.Properties != null)
            {
                foreach (var pi in builder.Properties)
                {
                    // For open properties, we need to write the type name first as property annotation
                    if (builder.OpenProperties != null && builder.OpenProperties.Exists(n => n == pi.Name) && pi.Value != null)
                    {
                        PayloadGenerator payloadGenerator = pi.Value as PayloadGenerator;
                        if (payloadGenerator == null)
                        {
                            // Write the type annotation
                            // TODO: make this work for byte[] and System.Linq.Binary types
                            string typeName = pi.Value.GetType().ToString().Replace("System", "Edm");
                            this.WriteKeyValuePair(pi.Name + "@odata.type", this.GetQuotedString(GetPrefixTypeName(RemoveEdmPrefixFromTypeName(typeName))));
                        }
                    }

                    if (pi.PropertyKind == PayloadBuilderPropertyKind.Primitive || pi.Value == null)
                    {
                        // Write primitive property value
                        this.WriteKeyValuePair(pi.Name, JsonPrimitiveTypesUtil.PrimitiveToString(pi.Value, null));
                    }
                    else if (pi.PropertyKind == PayloadBuilderPropertyKind.Enum)
                    {
                        // Write enum property value
                        this.WriteKeyValuePair(pi.Name, pi.Value + "");
                    }
                    else
                    {
                        PayloadBuilder structuredPropertyValue = pi.Value as PayloadBuilder;
                        if (structuredPropertyValue != null)
                        {
                            if (IsEntityBindingPayload(structuredPropertyValue))
                            {
                                this.WriteKeyValuePair(pi.Name + "@odata.bind", this.GetQuotedString(structuredPropertyValue.Uri));
                            }
                            else
                            {
                                this.WriteKey(pi.Name);
                                this.GenerateJson(structuredPropertyValue);
                            }
                        }
                        else if (pi.PropertyKind == PayloadBuilderPropertyKind.Collection)
                        {
                            var collectionPropertyPayloadBuilder = (CollectionPropertyPayloadBuilder)pi;
                            if (!String.IsNullOrEmpty(collectionPropertyPayloadBuilder.CollectionEdmTypeName))
                            {
                                this.WriteKeyValuePair(pi.Name + "@odata.type", this.GetQuotedString(GetPrefixTypeName(RemoveEdmPrefixFromTypeName(collectionPropertyPayloadBuilder.CollectionEdmTypeName))));
                            }
                            this.WriteKey(pi.Name);
                            this.WriteCollectionValue(collectionPropertyPayloadBuilder, writeCollectionTypeName: false);
                        }
                        else
                        {
                            IEnumerable<PayloadBuilder> payloads = pi.Value as IEnumerable<PayloadBuilder>;
                            if (payloads != null)
                            {
                                var bindingPayloads = payloads.Where(p => IsEntityBindingPayload(p)).ToList();
                                if (bindingPayloads.Count > 0)
                                {
                                    this.WriteKey(pi.Name + "@odata.bind");
                                    this.WriteStartArray();
                                    foreach (var url in bindingPayloads)
                                    {
                                        this.WriteValue(this.GetQuotedString(url.Uri));
                                    }

                                    this.WriteEndArray();
                                }

                                var insertPayloads = payloads.Where(p => IsEntityInsertPayload(p)).ToList();
                                if (insertPayloads.Count > 0)
                                {
                                    this.WriteKey(pi.Name);
                                    this.WriteStartArray();
                                    bool first = true;
                                    foreach (var insert in insertPayloads)
                                    {
                                        if (!first)
                                        {
                                            this.WriteValue(",");
                                        }

                                        this.GenerateJson(insert);
                                        first = false;
                                    }

                                    this.WriteEndArray();
                                }
                            }
                        }
                    }
                }
            }

            this.WriteEndObject();
        }
Exemplo n.º 16
0
            public void UpdatePutDeepResourceReferencePropertyToNull()
            {
                var payloadBuilder = new PayloadBuilder() { TypeName = typeof(CustomerWithBirthday).FullName }
                    .AddNavigationReferenceProperty("BestFriend", null);

                var atomUriAndXPath1 = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(1)", new string[] { "/atom:entry[atom:category/@term='#" + typeof(CustomerWithBirthday).FullName + "' and atom:id='http://host/Customers(1)']" }),
                    new KeyValuePair<string, string[]>("/Customers(1)?$expand=BestFriend",
                    new string[] {
                        "atom:entry[atom:category/@term='#" + typeof(CustomerWithBirthday).FullName + "' and atom:id='http://host/Customers(1)' and atom:link[@title='BestFriend' and adsm:inline[string()='']]]",
                    })};

                var jsonLiteUriAndXPath1 = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(1)?$expand=BestFriend",
                    new string[] { String.Format("/{0}[odata.type='#{1}' and ID=1 and BestFriend/@IsNull='true']",
                                    JsonValidator.ObjectString, 
                                    typeof(CustomerWithBirthday).FullName),
                                })};

                DoUpdatesForVariousProvidersWithOpenMissing("PATCH", "/Customers(1)", UnitTestsUtil.AtomFormat, payloadBuilder, atomUriAndXPath1, true/*verifyETag*/);
                DoUpdatesForVariousProvidersWithOpenMissing("PATCH", "/Customers(1)", UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteUriAndXPath1, true/*verifyETag*/);
            }
Exemplo n.º 17
0
            public void UpdateMergeReferencePropertyUpdate()
            {
                PayloadBuilder payloadBuilder = new PayloadBuilder()
                {
                    TypeName = typeof(Customer).FullName,
                    Uri = "/Customers(0)"
                }
                .AddProperty("Name", "Foo");

                var atomUriAndXPath1 = new KeyValuePair<string, string[]>(
                    "/Customers(1)/BestFriend",
                    new string[] { "/atom:entry[atom:category/@term='#" + typeof(Customer).FullName + "' and atom:id='http://host/Customers(0)' and atom:content/adsm:properties[ads:ID='0' and ads:Name='Foo']]" });

                var atomUriAndXPath2 = new KeyValuePair<string, string[]>(
                    "/Customers(0)",
                    new string[] { "/atom:entry[atom:category/@term='#" + typeof(Customer).FullName + "' and atom:id='http://host/Customers(0)' and atom:content/adsm:properties[ads:ID='0' and ads:Name='Foo']]" });

                var jsonLiteUriAndXPath1 = new KeyValuePair<string, string[]>(
                    "/Customers(1)/BestFriend",
                    new string[] { String.Format("/{0}[ID=0 and Name='Foo']", JsonValidator.ObjectString) });

                var jsonLiteUriAndXPath2 = new KeyValuePair<string, string[]>("/Customers(0)", jsonLiteUriAndXPath1.Value);

                DoUpdatesForVariousProviders("PATCH", "/Customers(1)/BestFriend", UnitTestsUtil.AtomFormat, payloadBuilder, new KeyValuePair<string, string[]>[] { atomUriAndXPath1, atomUriAndXPath2 }, true, true /*verifyUpdateResponse*/);
                DoUpdatesForVariousProviders("PATCH", "/Customers(1)/BestFriend", UnitTestsUtil.JsonLightMimeType, payloadBuilder, new KeyValuePair<string, string[]>[] { jsonLiteUriAndXPath1, jsonLiteUriAndXPath2 }, true, true /*verifyUpdateResponse*/);
            }
Exemplo n.º 18
0
 public PayloadBuilder AddComplexProperty(string name, PayloadBuilder propertyPayloadBuilder)
 {
     propertyPayloadBuilder.IsComplex = true;
     this.AddProperty(name, propertyPayloadBuilder, PayloadBuilderPropertyKind.Complex);
     return this;
 }
Exemplo n.º 19
0
 internal static void DoUpdatesForVariousProviders(string method, string uri, string responseFormat, PayloadBuilder payloadBuilder, string[] xPaths, bool verifyETag)
 {
     DoUpdatesForVariousProviders(method, uri, responseFormat, payloadBuilder, new KeyValuePair<string, string[]>[] { new KeyValuePair<string, string[]>(uri, xPaths) }, verifyETag);
 }
Exemplo n.º 20
0
        private List<PropertyPayloadBuilder> GeneratePropertiesPayload(XmlWriter writer, PayloadBuilder builder)
        {
            List<PropertyPayloadBuilder> navProperties = new List<PropertyPayloadBuilder>();
            foreach (var pi in builder.Properties)
            {
                if (pi.PropertyKind == PayloadBuilderPropertyKind.Primitive)
                {
                    writer.WriteStartElement(pi.Name, AtomUpdatePayloadBuilder.DataWebXmlNamespace);
                    if (pi.Value == null)
                    {
                        writer.WriteAttributeString("null", AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace, "true");
                    }
                    else
                    {
                        writer.WriteValue(TypeData.XmlValueFromObject(pi.Value));
                    }
                    writer.WriteEndElement();
                }
                else
                {
                    PayloadBuilder structuredPropertyPayload = pi.Value as PayloadBuilder;
                    if (structuredPropertyPayload != null)
                    {
                        if (structuredPropertyPayload.IsComplex)
                        {
                            writer.WriteStartElement(pi.Name, AtomUpdatePayloadBuilder.DataWebXmlNamespace);
                            if (!String.IsNullOrEmpty(structuredPropertyPayload.TypeName))
                            {
                                writer.WriteAttributeString("type", AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace, structuredPropertyPayload.TypeName);
                            }

                            PayloadBuilder p = (PayloadBuilder)pi.Value;
                            this.GeneratePayload(writer, structuredPropertyPayload);
                            writer.WriteEndElement();
                        }
                        else
                        {
                            navProperties.Add(pi);
                        }
                    }
                    else
                    {
                        navProperties.Add(pi);
                    }
                }
            }

            return navProperties;
        }
Exemplo n.º 21
0
 internal static void DoUpdatesForVariousProvidersWithOpenMissing(string method, string uri, string responseFormat, PayloadBuilder payloadBuilder, KeyValuePair<string, string[]>[] uriAndXPathsToVerify, bool verifyETag, bool verifyResponsePreference = true)
 {
     DoUpdatesForVariousProviders(
         method,
         uri,
         responseFormat,
         payloadBuilder,
         uriAndXPathsToVerify,
         verifyETag,
         includeOpenTypesProvider:false,
         verifyResponsePreference: verifyResponsePreference);
 }
Exemplo n.º 22
0
            public void UpdatePutTopLevelResourceDirectly()
            {
                PayloadBuilder payloadBuilder =
                    new PayloadBuilder()
                    {
                        TypeName = typeof(CustomerWithBirthday).FullName
                    }
                    .AddProperty("Name", "Foo");

                string[] atomXPath = new string[] {
                    "/atom:entry[atom:category/@term='#" + typeof(CustomerWithBirthday).FullName + "' and atom:id='http://host/Customers(1)' and atom:content/adsm:properties[ads:ID='1' and ads:Name='Foo']]" };

                string[] jsonLiteXPath = new string[] {
                    String.Format("/{0}[odata.type='#{1}' and ID=1 and Name='Foo']", 
                                    JsonValidator.ObjectString, 
                                    typeof(CustomerWithBirthday).FullName),
                             };

                DoUpdatesForVariousProviders("PATCH", "/Customers(1)", UnitTestsUtil.AtomFormat, payloadBuilder, atomXPath, true/*verifyETag*/);
                DoUpdatesForVariousProviders("PATCH", "/Customers(1)", UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteXPath, true/*verifyETag*/);
            }
Exemplo n.º 23
0
            public void UpdatePostSimple()
            {
                #region Payload

                var payloadGenerator = new PayloadBuilder() { TypeName = typeof(Customer).FullName }
                    .AddProperty("ID", 125)
                    .AddProperty("Name", "Foo")
                    .AddProperty("Address", new PayloadBuilder()
                        {
                            TypeName = typeof(Address).FullName,
                            IsComplex = true
                        }
                        .AddProperty("StreetAddress", "Street Number, Street Address")
                        .AddProperty("City", "Redmond")
                        .AddProperty("State", "WA")
                        .AddProperty("PostalCode", "98052"));

                #endregion Payload

               string[] jsonLiteXPaths = new string[] {
                    String.Format("/{0}[ID=125 and Name='Foo' and Address/StreetAddress='Street Number, Street Address' and Address/City='Redmond' and Address/State='WA' and Address/PostalCode='98052']",
                                  JsonValidator.ObjectString)};

                string[] atomXPaths = new string[] {
                    String.Format("/atom:entry[atom:category/@term='#{0}' and atom:id='http://host/Customers(125)' and atom:content/adsm:properties[ads:Name='Foo' and ads:ID=125 and ads:Address[ads:StreetAddress='Street Number, Street Address' and ads:City='Redmond' and ads:PostalCode='98052']]]",
                                  typeof(Customer).FullName)};

                DoInsertsForVariousProviders("/Customers", UnitTestsUtil.AtomFormat, payloadGenerator, atomXPaths);
                DoInsertsForVariousProviders("/Customers", UnitTestsUtil.JsonLightMimeType, payloadGenerator, jsonLiteXPaths);
            }
Exemplo n.º 24
0
            public void UpdatePutTopLevelResourceDirectlyWithoutMetadataInformation()
            {
                PayloadBuilder payloadBuilder =
                   new PayloadBuilder().AddProperty("DollarAmount", 1000.95);

                string[] atomXPath = new string[] {
                    "/atom:entry[atom:category/@term='#" + typeof(Order).FullName + "' and atom:id='http://host/Orders(1)' and atom:content/adsm:properties[ads:ID='1' and ads:DollarAmount='1000.95']]" };

                string[] jsonLiteXPath = new string[] {
                    String.Format("/{0}[ID=1 and DollarAmount=1000.95]", JsonValidator.ObjectString)
                             };

                DoUpdatesForVariousProviders("PATCH", "/Orders(1)", UnitTestsUtil.AtomFormat, payloadBuilder, atomXPath, false);
                DoUpdatesForVariousProviders("PATCH", "/Orders(1)", UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteXPath, false);
            }
Exemplo n.º 25
0
 internal static void CustomProviderRequest(
     Type providerType,
     string uri,
     string responseFormat,
     PayloadBuilder payloadBuilder,
     KeyValuePair<string, string[]>[] uriAndXPathsToVerify,
     string httpMethodName,
     bool verifyETagReturned,
     IList<KeyValuePair<string, string>> requestHeaders = null,
     IList<KeyValuePair<string, string>> responseHeaders = null,
     UnitTestsUtil.SendRequestModifier sendRequestModifier = UnitTestsUtil.SendRequestModifier.None)
 {
     using (UnitTestsUtil.AppendTypesForOpenProperties(providerType, payloadBuilder, responseFormat))
     {
         UnitTestsUtil.CustomProviderRequest(providerType, uri, responseFormat, PayloadGenerator.Generate(payloadBuilder, responseFormat), uriAndXPathsToVerify, httpMethodName, verifyETagReturned, requestHeaders, responseHeaders, sendRequestModifier);
     }
 }
Exemplo n.º 26
0
            public void UpdatePutDeepReferencePropertyUpdate()
            {
                PayloadBuilder payloadBuilder =
                    new PayloadBuilder()
                    {
                        TypeName = typeof(CustomerWithBirthday).FullName
                    }
                   .AddProperty("BestFriend", new PayloadBuilder()
                        {
                            Uri = "/Customers(0)"
                        }.AddProperty("Name", "Foo"));

                VerifyInvalidRequestForVariousProviders1(payloadBuilder, "/Customers(1)", UnitTestsUtil.AtomFormat, "PUT", 400);
                VerifyInvalidRequestForVariousProviders1(payloadBuilder, "/Customers(1)", UnitTestsUtil.JsonLightMimeType, "PUT", 400);
            }
Exemplo n.º 27
0
            public void UpdatePostDeepInsert()
            {
                string customerFullName = typeof(Customer).FullName;
                string orderFullName = typeof(Order).FullName;

                #region Payload
                PayloadBuilder payloadGenerator = new PayloadBuilder() { TypeName = typeof(Customer).FullName }
                    .AddProperty("Name", "Foo")
                    .AddProperty("ID", 125)
                    .AddProperty("BestFriend", new PayloadBuilder()
                        {
                            TypeName = typeof(Customer).FullName,
                            Uri = "/Customers(1)",
                        }
                        .AddProperty("Name", "FooBestFriend")
                        .AddProperty("ID", 126)
                        .AddProperty("Orders", new PayloadBuilder[] {
                            new PayloadBuilder()
                            {
                                TypeName = typeof(Order).FullName,
                                Uri = "/Orders(101)",
                            }
                            .AddProperty("ID", 151)
                            .AddProperty("DollarAmount", 1500.00),

                            new PayloadBuilder()
                            {
                                TypeName = typeof(Order).FullName,
                            }
                            .AddProperty("ID", 152)
                            .AddProperty("DollarAmount", 500.00),

                            new PayloadBuilder()
                            {
                                TypeName = typeof(Order).FullName
                            }
                            .AddProperty("ID", 153)
                            .AddProperty("DollarAmount", 00.00),

                            new PayloadBuilder()
                            {
                                TypeName = typeof(Order).FullName,
                                Uri = "/Orders(101)",
                            }
                        }));

                #endregion // Payload

                #region Atom XPath
                var atomXPaths1 = new KeyValuePair<string, string[]>(
                    "/Customers",
                    new string[] { "/atom:entry[atom:category/@term='#" + customerFullName + "' and atom:id='http://host/Customers(125)' and atom:content/adsm:properties[ads:Name='Foo' and ads:ID='125']]" });

                var atomXPaths2 = new KeyValuePair<string, string[]>(
                    "/Customers(125)/BestFriend",
                    new string[] { "/atom:entry[atom:category/@term='#" + customerFullName + "' and atom:id='http://host/Customers(126)' and atom:content/adsm:properties[ads:Name='FooBestFriend' and ads:ID='126']]" });

                var atomXPaths3 = new KeyValuePair<string, string[]>(
                    "/Customers",
                    new string[] { "/atom:feed/atom:entry[atom:category/@term='#" + customerFullName + "' and atom:id='http://host/Customers(125)' and atom:content/adsm:properties[ads:Name='Foo' and ads:ID='125']]",
                                   "/atom:feed/atom:entry[atom:category/@term='#" + customerFullName + "' and atom:id='http://host/Customers(126)' and atom:content/adsm:properties[ads:Name='FooBestFriend' and ads:ID='126']]"});

                var atomXPaths4 = new KeyValuePair<string, string[]>(
                    "/Customers(125)/BestFriend/Orders",
                    new string[] {
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(151)' and atom:content/adsm:properties[ads:DollarAmount='1500' and ads:ID='151']]",
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(152)' and atom:content/adsm:properties[ads:DollarAmount='500' and ads:ID='152']]",
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(153)' and atom:content/adsm:properties[ads:DollarAmount='0' and ads:ID='153']]",
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(101)' and atom:content/adsm:properties[ads:ID='101']]"
                    });

                var atomXPaths5 = new KeyValuePair<string, string[]>(
                    "/Orders",
                    new string[] {
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(151)' and atom:content/adsm:properties[ads:DollarAmount='1500' and ads:ID='151']]",
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(152)' and atom:content/adsm:properties[ads:DollarAmount='500' and ads:ID='152']]",
                        "/atom:feed/atom:entry[atom:category/@term='#" + orderFullName + "' and atom:id='http://host/Orders(153)' and atom:content/adsm:properties[ads:DollarAmount='0' and ads:ID='153']]"
                    });

                #endregion

                #region JsonLite XPath
                var jsonLiteXPaths1 = new KeyValuePair<string, string[]>(
                    "/Customers",
                    new string[] { String.Format("/{0}[ID=125 and Name='Foo']", JsonValidator.ObjectString) });

                var jsonLiteXPaths2 = new KeyValuePair<string, string[]>(
                    "/Customers(125)/BestFriend",
                    new string[] { String.Format("{0}[ID=126 and Name='FooBestFriend']", JsonValidator.ObjectString) });

                var jsonLiteXPaths3 = new KeyValuePair<string, string[]>(
                    "/Customers",
                    new string[] { String.Format("//{0}/{1}[ID=125 and Name='Foo']", JsonValidator.ArrayString, JsonValidator.ObjectString) });

                var jsonLiteXPaths4 = new KeyValuePair<string, string[]>(
                     "/Customers(125)/BestFriend/Orders",
                     new string[] {
                               String.Format("//{0}/{1}[ID=151 and DollarAmount=1500]", JsonValidator.ArrayString, JsonValidator.ObjectString),
                               String.Format("//{0}/{1}[ID=152 and DollarAmount=500]", JsonValidator.ArrayString, JsonValidator.ObjectString),
                               String.Format("//{0}/{1}[ID=153 and DollarAmount=0]", JsonValidator.ArrayString, JsonValidator.ObjectString),
                               String.Format("//{0}/{1}[ID=101]", JsonValidator.ArrayString, JsonValidator.ObjectString) });

                var jsonLiteXPaths5 = new KeyValuePair<string, string[]>(
                    "/Orders",
                    new string[] {
                               String.Format("//{0}/{1}[ID=151 and DollarAmount=1500]", JsonValidator.ArrayString, JsonValidator.ObjectString),
                               String.Format("//{0}/{1}[ID=152 and DollarAmount=500]", JsonValidator.ArrayString, JsonValidator.ObjectString),
                               String.Format("//{0}/{1}[ID=153 and DollarAmount=0]", JsonValidator.ArrayString, JsonValidator.ObjectString)
                             });
                #endregion

                UnitTestsUtil.DoInsertsForVariousProviders("/Customers", UnitTestsUtil.AtomFormat, payloadGenerator, new KeyValuePair<string, string[]>[] { atomXPaths1, atomXPaths2, atomXPaths3, atomXPaths4, atomXPaths5 }, true/*verifyETag*/);
                UnitTestsUtil.DoInsertsForVariousProviders("/Customers", UnitTestsUtil.JsonLightMimeType, payloadGenerator, new KeyValuePair<string, string[]>[] { jsonLiteXPaths1, jsonLiteXPaths2, jsonLiteXPaths3, jsonLiteXPaths4, jsonLiteXPaths5 }, true/*verifyETag*/);
            }
Exemplo n.º 28
0
            public void UpdatePut_ChangeReferenceRelationshipInPayload()
            {
                string customerFullName = typeof(Customer).FullName;

                PayloadBuilder payloadBuilder =
                    new PayloadBuilder()
                    {
                        TypeName = typeof(Customer).FullName
                    }
                   .AddProperty("BestFriend", new PayloadBuilder()
                   {
                       TypeName = typeof(Customer).FullName, Uri = "/Customers(1)/BestFriend"
                   });

                 var atomUriAndXPath1 = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(2)", new string[] { "/atom:entry[atom:category/@term='#" + typeof(Customer).FullName + "' and atom:id='http://host/Customers(2)']" }),
                    new KeyValuePair<string, string[]>("/Customers(2)/BestFriend",
                     new string[] { "/atom:entry[atom:category/@term='#" + customerFullName + "' and atom:id='http://host/Customers(0)' and atom:content/adsm:properties[ads:ID='0']]" })};

                 var jsonLiteUriAndXPath1 = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(2)/BestFriend",
                        new string[] { String.Format("/{0}[ID=0]", 
                                    JsonValidator.ObjectString) })};

                 DoUpdatesForVariousProviders("PATCH", "/Customers(2)", UnitTestsUtil.AtomFormat, payloadBuilder, atomUriAndXPath1, true, true /*verifyUpdateResponse*/);
                 DoUpdatesForVariousProviders("PATCH", "/Customers(2)", UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteUriAndXPath1, true, true /*verifyUpdateResponse*/);
            }
Exemplo n.º 29
0
 internal static void DoInsertsForVariousProviders(string uri, string responseFormat, PayloadBuilder payloadGenerator, string[] xPaths)
 {
     UnitTestsUtil.DoInsertsForVariousProviders(uri, responseFormat, payloadGenerator, new KeyValuePair<string, string[]>[] { new KeyValuePair<string, string[]>(uri, xPaths) }, true /*verifyETag*/);
 }
Exemplo n.º 30
0
            public void UpdatePut_ChangeReferenceSetRelationshipInPayload()
            {
                PayloadBuilder payloadBuilder = new PayloadBuilder() { TypeName = typeof(Customer).FullName }
                    .AddProperty("Orders", new PayloadBuilder[] {
                        new PayloadBuilder() { Uri = "/Orders(0)" },
                        new PayloadBuilder() { Uri = "/Orders(100)" }});

                var atomUriAndXPath1 = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(2)", new string[] { "/atom:entry[atom:category/@term='#" + typeof(Customer).FullName + "' and atom:id='http://host/Customers(2)']" }),
                    new KeyValuePair<string, string[]>(
                        "/Customers(2)/Orders",
                        new string[] { "/atom:feed/atom:entry[atom:category/@term='#" + typeof(Order).FullName + "' and atom:id='http://host/Orders(0)']",
                                       "/atom:feed/atom:entry[atom:category/@term='#" + typeof(Order).FullName + "' and atom:id='http://host/Orders(100)']"}) };

                var jsonLiteUriAndXPath1 = new KeyValuePair<string, string[]>[] {
                    new KeyValuePair<string, string[]>("/Customers(2)/Orders",
                        new string[] {
                            String.Format(
                                "//{0}/{1}[ID=0]", 
                                JsonValidator.ArrayString,
                                JsonValidator.ObjectString),
                            String.Format(
                                "//{0}/{1}[ID=100]", 
                                JsonValidator.ArrayString,
                                JsonValidator.ObjectString)
                        }) };

                DoUpdatesForVariousProviders("PATCH", "/Customers(2)", UnitTestsUtil.AtomFormat, payloadBuilder, atomUriAndXPath1, true, true /*verifyUpdateResponse*/);
                DoUpdatesForVariousProviders("PATCH", "/Customers(2)", UnitTestsUtil.JsonLightMimeType, payloadBuilder, jsonLiteUriAndXPath1, true, true /*verifyUpdateResponse*/);
            }