Ejemplo n.º 1
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 void Can_Instantiate_New_SimpleAttribute_With_FactoryMethod()
        {
            //Act
            var attribute = SimpleAttribute.New(AttributeTypes.Integer, "objectId", "1777");

            //Assert
            Assert.That(attribute, Is.Not.Null);
        }
        public void Can_Instantiate_New_SimpleAttribute()
        {
            //Act
            var attribute = new SimpleAttribute(AttributeTypes.Text);

            //Assert
            Assert.That(attribute, Is.Not.Null);
        }
Ejemplo 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);
        }
        public void Instantiation_Sets_Correct_Values_On_BaseType_Props()
        {
            //Act
            var attribute = new SimpleAttribute(AttributeTypes.Date);

            //Assert
            Assert.That(attribute.AttributeType, Is.EqualTo(AttributeTypes.Date));
            Assert.That(attribute.ElementName, Is.EqualTo("SimpleAttribute"));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Base method for retrieving Data extension element values.
        /// </summary>
        /// <param name="extension">The name of the Data extension element to look for</param>
        /// <returns>value as string, or NULL if the extension was not found</returns>
        public string getAccountExtensionValue(string extension)
        {
            SimpleAttribute e = getDataExtension(extension);

            if (e != null)
            {
                return((string)e.Value);
            }
            return(null);
        }
        public string getWebmasterToolsAttributeValue(string extension)
        {
            SimpleAttribute e = getWebmasterToolsAttribute(extension);

            if (e != null)
            {
                return((string)e.Value);
            }
            return(null);
        }
Ejemplo n.º 8
0
        public string getWebmasterToolsAttributeValue(string extension)
        {
            SimpleAttribute attribute = this.getWebmasterToolsAttribute(extension);

            if (attribute != null)
            {
                return(attribute.Value);
            }
            return(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Base method for retrieving Calendar extension element values.
        /// </summary>
        /// <param name="extension">The name of the Calendar extension element to look for</param>
        /// <returns>value as string, or NULL if the extension was not found</returns>
        public string getCalendarExtensionValue(string extension)
        {
            SimpleAttribute e = getCalendarExtension(extension);

            if (e != null)
            {
                return((string)e.Value);
            }
            return(null);
        }
Ejemplo n.º 10
0
        public void Can_Add_ModificationItem()
        {
            //Arrange
            var builder = new ModifyRequestBuilder();

            //Act
            builder.AddModification(Modifications.RemoveValue, SimpleAttribute.New(AttributeTypes.Integer, "objectId"));

            //Assert
            Assert.That(builder.Modifications.Count(), Is.EqualTo(1));
        }
        public void GetAttributes_Inherit_Method()
        {
            // Arrange
            var provider = typeof(ChildPoco).GetMethod(nameof(ChildPoco.MyMethod));
            var expected = new SimpleAttribute[] { new ChildAttribute() };

            // Act
            var actual = CustomAttributeProviderExtensions.GetAttributes <SimpleAttribute>(provider);

            // Assert
            actual.ShouldHaveSameValueAs(expected);
        }
Ejemplo n.º 12
0
        public void GetEnumValueAttribute()
        {
            // Arrange
            var expected = new SimpleAttribute {
                MyInt = 1, MyString = "a"
            };

            // Act
            var actual = EnumAttributeHelper.GetEnumValueAttribute <SimpleAttribute>(TestEnum.Value0);

            // Assert
            actual.ShouldHaveSameValueAs(expected);
        }
        public void Validate_Throws_ASVE_If_Name_Is_Not_Set()
        {
            //Arrange
            var attribute = new SimpleAttribute(AttributeTypes.Binary)
            {
                Values = new List <string> {
                    "1777"
                }
            };

            //Act
            attribute.ToAdsml();
        }
Ejemplo n.º 14
0
        public SimpleElement setWebmasterToolsAttribute(string extension, string newValue)
        {
            if (extension == null)
            {
                throw new ArgumentNullException("extension");
            }
            SimpleAttribute attribute = this.getWebmasterToolsAttribute(extension);

            if (attribute == null)
            {
                attribute = base.CreateExtension(extension, "http://schemas.google.com/webmasters/tools/2007") as SimpleAttribute;
                base.ExtensionElements.Add(attribute);
            }
            attribute.Value = newValue;
            return(attribute);
        }
        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));
        }
