コード例 #1
0
ファイル: XStreamingElementTest.cs プロジェクト: nobled/mono
		public void WriteXStreamingElementChildren ()
		{
			var xml = "<?xml version='1.0' encoding='utf-8'?><root type='array'><item type='number'>0</item><item type='number'>2</item><item type='number'>5</item></root>".Replace ('\'', '"');
			
			var ms = new MemoryStream ();
			var xw = XmlWriter.Create (ms);
			int [] arr = new int [] {0, 2, 5};
			var xe = new XStreamingElement (XName.Get ("root"));
			xe.Add (new XAttribute (XName.Get ("type"), "array"));
			var at = new XAttribute (XName.Get ("type"), "number");
			foreach (var i in arr)
				xe.Add (new XStreamingElement (XName.Get ("item"), at, i));

			xe.WriteTo (xw);
			xw.Close ();
			Assert.AreEqual (xml, new StreamReader (new MemoryStream (ms.ToArray ())).ReadToEnd (), "#1");
		}
コード例 #2
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddAttributeAfterContent()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
     streamElement.Add(contact.Attribute("type"));
     using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null))
     {
         Assert.Throws<InvalidOperationException>(() => streamElement.WriteTo(w));
     }
 }
コード例 #3
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddAttribute()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(contact.Attribute("type"));
     streamElement.Add("925-555-0134");
     GetFreshStream();
     streamElement.Save(_sourceStream);
     contact.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #4
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddTimeSpanObject()
 {
     XElement contact = new XElement("Time", TimeSpan.FromMinutes(12));
     XStreamingElement streamElement = new XStreamingElement("Time");
     streamElement.Add(TimeSpan.FromMinutes(12));
     GetFreshStream();
     streamElement.Save(_sourceStream);
     contact.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #5
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddObject(object content)
 {
     XElement contact = new XElement("phone", content);
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(content);
     GetFreshStream();
     streamElement.Save(_sourceStream);
     contact.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #6
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 1, Desc = "Add(null)")]
 public void AddWithNull()
 {
     XStreamingElement streamElement = new XStreamingElement("contact");
     streamElement.Add(null);
     if (!streamElement.ToString().Equals("<contact />"))
         throw new TestFailedException("");
 }
コード例 #7
0
ファイル: CommandCenter.cs プロジェクト: haozhouxu/Jewelry
        private static void SaveLow(Dictionary<string, object> paraDic)
        {
            try
            {
                //新建一个xml文档类
                XDocument xdoc = new XDocument();
                //可以增加注释
                xdoc.Add(new XComment("增加注释测试"));
                //增加内容
                XStreamingElement rootXE = new XStreamingElement("root");

                Jewelry je = paraDic["context"] as Jewelry;

                //解析内容
                rootXE.Add(new XElement("guid", je.Guid.ToString()));
                rootXE.Add(new XElement("image", helper.ImageToBase64(je.Image)));
                rootXE.Add(new XElement("totalweight", je.TotalWeight.ToString()));
                rootXE.Add(new XElement("jadeweight", je.JadeWeight.ToString()));
                rootXE.Add(new XElement("goldweight", je.GoldWeight.ToString()));
                rootXE.Add(new XElement("processfee", je.ProcessFee.ToString()));
                rootXE.Add(new XElement("otherfee", je.OtherFee.ToString()));
                rootXE.Add(new XElement("totalprice", je.TotalPrice.ToString()));

                xdoc.Add(rootXE);

                string sql = string.Format("insert into {0} Values('{1}','{2}','{3}','{4}')", "detail", je.Guid.ToString(), xdoc.ToString(), System.DateTime.Now, System.DateTime.Now);

                SQLiteConnection conn = new SQLiteConnection(@"Data Source=c:/xhz/ms.db;");
                //SQLiteConnection conn = new SQLiteConnection(@"Data Source=DB/ms.db;");
                conn.Open();
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);

                int i = cmd.ExecuteNonQuery();

                System.Windows.MessageBox.Show(i.ToString());

                conn.Close();

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message.ToString());
            }
            finally
            {

            }
        }
