Example #1
0
        public void LockAllElementsExceptCollectionIsCorrectType()
        {
            var lockCollection = new SimpleElement().LockAllElementsExcept;

            Assert.Equal(0, lockCollection.Count);
            Assert.Equal("LockedElementsExceptionList", LockType.GetValue(lockCollection).ToString());
        }
Example #2
0
        public void EvaluationContextThrows()
        {
            // If we haven't associated a configuration record we should fail
            SimpleElement element = new SimpleElement();

            Assert.Throws <ConfigurationErrorsException>(() => element.TestEvaluationContext);
        }
Example #3
0
        public void LockAttributesCollectionIsCorrectType()
        {
            var lockCollection = new SimpleElement().LockAttributes;

            Assert.Equal(0, lockCollection.Count);
            Assert.Equal("LockedAttributes", LockType.GetValue(lockCollection).ToString());
        }
        public void TestObjectMethods()
        {
            SimpleDocument sd1 = new SimpleDocument("doc1");
            SimpleDocument sd2 = new SimpleDocument("doc2");

            Assert.IsFalse(sd1.Equals(sd2));
            sd1.Name = "doc2";
            Assert.IsTrue(sd1.Equals(sd2));
            sd1.DocumentComment = "comment";
            Assert.IsFalse(sd1.Equals(sd2));
            sd2.DocumentComment = sd1.DocumentComment;
            Assert.IsTrue(sd1.Equals(sd2));
            sd1.DtdUri = "test.dtd";
            Assert.IsFalse(sd1.Equals(sd2));
            Assert.AreNotEqual(sd1.GetHashCode(), sd2.GetHashCode());
            sd2.DtdUri = sd1.DtdUri;
            Assert.IsTrue(sd1.Equals(sd2));
            sd1.DtdName = "public name";
            Assert.IsFalse(sd1.Equals(sd2));
            sd2.DtdName = sd1.DtdName;
            Assert.IsTrue(sd1.Equals(sd2));
            sd1.Encoding = "UTF-8";
            Assert.IsFalse(sd1.Equals(sd2));
            sd2.Encoding = sd1.Encoding;
            Assert.IsTrue(sd1.Equals(sd2));
            Assert.AreEqual(sd1.GetHashCode(), sd2.GetHashCode());

            SimpleElement se = new SimpleElement();

            Assert.IsFalse(sd1.Equals(se));
        }
Example #5
0
        public void SetLockItem()
        {
            var element = new SimpleElement();

            element.LockItem = true;
            Assert.True(element.LockItem);
        }
        public SimpleElement setWebmasterToolsExtension(string extension, string newValue)
        {
            if (extension == null)
            {
                throw new System.ArgumentNullException("extension");
            }

            SimpleElement ele = getWebmasterToolsExtension(extension);

            if (ele == null && newValue != null)
            {
                ele = CreateExtension(extension, WebmasterToolsNameTable.gWebmasterToolsNamspace) as SimpleElement;
                if (ele != null)
                {
                    this.ExtensionElements.Add(ele);
                }
            }
            if (ele == null)
            {
                throw new System.ArgumentException("invalid extension element specified");
            }

            if (newValue == null && ele != null)
            {
                DeleteExtensions(extension, WebmasterToolsNameTable.gWebmasterToolsNamspace);
            }

            if (ele != null)
            {
                ele.Value = newValue;
            }

            return(ele);
        }
Example #7
0
        public SimpleElement setWebmasterToolsExtension(string extension, string newValue)
        {
            if (extension == null)
            {
                throw new ArgumentNullException("extension");
            }
            SimpleElement element = this.getWebmasterToolsExtension(extension);

            if ((element == null) && (newValue != null))
            {
                element = base.CreateExtension(extension, "http://schemas.google.com/webmasters/tools/2007") as SimpleElement;
                if (element != null)
                {
                    base.ExtensionElements.Add(element);
                }
            }
            if (element == null)
            {
                throw new ArgumentException("invalid extension element specified");
            }
            if ((newValue == null) && (element != null))
            {
                base.DeleteExtensions(extension, "http://schemas.google.com/webmasters/tools/2007");
            }
            if (element != null)
            {
                element.Value = newValue;
            }
            return(element);
        }