Ejemplo n.º 16
0
        public void Can_Build_ModifyRequest()
        {
            //Arrange
            var builder = new ModifyRequestBuilder();

            //Act
            builder.Context("/foo/bar")
            .AddModification(Modifications.RemoveAttribute, SimpleAttribute.New(AttributeTypes.Integer, "objectId"));

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

            //Assert
            Assert.That(request, Is.Not.Null);
            Assert.That(request, Is.InstanceOf <ModifyRequest>());

            Assert.DoesNotThrow(() => batchRequest.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
        public void Can_Generate_Api_Xml_With_Multiple_Values()
        {
            //Arrange
            var expected = new XElement("SimpleAttribute",
                                        new XAttribute("name", "objectTypeId"),
                                        new XAttribute("type", "integer"),
                                        new XElement("Value", new XCData("12")),
                                        new XElement("Value", new XCData("24"))).ToString();

            var attribute = SimpleAttribute.New(AttributeTypes.Integer, "objectTypeId", new[] { "12", "24" });

            //Act
            var actual = attribute.ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
        public SimpleElement setWebmasterToolsAttribute(string extension, string newValue)
        {
            if (extension == null)
            {
                throw new System.ArgumentNullException("extension");
            }

            SimpleAttribute ele = getWebmasterToolsAttribute(extension);

            if (ele == null)
            {
                ele = CreateExtension(extension, WebmasterToolsNameTable.gWebmasterToolsNamspace) as SimpleAttribute;
                this.ExtensionElements.Add(ele);
            }

            ele.Value = newValue;

            return(ele);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Base method for setting Calendar extension element values.
        /// </summary>
        /// <param name="extension">the name of the extension to look for</param>
        /// <param name="newValue">the new value for this extension element</param>
        /// <returns>SimpleAttribute, either a brand new one, or the one
        /// returned by the service</returns>
        public SimpleElement setCalendarExtension(string extension, string newValue)
        {
            if (extension == null)
            {
                throw new System.ArgumentNullException("extension");
            }

            SimpleAttribute ele = getCalendarExtension(extension);

            if (ele == null)
            {
                ele = CreateExtension(extension, GDataParserNameTable.NSGCal) as SimpleAttribute;
                this.ExtensionElements.Add(ele);
            }

            ele.Value = newValue;

            return(ele);
        }
Ejemplo n.º 20
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));
        }
        public void Can_Generate_Api_Xml_Without_Value()
        {
            //Arrange
            var expected = new XElement("SimpleAttribute",
                                        new XAttribute("name", "objectTypeId"),
                                        new XAttribute("type", "integer")).ToString();

            var attribute = new SimpleAttribute(AttributeTypes.Integer)
            {
                Name = "objectTypeId"
            };

            //Act
            var actual = attribute.ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Ejemplo n.º 22
0
        public static IAttributeChain Create(string attributeString)
        {
            if (string.IsNullOrEmpty(attributeString))
            {
                throw new QuerySystemException(ErrorCodes.Query.ATTRIBUTE_NULL_OR_EMPTY);
            }
            var             attributor        = new SimpleAttribute();
            var             queue             = new Queue <string>(attributeString.Split('.'));
            SimpleAttribute currentAttributor = attributor;

            while (queue.Count > 0)
            {
                string attribute = queue.Dequeue();
                var    split     = attribute.Split('[');
                if (split.Length > 1)
                {
                    currentAttributor.Name    = split[0];
                    currentAttributor.Indices = new int[split.Length];
                    for (int i = 1; i < split.Length; i++)
                    {
                        var isolate = split[i].Split(']');
                        int index;
                        if (isolate.Length < 2 || !int.TryParse(isolate[0], out index))
                        {
                            throw new QuerySystemException(ErrorCodes.Query.INVALID_ATTRIBUTE);
                        }
                        currentAttributor.Indices[i] = index;
                    }
                }
                else
                {
                    currentAttributor.Name = attribute;
                }
                if (queue.Count > 0)
                {
                    currentAttributor.Child = new SimpleAttribute();
                    currentAttributor       = currentAttributor.Child as SimpleAttribute;
                }
            }
            return(attributor);
        }
Ejemplo n.º 23
0
        public void Can_Build_ModifyRequest_With_Request_Filters()
        {
            //Arrange
            var builder = new ModifyRequestBuilder();

            //Act
            builder.Context("/foo/bar")
            .ReturnNoAttributes()
            .FailOnError()
            .AddModification(Modifications.RemoveAttribute, SimpleAttribute.New(AttributeTypes.Integer, "objectId"));

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

            //Assert
            Assert.That(request.RequestFilters.Count(), Is.EqualTo(2));
            Assert.That(request.RequestFilters.ElementAt(0), Is.InstanceOf <ReturnNoAttributesFilter>());
            Assert.That(request.RequestFilters.ElementAt(1), Is.InstanceOf <FailOnErrorFilter>());

            Assert.DoesNotThrow(() => batchRequest.ToAdsml().ValidateAdsmlDocument("adsml.xsd"));
        }
Ejemplo n.º 24
0
        public void Can_Deserialize_SimpleAttribute()
        {
            //Arrange
            var xml =
                new XElement("SimpleAttribute",
                             new XAttribute("name", "name"),
                             new XAttribute("type", "text"),
                             new XElement("Value", "foo"));

            var expected = SimpleAttribute.New(AttributeTypes.Text, "name", "foo");

            var sad = new SimpleAttributeDeserializer();

            //Act
            var actual = (SimpleAttribute)sad.Deserialize(xml);

            //Assert
            Assert.That(actual, Is.InstanceOf <SimpleAttribute>());

            Assert.That(actual.Name, Is.EqualTo(expected.Name));
            Assert.That(actual.AttributeType, Is.EqualTo(expected.AttributeType));

            Assert.That(actual.Values.ElementAt(0), Is.EqualTo(expected.Values.ElementAt(0)));
        }
Ejemplo n.º 25
0
 public void TestSimpleFill()
 {
     var simpleAttribute = new SimpleAttribute();
       this.parser.Fill(simpleAttribute);
       Assert.Equal<string>(simpleAttribute.Name, "John Doe");
 }