public string GetTestDefault()
        {
            BindingExpression be = TestDefault.GetBindingExpression(Hyperlink.NavigateUriProperty);

            be?.UpdateTarget();
            return(TestDefault.NavigateUri.ToString());
        }
示例#2
0
		[Category ("NotWorking")] // SerializationCodeGenerator outputs wrong xsi:type for flagencoded in #C1
		public void TestSerializeDefaultValueAttribute_Encoded ()
		{
			SoapAttributeOverrides overrides = new SoapAttributeOverrides ();
			SoapAttributes attr = new SoapAttributes ();
			attr.SoapAttribute = new SoapAttributeAttribute ();
			string defaultValueInstance = "nothing";
			attr.SoapDefaultValue = defaultValueInstance;
			overrides.Add (typeof (SimpleClass), "something", attr);

			// use the default
			SimpleClass simple = new SimpleClass ();
			SerializeEncoded (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A1");

			// same value as default
			simple.something = defaultValueInstance;
			SerializeEncoded (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A2");

			// some other value
			simple.something = "hello";
			SerializeEncoded (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass id='id1' something='hello' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A3");

			attr.SoapAttribute = null;
			attr.SoapElement = new SoapElementAttribute ();

			// use the default
			simple = new SimpleClass ();
			SerializeEncoded (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B1");

			// same value as default
			simple.something = defaultValueInstance;
			SerializeEncoded (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something xsi:type='xsd:string'>nothing</something></SimpleClass>"), WriterText, "#B2");

			// some other value
			simple.something = "hello";
			SerializeEncoded (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass id='id1' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something xsi:type='xsd:string'>hello</something></SimpleClass>"), WriterText, "#B3");

			overrides = new SoapAttributeOverrides ();
			attr = new SoapAttributes ();
			attr.SoapElement = new SoapElementAttribute ("flagenc");
			overrides.Add (typeof (TestDefault), "flagencoded", attr);

			// use the default (from MS KB325691)
			TestDefault testDefault = new TestDefault ();
			SerializeEncoded (testDefault);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Default Value</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>true</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>false</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>10</decimalval>" +
				"    <flag xsi:type='FlagEnum'>e1 e4</flag>" +
				"    <flagencoded xsi:type='flagenum'>one four</flagencoded>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C1");

			SerializeEncoded (testDefault, overrides);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Default Value</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>true</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>false</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>10</decimalval>" +
				"    <flag xsi:type='FlagEnum'>e1 e4</flag>" +
				"    <flagenc xsi:type='flagenum'>one four</flagenc>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C2");

			SerializeEncoded (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Default Value</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>true</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>false</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>10</decimalval>" +
				"    <flag xmlns:q2='{2}' xsi:type='q2:FlagEnum'>e1 e4</flag>" +
				"    <flagenc xmlns:q3='{2}' xsi:type='q3:flagenum'>one four</flagenc>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace,
				AnotherNamespace)), WriterText, "#C3");

			// non-default values
			testDefault.strDefault = "Some Text";
			testDefault.boolT = false;
			testDefault.boolF = true;
			testDefault.decimalval = 20m;
			testDefault.flag = FlagEnum.e2;
			testDefault.flagencoded = FlagEnum_Encoded.e2 | FlagEnum_Encoded.e1;
			SerializeEncoded (testDefault);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Some Text</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>false</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>true</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>20</decimalval>" +
				"    <flag xsi:type='FlagEnum'>e2</flag>" +
				"    <flagencoded xsi:type='flagenum'>one two</flagencoded>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C4");

			SerializeEncoded (testDefault, overrides);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Some Text</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>false</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>true</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>20</decimalval>" +
				"    <flag xsi:type='FlagEnum'>e2</flag>" +
				"    <flagenc xsi:type='flagenum'>one two</flagenc>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C5");

			attr = new SoapAttributes ();
			attr.SoapType = new SoapTypeAttribute ("flagenum", "yetanother:urn");
			overrides.Add (typeof (FlagEnum_Encoded), attr);

			SerializeEncoded (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Some Text</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>false</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>true</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>20</decimalval>" +
				"    <flag xmlns:q2='{2}' xsi:type='q2:FlagEnum'>e2</flag>" +
				"    <flagenc xmlns:q3='yetanother:urn' xsi:type='q3:flagenum'>one two</flagenc>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace,
				AnotherNamespace)), WriterText, "#C6");

			attr = new SoapAttributes ();
			attr.SoapType = new SoapTypeAttribute ("testDefault");
			overrides.Add (typeof (TestDefault), attr);

			SerializeEncoded (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<q1:testDefault id='id1' xmlns:q1='{2}' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault xsi:type='xsd:string'>Some Text</strDefault>" +
				"    <boolT xsi:type='xsd:boolean'>false</boolT>" +
				"    <boolF xsi:type='xsd:boolean'>true</boolF>" +
				"    <decimalval xsi:type='xsd:decimal'>20</decimalval>" +
				"    <flag xsi:type='q1:FlagEnum'>e2</flag>" +
				"    <flagenc xmlns:q2='yetanother:urn' xsi:type='q2:flagenum'>one two</flagenc>" +
				"</q1:testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace,
				AnotherNamespace)), WriterText, "#C7");
		}
