public void Can_Specify_AttributeNamelist_And_AttributesToReturn()
        {
            //Arrange
            string expected =
                new XElement("LookupControls",
                             new XElement("AttributesToReturn",
                                          new XAttribute("namelist", "members"),
                                          new XElement("Attribute",
                                                       new XAttribute("name", "35")),
                                          new XElement("Attribute",
                                                       new XAttribute("name", "36")))).ToString();

            var builder = new LookupControlBuilder();

            //Act
            builder
            .AttributeNamelist("members")
            .ReturnAttributes(
                AttributeToReturn.WithName("35"),
                AttributeToReturn.WithName("36")
                );

            var actual = builder.Build().ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Can_Configure_ReferenceControls()
        {
            //Arrange
            var expected =
                new XElement("LookupControls",
                             new XAttribute("returnRelationsAsAttributes", "true"),
                             new XElement("AttributesToReturn",
                                          new XElement("Attribute", new XAttribute("name", "Artikelnummer"))),
                             new XElement("LanguagesToReturn",
                                          new XElement("Language", new XAttribute("id", "10"))),
                             new XElement("ReferenceControls", new XAttribute("valueOnly", "true")));

            var builder = new LookupControlBuilder();

            //Act
            builder.AddRequestFilters(Filter.ReturnRelationsAsAttributes())
            .ReturnAttributes(AttributeToReturn.WithName("Artikelnummer"))
            .ReturnLanguages(LanguageToReturn.WithLanguageId(10))
            .ConfigureReferenceHandling(ReferenceOptions.ReturnValuesOnly());

            var request = builder.Build().ToAdsml();

            //Assert
            Assert.That(request.ToString(), Is.EqualTo(expected.ToString()));
        }
        public void CanGenerateApiXmlWithLookupControl()
        {
            //Arrange
            var expected =
                new XElement("CreateRequest",
                             new XAttribute("name", "fooPath"),
                             new XAttribute("type", "fooObjectTypeName"),
                             new XElement("LookupControls",
                                          new XElement("AttributesToReturn",
                                                       new XElement("Attribute",
                                                                    new XAttribute("name", "fooAttributeName")))),
                             new XElement("AttributesToSet",
                                          new XElement("StructureAttribute",
                                                       new XAttribute("id", "215"),
                                                       new XAttribute("name", "fooAttributeName"),
                                                       new XElement("StructureValue",
                                                                    new XAttribute("langId", "10"),
                                                                    new XAttribute("scope", "global"),
                                                                    new XCData("fooValue")))));

            var value = new StructureValue {
                LanguageId = 10, Value = "fooValue"
            };
            var attribute = new StructureAttribute {
                DefinitionId = 215,
                Name         = "fooAttributeName",
                Values       = new List <StructureValue> {
                    value
                }
            };

            var lcb = new LookupControlBuilder();

            lcb.ReturnAttributes(AttributeToReturn.WithName("fooAttributeName"));
            var lc = lcb.Build();

            var create = new CreateRequest("fooObjectTypeName", "fooPath", null, attribute)
            {
                LookupControl = lc
            };

            //Act
            var actual  = create.ToAdsml();
            var request = new BatchRequest(create);

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.ToString(), Is.EqualTo(expected.ToString()));
            Assert.DoesNotThrow(() => request.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
        public void Can_Add_Request_Filters()
        {
            //Arrange
            var expected = new XElement("LookupControls", new XAttribute("returnRelationsAsAttributes", "true"));
            var builder  = new LookupControlBuilder();

            //Act
            builder.AddRequestFilters(Filter.ReturnRelationsAsAttributes());

            var request = builder.Build().ToAdsml();

            //Assert
            Assert.That(request.ToString(), Is.EqualTo(expected.ToString()));
        }
Ejemplo n.º 5
0
        public void Can_Generate_Api_Xml_With_LookupControls()
        {
            //Arrange
            string expected =
                new XElement("ModifyRequest",
                             new XAttribute("name", "/foo/bar"),
                             new XElement("ModificationItem",
                                          new XAttribute("operation", "addValue"),
                                          new XElement("AttributeDetails",
                                                       new XElement("StructureAttribute",
                                                                    new XAttribute("id", "31"),
                                                                    new XElement("StructureValue",
                                                                                 new XAttribute("langId", "10"),
                                                                                 new XAttribute("scope", "global"),
                                                                                 new XCData("foo"))))),
                             new XElement("LookupControls",
                                          new XElement("AttributesToReturn",
                                                       new XElement("Attribute",
                                                                    new XAttribute("name", "Artikelnummer"))),
                                          new XElement("LanguagesToReturn",
                                                       new XElement("Language",
                                                                    new XAttribute("id", "10"))))).ToString();

            var lookupBuilder = new LookupControlBuilder();

            lookupBuilder.ReturnAttributes(AttributeToReturn.WithName("Artikelnummer"))
            .ReturnLanguages(LanguageToReturn.WithLanguageId(10));

            //Act
            var modReq = new ModifyRequest("/foo/bar", new List <ModificationItem> {
                ModificationItem.New(
                    Modifications.AddValue,
                    StructureAttribute.New(31, new StructureValue(10, "foo"))
                    )
            })
            {
                LookupControl = lookupBuilder.Build()
            };

            var actual  = modReq.ToAdsml();
            var request = new BatchRequest(modReq);

            Console.WriteLine(actual.ToString());

            //Assert
            Assert.That(actual.ToString(), Is.EqualTo(expected));
            Assert.DoesNotThrow(() => request.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
        public void Can_Specify_Attribute_IdList_To_Return()
        {
            //Arrange
            string expected =
                new XElement("LookupControls",
                             new XElement("AttributesToReturn",
                                          new XAttribute("idlist", "1, 2, 3, 4"))).ToString();

            var builder = new LookupControlBuilder();

            //Act
            builder.ReturnAttributes(1, 2, 3, 4);
            var actual = builder.Build().ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Can_Restrict_Returned_Attributes()
        {
            //Arrange
            var expected =
                new XElement("LookupControls",
                             new XAttribute("returnRelationsAsAttributes", "true"),
                             new XElement("AttributesToReturn",
                                          new XElement("Attribute", new XAttribute("name", "Artikelnummer"))));

            var builder = new LookupControlBuilder();

            //Act
            builder.AddRequestFilters(Filter.ReturnRelationsAsAttributes())
            .ReturnAttributes(AttributeToReturn.WithName("Artikelnummer"));

            var request = builder.Build().ToAdsml();

            //Assert
            Assert.That(request.ToString(), Is.EqualTo(expected.ToString()));
        }
        public void Can_Specify_Attribute_Types_To_Return()
        {
            //Arrange
            string expected =
                new XElement("LookupControls",
                             new XElement("AttributeTypesToReturn",
                                          new XElement("AttributeType",
                                                       new XAttribute("name", "structure-text")))).ToString();

            var builder = new LookupControlBuilder();

            //Act
            builder.ReturnAttributes(AttributeTypeToReturn.OfType(AttributeDataType.StructureText));
            var actual = builder.Build().ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Ejemplo n.º 9
0
        public void Can_Generate_Api_Xml_With_CopyControl_Containing_LookupControl()
        {
            //Arrange
            string expected =
                new XElement("LinkRequest",
                             new XAttribute("name", "foo"),
                             new XAttribute("targetLocation", "bar"),
                             new XElement("CopyControls",
                                          new XAttribute("copyLocalAttributes", "true"),
                                          new XElement("LookupControls",
                                                       new XElement("AttributesToReturn",
                                                                    new XElement("Attribute",
                                                                                 new XAttribute("name", "Artikelnummer")))))).ToString();

            var lookupBuilder = new LookupControlBuilder();

            lookupBuilder.ReturnAttributes(AttributeToReturn.WithName("Artikelnummer"));

            var request = new LinkRequest("foo", "bar")
            {
                CopyControl =
                    new CopyControl(new List <ICopyControlFilter> {
                    Filter.CopyLocalAttributesFromSource()
                },
                                    lookupBuilder.Build())
            };

            //Act
            var actual       = request.ToAdsml();
            var batchRequest = new BatchRequest(request);

            Console.WriteLine(actual.ToString());

            //Assert
            Assert.That(actual.ToString(), Is.EqualTo(expected));
            Assert.DoesNotThrow(() => batchRequest.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
Ejemplo n.º 10
0
        public void CanGenerateApiXmlWithLookupControl()
        {
            //Arrange
            string expexcted =
                new XElement("LookupRequest",
                             new XAttribute("name", "/Schema/Attribute Sets/Översättningsattribut"),
                             new XElement("LookupControls",
                                          new XElement("AttributesToReturn",
                                                       new XAttribute("namelist", "members")),
                                          new XElement("LanguagesToReturn",
                                                       new XElement("Language",
                                                                    new XAttribute("id", "10"))))).ToString();

            var lookupBuilder = new LookupControlBuilder();

            lookupBuilder.AttributeNamelist("members").ReturnLanguages(LanguageToReturn.WithLanguageId(10));

            //Act
            var req          = new LookupRequest("/Schema/Attribute Sets/Översättningsattribut", lookupBuilder.Build());
            var actual       = req.ToAdsml();
            var batchRequest = new BatchRequest(req);

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual.ToString(), Is.EqualTo(expexcted));
            Assert.DoesNotThrow(() => batchRequest.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }