コード例 #1
0
        public void CanBuildCreateRequest()
        {
            //Arrange
            var builder = new CreateRequestBuilder();

            //Act
            builder
            .NewContextName("/foo/bar")
            .ObjectTypeToCreate("baz")
            .ReturnNoAttributes()
            .FailOnError()
            .UpdateIfExists()
            .AttributesToSet(
                StructureAttribute.New(215, new StructureValue(10, "169010"))
                )
            .ConfigureLookupControls()
            .ReturnAttributes(AttributeToReturn.WithName("Artikelnummer"))
            .ReturnLanguages(LanguageToReturn.WithLanguageId(10))
            .ConfigureReferenceHandling(
                ReferenceOptions.ReturnValuesOnly()
                );

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

            //Assert
            Assert.That(builder.Build(), Is.Not.Null);
            Assert.DoesNotThrow(() => request.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
コード例 #2
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"));
        }
コード例 #3
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"));
        }
コード例 #4
0
        public void CanSetAttributesToBeCreatedWithParamsOverload()
        {
            //Act
            _builder.AttributesToSet(StructureAttribute.New(10, new StructureValue(10, "foo")));

            //Assert
            Assert.That(_builder.Attributes.Count(), Is.EqualTo(1));
        }
コード例 #5
0
        public void Can_Create_New_StructureAttribute_Using_Factory_Method_Providing_DefinitionId()
        {
            //Act
            var sa = StructureAttribute.New(10, new StructureValue(10, "bar"));

            //Assert
            Assert.That(sa.DefinitionId, Is.EqualTo(10));
            Assert.That(sa.Values.Count(), Is.EqualTo(1));
            Assert.That(sa.Values[0].Value, Is.EqualTo("bar"));
        }
コード例 #6
0
        public void CanSetAttributesToBeCreatedWithListOverload()
        {
            //Arrange
            var builder    = new CreateRequestBuilder();
            var attributes = new List <StructureAttribute> {
                StructureAttribute.New(10, new StructureValue(10, "foo"))
            };

            //Act
            builder.AttributesToSet(attributes);

            //Assert
            Assert.That(builder.Attributes.Count(), Is.EqualTo(1));
        }
コード例 #7
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"));
        }
コード例 #8
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.");
        }
コード例 #9
0
        public void CanSetAttributesToBeCreatedWithListFactoryOverload()
        {
            //Arrange
            var builder = new CreateRequestBuilder();

            //Act
            builder.AttributesToSet(
                () => new List <IAdsmlAttribute> {
                StructureAttribute.New(10, new StructureValue(10, "foo")),
                SimpleAttribute.New(AttributeTypes.Text, "objectName", "foo")
            }
                );

            //Assert
            Assert.That(builder.Attributes.Count(), Is.EqualTo(2));
        }
コード例 #10
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));
        }