示例#3
0
		public void TestSerializeDefaultValueAttribute ()
		{
			XmlAttributeOverrides overrides = new XmlAttributeOverrides ();

			XmlAttributes attr = new XmlAttributes ();
			string defaultValueInstance = "nothing";
			attr.XmlDefaultValue = defaultValueInstance;
			overrides.Add (typeof (SimpleClass), "something", attr);

			// use the default
			SimpleClass simple = new SimpleClass ();
			Serialize (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A1");

			// same value as default
			simple.something = defaultValueInstance;
			Serialize (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#A2");

			// some other value
			simple.something = "hello";
			Serialize (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></SimpleClass>"), WriterText, "#A3");

			overrides = new XmlAttributeOverrides ();
			attr = new XmlAttributes ();
			attr.XmlAttribute = new XmlAttributeAttribute ();
			attr.XmlDefaultValue = defaultValueInstance;
			overrides.Add (typeof (SimpleClass), "something", attr);

			// use the default
			simple = new SimpleClass ();
			Serialize (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B1");

			// same value as default
			simple.something = defaultValueInstance;
			Serialize (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B2");

			// some other value
			simple.something = "hello";
			Serialize (simple, overrides);
			Assert.AreEqual (Infoset ("<SimpleClass something='hello' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#B3");

			overrides = new XmlAttributeOverrides ();
			attr = new XmlAttributes ();
			attr.XmlAttribute = new XmlAttributeAttribute ("flagenc");
			overrides.Add (typeof (TestDefault), "flagencoded", attr);

			// use the default
			TestDefault testDefault = new TestDefault ();
			Serialize (testDefault);
			Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C1");

			// use the default with overrides
			Serialize (testDefault, overrides);
			Assert.AreEqual (Infoset ("<testDefault flagenc='e1 e4' xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C2");

			overrides = new XmlAttributeOverrides ();
			attr = new XmlAttributes ();
			attr.XmlAttribute = new XmlAttributeAttribute ("flagenc");
			attr.XmlDefaultValue = (FlagEnum_Encoded.e1 | FlagEnum_Encoded.e4); // add default again
			overrides.Add (typeof (TestDefault), "flagencoded", attr);

			// use the default with overrides
			Serialize (testDefault, overrides);
			Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C3");

			// use the default with overrides and default namspace
			Serialize (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset ("<testDefault xmlns='urn:myNS' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText, "#C4");

			// non-default values
			testDefault.strDefault = "Some Text";
			testDefault.boolT = false;
			testDefault.boolF = true;
			testDefault.decimalval = 20m;
			testDefault.flag = FlagEnum.e2;
			testDefault.flagencoded = FlagEnum_Encoded.e2 | FlagEnum_Encoded.e1;
			Serialize (testDefault);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<testDefault xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault>Some Text</strDefault>" +
				"    <boolT>false</boolT>" +
				"    <boolF>true</boolF>" +
				"    <decimalval>20</decimalval>" +
				"    <flag>two</flag>" +
				"    <flagencoded>e1 e2</flagencoded>" +
				"</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C5");

			Serialize (testDefault, overrides);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault>Some Text</strDefault>" +
				"    <boolT>false</boolT>" +
				"    <boolF>true</boolF>" +
				"    <decimalval>20</decimalval>" +
				"    <flag>two</flag>" +
				"</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C6");

			Serialize (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault>Some Text</strDefault>" +
				"    <boolT>false</boolT>" +
				"    <boolF>true</boolF>" +
				"    <decimalval>20</decimalval>" +
				"    <flag>two</flag>" +
				"</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C7");

			attr = new XmlAttributes ();
			XmlTypeAttribute xmlType = new XmlTypeAttribute ("flagenum");
			xmlType.Namespace = "yetanother:urn";
			attr.XmlType = xmlType;
			overrides.Add (typeof (FlagEnum_Encoded), attr);

			Serialize (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<testDefault flagenc='e1 e2' xmlns='urn:myNS' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault>Some Text</strDefault>" +
				"    <boolT>false</boolT>" +
				"    <boolF>true</boolF>" +
				"    <decimalval>20</decimalval>" +
				"    <flag>two</flag>" +
				"</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)),
				WriterText, "#C8");

			attr = new XmlAttributes ();
			attr.XmlType = new XmlTypeAttribute ("testDefault");
			overrides.Add (typeof (TestDefault), attr);

			Serialize (testDefault, overrides, AnotherNamespace);
			Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
				"<testDefault flagenc='e1 e2' xmlns='{2}' xmlns:xsd='{0}' xmlns:xsi='{1}'>" +
				"    <strDefault>Some Text</strDefault>" +
				"    <boolT>false</boolT>" +
				"    <boolF>true</boolF>" +
				"    <decimalval>20</decimalval>" +
				"    <flag>two</flag>" +
				"</testDefault>", XmlSchema.Namespace, XmlSchema.InstanceNamespace,
				AnotherNamespace)), WriterText, "#C9");
		}