Example #8
0
 public void LoadParameter()
 {
     ReadXml($"{CommonFunction.DefaultConfigPath}Gauge{TableName}.xml");
     if (File.Exists($"{CommonFunction.DefaultConfigPath}GPara{TableName}.xml"))
     {
         SimpleElement root = XmlDomUtil.readDefaultPathConfigFile($"GPara{TableName}.xml");
         RefThickness                   = double.Parse(root.ChildElements["RefThickness"].Text);
         ThicknessMeasRefLeft           = double.Parse(root.ChildElements["ThicknessRefLeft"].Text);
         ThicknessMeasRefMid            = double.Parse(root.ChildElements["ThicknessRefMid"].Text);
         ThicknessMeasRefRight          = double.Parse(root.ChildElements["ThicknessRefRight"].Text);
         ThicknessLeftLinear.Slope      = double.Parse(root.ChildElements["ThicknessLeftLinear"].Attributes["Slope"]);
         ThicknessLeftLinear.Intercept  = double.Parse(root.ChildElements["ThicknessLeftLinear"].Attributes["Intercept"]);
         ThicknessLeftLinear.Enable     = bool.Parse(root.ChildElements["ThicknessLeftLinear"].Attributes["Enable"]);
         ThicknessMidLinear.Slope       = double.Parse(root.ChildElements["ThicknessMidLinear"].Attributes["Slope"]);
         ThicknessMidLinear.Intercept   = double.Parse(root.ChildElements["ThicknessMidLinear"].Attributes["Intercept"]);
         ThicknessMidLinear.Enable      = bool.Parse(root.ChildElements["ThicknessMidLinear"].Attributes["Enable"]);
         ThicknessRightLinear.Slope     = double.Parse(root.ChildElements["ThicknessRightLinear"].Attributes["Slope"]);
         ThicknessRightLinear.Intercept = double.Parse(root.ChildElements["ThicknessRightLinear"].Attributes["Intercept"]);
         ThicknessRightLinear.Enable    = bool.Parse(root.ChildElements["ThicknessRightLinear"].Attributes["Enable"]);
         CCDXLinear.Slope               = double.Parse(root.ChildElements["CCDXLinear"].Attributes["Slope"]);
         CCDXLinear.Intercept           = double.Parse(root.ChildElements["CCDXLinear"].Attributes["Intercept"]);
         CCDXLinear.Enable              = bool.Parse(root.ChildElements["CCDXLinear"].Attributes["Enable"]);
         CCDYLinear.Slope               = double.Parse(root.ChildElements["CCDYLinear"].Attributes["Slope"]);
         CCDYLinear.Intercept           = double.Parse(root.ChildElements["CCDYLinear"].Attributes["Intercept"]);
         CCDYLinear.Enable              = bool.Parse(root.ChildElements["CCDYLinear"].Attributes["Enable"]);
     }
 }
        /////////////////////////////////////////////////////////////////////////////



        protected void DisplayExtensions(AtomBase obj)
        {
            foreach (Object o in obj.ExtensionElements)
            {
                IExtensionElementFactory e = o as IExtensionElementFactory;
                SimpleElement            s = o as SimpleElement;
                XmlElement x = o as XmlElement;
                if (s != null)
                {
                    DumpSimpleElement(s);

                    SimpleContainer sc = o as SimpleContainer;

                    if (sc != null)
                    {
                        foreach (SimpleElement se in sc.ExtensionElements)
                        {
                            DumpSimpleElement(se);
                        }
                    }
                }
                else if (e != null)
                {
                    Tracing.TraceMsg("Found an extension Element " + e.ToString());
                }
                else if (x != null)
                {
                    Tracing.TraceMsg("Found an XmlElement " + x.ToString() + " " + x.LocalName + " " + x.NamespaceURI);
                }
                else
                {
                    Tracing.TraceMsg("Found an object " + o.ToString());
                }
            }
        }
Example #10
0
        public void TestObjectMethods()
        {
            //Equals
            SimpleElement se1 = new SimpleElement("name");
            SimpleElement se2 = new SimpleElement("name", "value");
            SimpleValue   sv  = new SimpleValue("value");

            Assert.IsFalse(se1.Equals(sv));
            Assert.IsFalse(se1.Equals(se2));
            se2.SetString(se1.GetString());
            Assert.IsTrue(se1.Equals(se2));
            se1.AddElement("child1");
            se1.AddElement("child2");
            Assert.IsFalse(se1.Equals(se2));
            se2.AddElement("child1");
            se2.AddElement("child2");
            Assert.IsTrue(se1.Equals(se2));
            se1.AddAttribute("attr1");
            Assert.IsFalse(se1.Equals(se2));
            se2.AddAttribute("attr1");
            Assert.IsTrue(se1.Equals(se2));

            //GetHashCode
            Assert.AreEqual(XmlHelper.HashElement(se1), se1.GetHashCode());

            //Clone
            SimpleElement se1c = (SimpleElement)se1.Clone();

            Assert.AreEqual(se1c, se1);
            Assert.AreNotSame(se1, se1c);
            se1.Comment = "comment";
            Assert.AreNotEqual(se1c, se1);
        }
Example #11
0
        public void ValueIsSet()
        {
            const int elementValue = 4711;
            var       element      = new SimpleElement {
                Value = elementValue
            };

            Assert.That(element.Value, Is.EqualTo(elementValue));
        }
Example #12
0
        public void TestElementMethods()
        {
            //GetElement
            SimpleElement se = new SimpleElement();

            Assert.IsNull(se.GetElement("child1"));
            IXmlElement child1 = se.AddElement("child1");

            Assert.IsNotNull(se.GetElement("child1"));

            //FindElement
            Assert.IsNull(se.FindElement("/child2"));
            Assert.AreEqual(child1, se.FindElement("/child1"));

            //EnsureElement
            Assert.AreEqual(se.ElementList.Count, 1);
            Assert.IsNotNull(se.EnsureElement("/child2"));
            IXmlElement child2 = se.GetElement("child2");

            Assert.IsTrue(child2.IsMutable);
            Assert.AreEqual(se.ElementList.Count, 2); //element is added

            //GetSafeElement
            Assert.AreEqual(se.ElementList.Count, 2);
            Assert.AreEqual(se, se.GetSafeElement(""));
            IXmlElement child3 = se.GetSafeElement("/child3");

            Assert.IsNotNull(child3);
            Assert.IsFalse(child3.IsMutable);
            Assert.AreEqual(se.ElementList.Count, 2); //element is not added
            IXmlElement child4 = se.GetSafeElement("/child3/../child4");

            Assert.IsNotNull(child4);
            Exception e = null;

            try
            {
                se.GetSafeElement(null);
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(ArgumentNullException), e);
            e = null;
            try
            {
                se.GetSafeElement("..");
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(ArgumentException), e);
        }
        /// <summary>
        /// instead of having 20 extension elements
        /// we have one string based getter
        /// usage is: entry.getPhotoExtensionValue("albumid") to get the elements value
        /// </summary>
        /// <param name="extension">the name of the extension to look for</param>
        /// <returns>value as string, or NULL if the extension was not found</returns>
        public string getYouTubeExtensionValue(string extension)
        {
            SimpleElement e = getYouTubeExtension(extension);

            if (e != null)
            {
                return(e.Value);
            }
            return(null);
        }
        public string getWebmasterToolsValue(string extension)
        {
            SimpleElement e = getWebmasterToolsExtension(extension);

            if (e != null)
            {
                return(e.Value);
            }
            return(null);
        }
Example #15
0
        public void ValueChangedEventWhenValueChanges()
        {
            var  element     = new SimpleElement();
            bool eventCalled = false;

            element.ValueChanged += (sender, e) => eventCalled = true;
            element.Value         = 6;

            Assert.That(eventCalled, Is.True);
        }
        /// <summary>
        /// we have one string based getter
        /// usage is: entry.getExtensionValue("namespace", "tagname") to get the elements value
        /// </summary>
        /// <param name="extension">the name of the extension to look for</param>
        /// <param name="ns">the namespace of the extension to look for</param>
        /// <returns>value as string, or NULL if the extension was not found</returns>
        public string GetExtensionValue(string extension, string ns)
        {
            SimpleElement e = FindExtension(extension, ns) as SimpleElement;

            if (e != null)
            {
                return(e.Value);
            }
            return(null);
        }
Example #17
0
        public void ValueWithMultiplierElement()
        {
            var element1 = new ConstantElement(3000);
            var element2 = new SimpleElement {
                Value = 5, AggregateType = AggregateType.Multiplicate
            };

            this.composableAttribute.AddElement(element1);
            this.composableAttribute.AddElement(element2);
            Assert.That(this.composableAttribute.Value, Is.EqualTo(element1.Value * element2.Value));
        }
Example #18
0
        public void ValueChangedEventWhenElementAdded()
        {
            var element = new SimpleElement {
                Value = 5
            };
            bool eventCalled = false;

            this.composableAttribute.ValueChanged += (sender, e) => eventCalled = true;
            this.composableAttribute.AddElement(element);
            Assert.That(eventCalled, Is.True);
        }
Example #19
0
        public void ValueChangedEventWhenAggregateTypeChanges()
        {
            var element = new SimpleElement {
                Value = 0
            };
            bool eventCalled = false;

            element.ValueChanged += (sender, e) => eventCalled = true;
            element.AggregateType = AggregateType.AddFinal;

            Assert.That(eventCalled, Is.True);
        }
 protected void DumpSimpleElement(SimpleElement s)
 {
     Tracing.TraceMsg("Found a simple Element " + s.ToString() + " " + s.Value);
     if (s.Attributes.Count > 0)
     {
         for (int i = 0; i < s.Attributes.Count; i++)
         {
             string name  = s.Attributes.GetKey(i) as string;
             string value = s.Attributes.GetByIndex(i) as string;
             Tracing.TraceMsg("--- Attributes on element: " + name + ":" + value);
         }
     }
 }
Example #21
0
        public void TestWriteMethods()
        {
            //WriteValue
            TextWriter    writer = new StringWriter();
            SimpleElement se     = new SimpleElement("root", "some\ntext");

            se.WriteValue(writer, true);
            Assert.AreEqual(se.GetString(), writer.ToString());

            writer = new StringWriter();
            IndentingWriter indentedWriter = new IndentingWriter(writer, 2);

            se.WriteValue(indentedWriter, true);
            Assert.AreEqual(se.GetString(), writer.ToString());

            //WriteXml
            se     = new SimpleElement("root");
            writer = new StringWriter();
            se.WriteXml(writer, true);
            Assert.AreEqual("<root/>", writer.ToString());

            se.AddAttribute("attr1").SetString("value1");
            writer = new StringWriter();
            se.WriteXml(writer, true);
            Assert.AreEqual("<root attr1='value1'/>", writer.ToString());

            se.Comment = "comment text";
            se.SetString("content");
            writer = new StringWriter();
            se.WriteXml(writer, true);
            Assert.AreEqual("<root attr1='value1'><!--" + writer.NewLine + "comment text" + writer.NewLine + "-->content</root>", writer.ToString());
            writer = new StringWriter();
            se.WriteXml(writer, false);
            Assert.AreEqual("<root attr1='value1'><!--comment text-->content</root>", writer.ToString());

            se.AddElement("child").SetString("child content");
            writer = new StringWriter();
            se.WriteXml(writer, true);
            string result = "<root attr1='value1'>" + writer.NewLine + "  <!--" + writer.NewLine + "  comment text" +
                            writer.NewLine + "  -->" + writer.NewLine + "content" + writer.NewLine + "  <child>child content</child>" +
                            writer.NewLine + "</root>";

            Assert.AreEqual(result, writer.ToString());
            Assert.AreEqual(result, se.ToString());

            writer = new StringWriter();
            se.WriteXml(writer, false);
            result = "<root attr1='value1'><!--comment text-->content<child>child content</child></root>";
            Assert.AreEqual(result, writer.ToString());
        }
Example #22
0
            public int Compare(object x, object y)
            {
                if (x == null || y == null)
                {
                    throw new ArgumentNullException();
                }
                if (!(x is SimpleElement) || !(y is SimpleElement))
                {
                    throw new ArgumentException();
                }
                SimpleElement se1 = (SimpleElement)x;
                SimpleElement se2 = (SimpleElement)y;

                return(se1.Name.CompareTo(se2.Name));
            }
Example #23
0
    public void ValueChangedEvent()
    {
        var element = new SimpleElement {
            Value = 5
        };

        this._composableAttribute.AddElement(element);

        var eventCalled = false;

        this._composableAttribute.ValueChanged += (_, _) => eventCalled = true;
        element.Value = 6;

        Assert.That(eventCalled, Is.True);
    }
Example #24
0
 static void Main(string[] args)
 {
     FluentXmlWriter.Start("root")
     .Simple("First")
     .Simple("Second").Attr("a", "b")
     .Complex("Arr")
     .ManySimple(
         SimpleElement.Create("Arr1").Attr("key1", "val1"),
         SimpleElement.Create("Arr2").Attr("key2", "val2")
         ).EndElem()
     .Complex("Third").Text("My Text").EndElem()
     .Complex("Fourth").CData("Hello there!").EndElem()
     .Comment("A comment!")
     .OutputToString(Console.WriteLine);
 }
    public void InputOperatorPower()
    {
        const int element1Value = 1;
        const int element2Value = 2;
        const int inputOperand  = 10;
        var       element1      = new SimpleElement {
            Value = element1Value
        };
        var element2 = new SimpleElement {
            Value = element2Value
        };
        var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, inputOperand, InputOperator.Exponentiate);

        Assert.That(relationshipElement.Value, Is.EqualTo(Math.Pow(element1Value + element2Value, inputOperand)));
    }
    public void InputOperatorMultiply()
    {
        const int element1Value = 1;
        const int element2Value = 2;
        const int inputOperand  = 10;
        var       element1      = new SimpleElement {
            Value = element1Value
        };
        var element2 = new SimpleElement {
            Value = element2Value
        };
        var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, inputOperand, InputOperator.Multiply);

        Assert.That(relationshipElement.Value, Is.EqualTo((element1Value + element2Value) * inputOperand));
    }
Example #27
0
        public void SaveParameter()
        {
            WriteXml($"{CommonFunction.DefaultConfigPath}Gauge{TableName}.xml", XmlWriteMode.WriteSchema);
            SimpleElement root = new SimpleElement("GaugePara");
            SimpleElement para;

            para = new SimpleElement("RefThickness"); para.Text = RefThickness.ToString(); root.ChildElements.Add(para);
            para = new SimpleElement("ThicknessRefLeft"); para.Text = ThicknessMeasRefLeft.ToString(); root.ChildElements.Add(para);
            para = new SimpleElement("ThicknessRefMid"); para.Text = ThicknessMeasRefMid.ToString(); root.ChildElements.Add(para);
            para = new SimpleElement("ThicknessRefRight"); para.Text = ThicknessMeasRefRight.ToString(); root.ChildElements.Add(para);
            para = new SimpleElement("ThicknessLeftLinear"); para.Attributes.Add("Slope", ThicknessLeftLinear.Slope.ToString()); para.Attributes.Add("Intercept", ThicknessLeftLinear.Intercept.ToString()); para.Attributes.Add("Enable", ThicknessLeftLinear.Enable.ToString()); root.ChildElements.Add(para);
            para = new SimpleElement("ThicknessMidLinear"); para.Attributes.Add("Slope", ThicknessMidLinear.Slope.ToString()); para.Attributes.Add("Intercept", ThicknessMidLinear.Intercept.ToString()); para.Attributes.Add("Enable", ThicknessMidLinear.Enable.ToString()); root.ChildElements.Add(para);
            para = new SimpleElement("ThicknessRightLinear"); para.Attributes.Add("Slope", ThicknessRightLinear.Slope.ToString()); para.Attributes.Add("Intercept", ThicknessRightLinear.Intercept.ToString()); para.Attributes.Add("Enable", ThicknessRightLinear.Enable.ToString()); root.ChildElements.Add(para);
            para = new SimpleElement("CCDXLinear"); para.Attributes.Add("Slope", CCDXLinear.Slope.ToString()); para.Attributes.Add("Intercept", CCDXLinear.Intercept.ToString()); para.Attributes.Add("Enable", CCDXLinear.Enable.ToString()); root.ChildElements.Add(para);
            para = new SimpleElement("CCDYLinear"); para.Attributes.Add("Slope", CCDYLinear.Slope.ToString()); para.Attributes.Add("Intercept", CCDYLinear.Intercept.ToString()); para.Attributes.Add("Enable", CCDYLinear.Enable.ToString()); root.ChildElements.Add(para);
            XmlDomUtil.writeXMLtoDefulatPathConfigFile(root, 3, $"GPara{TableName}.xml");
        }
Example #28
0
        public void ValueCorrectAfterElementRemoved()
        {
            var element1 = new ConstantElement(3000);
            var element2 = new SimpleElement {
                Value = 5, AggregateType = AggregateType.Multiplicate
            };
            var element3 = new SimpleElement {
                Value = 1000, AggregateType = AggregateType.AddFinal
            };

            this.composableAttribute.AddElement(element1);
            this.composableAttribute.AddElement(element2);
            this.composableAttribute.AddElement(element3);
            Assert.That(this.composableAttribute.Value, Is.EqualTo((element1.Value * element2.Value) + element3.Value));
            this.composableAttribute.RemoveElement(element2);
            Assert.That(this.composableAttribute.Value, Is.EqualTo(element1.Value + element3.Value));
        }
Example #29
0
        public void TestConstructors()
        {
            SimpleElement se = new SimpleElement("name");

            Assert.IsNotNull(se);
            Assert.IsNull(se.Value);
            Assert.IsNotNull(se.Name);
            Assert.AreEqual("name", se.Name);

            se = new SimpleElement("name", "value");
            Assert.IsNotNull(se);
            Assert.IsNotNull(se.Value);
            Assert.IsNotNull(se.Name);
            Assert.AreEqual("name", se.Name);
            Assert.AreEqual(se.Value, "value");
            Assert.AreEqual(se.GetString(), "value");
        }
    public void ValueChangedEventWhenElementChanges()
    {
        const int element1Value = 1;
        const int element2Value = 2;
        const int inputOperand  = 10;
        var       element1      = new SimpleElement {
            Value = element1Value
        };
        var element2 = new SimpleElement {
            Value = element2Value
        };
        var relationshipElement = new AttributeRelationshipElement(new[] { element1, element2 }, inputOperand, InputOperator.Add);
        var eventCalled         = false;

        relationshipElement.ValueChanged += (sender, e) => eventCalled = true;
        element1.Value = 2;
        Assert.That(eventCalled, Is.True);
    }
Example #31
0
        private SimpleElement GetFeedData()
        {
            if (feedData == null)
            {
                feedData = new SimpleElement(GetResponse(BuildRequest("feed", "rss"), null)["channel"]);
            }

            return feedData;
        }