コード例 #8
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddIEnumerableOfXNodesPlusAttribute()
 {
     InputSpace.Contacts(ref _xDoc, ref _xmlDoc);
     XAttribute xAttrib = new XAttribute("Attribute", "Value");
     XElement element = new XElement("contacts", xAttrib, _xDoc.Root.DescendantNodes());
     XStreamingElement streamElement = new XStreamingElement("contacts");
     streamElement.Add(xAttrib, _xDoc.Root.DescendantNodes());
     GetFreshStream();
     streamElement.Save(_sourceStream);
     element.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #9
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 1, Desc = "Add(IEnumerable of Mixed Nodes)")]
 public void AddIEnumerableOfMixedNodes()
 {
     XElement element = new XElement("root", GetMixedNodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(GetMixedNodes());
     getFreshStream();
     streamElement.Save(_sourceStream); element.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #10
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 0, Desc = "Add(IEnumerable of XNodes)")]
 public void AddIEnumerableOfXNodes()
 {
     XElement x = InputSpace.GetElement(100, 3);
     XElement element = new XElement("root", x.Nodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(x.Nodes());
     getFreshStream();
     streamElement.Save(_sourceStream); element.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #11
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //An attribute cannot be written after content.
 //[Variation(Priority = 1, Desc = "Add(XAttribute) After Content is Added)")]
 public void AddAttributeAfterContent()
 {
     try
     {
         XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
         XStreamingElement streamElement = new XStreamingElement("phone", "925-555-0134");
         streamElement.Add(contact.Attribute("type"));
         using (XmlWriter w = XmlWriter.Create(new MemoryStream(), null))
         {
             streamElement.WriteTo(w);
         }
     }
     catch (System.InvalidOperationException)
     {
         return;
     }
     throw new TestFailedException("");
 }
コード例 #12
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 0, Desc = "Add(XAttribute)")]
 public void AddAttribute()
 {
     XElement contact = new XElement("phone", new XAttribute("type", "home"), "925-555-0134");
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(contact.Attribute("type"));
     streamElement.Add("925-555-0134");
     getFreshStream();
     streamElement.Save(_sourceStream); contact.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #13
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 1, Desc = "Add(TimeSpan)")]
 public void AddTimeSpanObject()
 {
     XElement contact = new XElement("Time", TimeSpan.FromMinutes(12));
     XStreamingElement streamElement = new XStreamingElement("Time");
     streamElement.Add(TimeSpan.FromMinutes(12));
     getFreshStream();
     streamElement.Save(_sourceStream); contact.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #14
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 0, Desc = "Add(String)", Params = new object[] { "9255550134" })]
 //[Variation(Priority = 0, Desc = "Add(Double)", Params = new object[] { (Double)9255550134 })]
 //[Variation(Priority = 0, Desc = "Add(Int)", Params = new object[] { (Int64)9255550134 })]
 public void AddObject()
 {
     XElement contact = new XElement("phone", Variation.Params[0]);
     XStreamingElement streamElement = new XStreamingElement("phone");
     streamElement.Add(Variation.Params[0]);
     getFreshStream();
     streamElement.Save(_sourceStream); contact.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #15
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddIEnumerableOfXNodes()
 {
     XElement x = InputSpace.GetElement(100, 3);
     XElement element = new XElement("root", x.Nodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(x.Nodes());
     GetFreshStream();
     streamElement.Save(_sourceStream);
     element.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #16
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddIEnumerableOfMixedNodes()
 {
     XElement element = new XElement("root", GetMixedNodes());
     XStreamingElement streamElement = new XStreamingElement("root");
     streamElement.Add(GetMixedNodes());
     GetFreshStream();
     streamElement.Save(_sourceStream);
     element.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #17
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 0, Desc = "Add(XAttribute + IEnumerable of XNodes)")]
 public void AddIEnumerableOfXNodesPlusAttribute()
 {
     InputSpace.Contacts(ref _xDoc, ref _xmlDoc);
     XAttribute xAttrib = new XAttribute("Attribute", "Value");
     XElement element = new XElement("contacts", xAttrib, _xDoc.Root.DescendantNodes());
     XStreamingElement streamElement = new XStreamingElement("contacts");
     streamElement.Add(xAttrib, _xDoc.Root.DescendantNodes());
     getFreshStream();
     streamElement.Save(_sourceStream); element.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #18
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void NestedXStreamingElementPlusIEnumerable()
 {
     InputSpace.Contacts(ref _xDoc, ref _xmlDoc);
     XElement element = new XElement("contacts", new XElement("Element", "Value"), _xDoc.Root.DescendantNodes());
     XStreamingElement streamElement = new XStreamingElement("contacts");
     streamElement.Add(new XStreamingElement("Element", "Value"), _xDoc.Root.DescendantNodes());
     GetFreshStream();
     streamElement.Save(_sourceStream);
     element.Save(_targetStream);
     ResetStreamPos();
     Assert.True(Diff.Compare(_sourceStream, _targetStream));
 }
コード例 #19
0
ファイル: StreamingOutput.cs プロジェクト: nnyamhon/corefx
 //[Variation(Priority = 0, Desc = "Nested XStreamingElements + IEnumerable")]
 public void NestedXStreamingElementPlusIEnumerable()
 {
     InputSpace.Contacts(ref _xDoc, ref _xmlDoc);
     XElement element = new XElement("contacts", new XElement("Element", "Value"), _xDoc.Root.DescendantNodes());
     XStreamingElement streamElement = new XStreamingElement("contacts");
     streamElement.Add(new XStreamingElement("Element", "Value"), _xDoc.Root.DescendantNodes());
     getFreshStream();
     streamElement.Save(_sourceStream); element.Save(_targetStream);
     resetStreamPos();
     if (!_diff.Compare(_sourceStream, _targetStream))
         throw new TestFailedException("");
 }
コード例 #20
0
ファイル: StreamingOutput.cs プロジェクト: noahfalk/corefx
 public void AddWithNull()
 {
     XStreamingElement streamElement = new XStreamingElement("contact");
     streamElement.Add(null);
     Assert.Equal("<contact />", streamElement.ToString());
 }
コード例 #21
0
ファイル: RegressionTests.cs プロジェクト: johnhhm/corefx
                //[Variation(Desc = "Tuple - New Dev10 Types", Param = 1)]
                //[Variation(Desc = "DynamicObject - New Dev10 Types", Param = 2)]
                //[Variation(Desc = "Guid - old type", Param = 3)]
                //[Variation(Desc = "Dictionary - old type", Param = 4)]
                public void CreatingXElementsFromNewDev10Types()
                {
                    object t = null;
                    Type type = typeof(object);
                    int param = (int)this.Variation.Param;
                    switch (param)
                    {
                        case 1: t = Tuple.Create(1, "Melitta", 7.5); type = typeof(Tuple); break;
                        case 3: t = new Guid(); type = typeof(Guid); break;
                        case 4: t = new Dictionary<int, string>(); ((Dictionary<int, string>)t).Add(7, "a"); type = typeof(Dictionary<int, string>); break;
                    }

                    XElement e = new XElement("e1",
                        new XElement("e2"), "text1",
                        new XElement("e3"), t);
                    e.Add(t);
                    e.FirstNode.ReplaceWith(t);

                    XNode n = e.FirstNode.NextNode;
                    n.AddBeforeSelf(t);
                    n.AddAnnotation(t);
                    n.ReplaceWith(t);

                    e.FirstNode.AddAfterSelf(t);
                    e.AddFirst(t);
                    e.Annotation(type);
                    e.Annotations(type);
                    e.RemoveAnnotations(type);
                    e.ReplaceAll(t);
                    e.ReplaceAttributes(t);
                    e.ReplaceNodes(t);
                    e.SetAttributeValue("a", t);
                    e.SetElementValue("e2", t);
                    e.SetValue(t);

                    XAttribute a = new XAttribute("a", t);
                    XStreamingElement se = new XStreamingElement("se", t);
                    se.Add(t);

                    try
                    {
                        new XDocument(t);
                    }
                    catch (ArgumentException)
                    {
                        try
                        {
                            new XDocument(t);
                        }
                        catch (ArgumentException)
                        {
                            return;
                        }
                    }
                    TestLog.Compare(false, "Failed");
                }