Esempio n. 1
0
        public void Can_Generate_Api_Xml()
        {
            //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")))))).ToString();

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

            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"));
        }
Esempio n. 2
0
        public void Can_Combine_All_Operations()
        {
            //Arrange
            var builder = new ModifyRequestBuilder();

            //Act
            builder.Context("/foo/bar")
            .ReturnNoAttributes()
            .FailOnError()
            .AddModification(Modifications.RemoveAttribute, SimpleAttribute.New(AttributeTypes.Integer, "objectId"))
            .AddModifications(() => new List <ModificationItem> {
                ModificationItem.New(
                    Modifications.AdvanceState, StructureAttribute.New(390, new StructureValue(10))
                    ),
                ModificationItem.New(
                    Modifications.RegressState, StructureAttribute.New(24, new StructureValue(10))
                    )
            })
            .ConfigureLookupControls()
            .ReturnAttributes(390, 24)
            .ReturnLanguages(10);

            var request = new BatchRequest(builder.Build());

            Console.WriteLine(builder.Build().ToAdsml().ToString());

            //Assert
            Assert.DoesNotThrow(() => builder.Build());
            Assert.DoesNotThrow(() => request.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
        public IAddModificationsConfigLookupControls AddModification <TAttribute>(Modifications modificationType, TAttribute attribute)
            where TAttribute : class, IAdsmlAttribute
        {
            var modification = ModificationItem.New(modificationType, attribute);

            this.Modifications.Add(modification);

            return(this);
        }
Esempio n. 4
0
        public void Can_Instantiate_New_ModificationItem_With_FactoryMethod()
        {
            //Act
            var modItem = ModificationItem.New(Modifications.RemoveValue,
                                               SimpleAttribute.New(AttributeTypes.Text, "foo"));

            //Assert
            Assert.That(modItem, Is.Not.Null);
        }
Esempio 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"));
        }
Esempio n. 6
0
        public void Validate_Throws_ApiSerializationValidationException_When_Context_Is_Empty()
        {
            //Arrange
            var modReq = new ModifyRequest(string.Empty, new List <ModificationItem> {
                ModificationItem.New(
                    Modifications.AddValue,
                    StructureAttribute.New(31, new StructureValue(10, "foo"))
                    )
            });

            //Act
            modReq.ToAdsml();

            //Assert
            Assert.Fail("Expected exception not thrown.");
        }
Esempio n. 7
0
        public void Can_Add_ModificationItems_With_ListFactory()
        {
            //Arrange
            var builder = new ModifyRequestBuilder();

            //Act
            builder.AddModifications(() => new List <ModificationItem> {
                ModificationItem.New(
                    Modifications.ReplaceAttribute,
                    SimpleAttribute.New(AttributeTypes.Integer, "foo", "bar")
                    ),
                ModificationItem.New(
                    Modifications.AddAttribute,
                    RelationAttribute.New("foo", "bar")
                    )
            });

            //Assert
            Assert.That(builder.Modifications.Count(), Is.EqualTo(2));
        }
Esempio n. 8
0
        public void Can_Generate_Api_Xml()
        {
            //Arrange
            var expected = new XElement("ModificationItem",
                                        new XAttribute("operation", "replaceValue"),
                                        new XElement("AttributeDetails",
                                                     new XElement("StructureAttribute",
                                                                  new XAttribute("id", "421"),
                                                                  new XAttribute("name", "yy Artikelstatus MMS001"),
                                                                  new XElement("StructureValue",
                                                                               new XAttribute("langId", "10"),
                                                                               new XAttribute("scope", "global"),
                                                                               new XCData("60"))))).ToString();


            //Act
            var actual = ModificationItem.New(Modifications.ReplaceValue,
                                              StructureAttribute.New("yy Artikelstatus MMS001", 421, new StructureValue(10, "60"))).ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }