NullableTypes/src/Tests NullableGuidTest.cs,NONE,1.1 AssemblyInfo.cs,1.10,1.11 NullableDoubleTest.cs
Status: Inactive
Brought to you by:
lukadotnet
From: \(luKa\) <luk...@us...> - 2005-02-12 03:44:43
|
Update of /cvsroot/nullabletypes/NullableTypes/src/Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24056/src/Tests Modified Files: AssemblyInfo.cs NullableDoubleTest.cs NullableSingleTest.cs NullableStringTest.cs Tests.csproj Added Files: NullableGuidTest.cs Log Message: Index: Tests.csproj =================================================================== RCS file: /cvsroot/nullabletypes/NullableTypes/src/Tests/Tests.csproj,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Tests.csproj 8 Dec 2003 21:57:27 -0000 1.26 --- Tests.csproj 12 Feb 2005 03:44:34 -0000 1.27 *************** *** 160,163 **** --- 160,168 ---- /> <File + RelPath = "NullableGuidTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NullableInt16Test2.cs" SubType = "Code" Index: NullableStringTest.cs =================================================================== RCS file: /cvsroot/nullabletypes/NullableTypes/src/Tests/NullableStringTest.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** NullableStringTest.cs 20 Feb 2004 00:42:22 -0000 1.13 --- NullableStringTest.cs 12 Feb 2005 03:44:34 -0000 1.14 *************** *** 19,22 **** --- 19,23 ---- // 18-Feb-2004 Luca Upgrade New test: XmlSerializableEmptyElementNil for xml deserialization of a nil // value with a non empty element + // 28-Jan-2005 DamienG Bug Fix XmlSerializable test was broken - not nu.Test and not calling correct function. // *************** *** 752,768 **** public void XmlSerializable() { ! NullableString serializedDeserialized; ! serializedDeserialized = SerializeDeserialize(NullableString.Null); ! nua.Assert("TestK#01", serializedDeserialized.IsNull); ! nua.Assert("TestK#02", NullableString.Null.Equals(serializedDeserialized)); NullableString ns = new NullableString("Pino"); ! serializedDeserialized = SerializeDeserialize(ns); ! nua.Assert("TestK#03", !serializedDeserialized.IsNull); ! nua.AssertEquals("TestK#04", ns.Value, serializedDeserialized.Value); ! nua.Assert("TestK#05", ns.Equals(serializedDeserialized)); ! } --- 753,769 ---- + [nu.Test] public void XmlSerializable() { ! NullableString xmlSerializedDeserialized; ! xmlSerializedDeserialized = XmlSerializeDeserialize(NullableString.Null); ! nua.Assert("TestK#11", xmlSerializedDeserialized.IsNull); ! nua.Assert("TestK#12", NullableString.Null.Equals(xmlSerializedDeserialized)); NullableString ns = new NullableString("Pino"); ! xmlSerializedDeserialized = XmlSerializeDeserialize(ns); ! nua.Assert("TestK#13", !xmlSerializedDeserialized.IsNull); ! nua.AssertEquals("TestK#14", ns.Value, xmlSerializedDeserialized.Value); ! nua.Assert("TestK#15", ns.Equals(xmlSerializedDeserialized)); } Index: NullableSingleTest.cs =================================================================== RCS file: /cvsroot/nullabletypes/NullableTypes/src/Tests/NullableSingleTest.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** NullableSingleTest.cs 20 Feb 2004 00:42:22 -0000 1.14 --- NullableSingleTest.cs 12 Feb 2005 03:44:34 -0000 1.15 *************** *** 21,24 **** --- 21,26 ---- // 18-Feb-2004 Luca Upgrade New test: XmlSerializableEmptyElementNil for xml deserialization of a nil // value with a non empty element + // 12-Feb-2005 Luca Upgrade Code upgrade: improved test ParseFormatException to make it pass also with + // current culture German (Switzerland) de-CH LCID=2055 // *************** *** 392,395 **** --- 394,399 ---- string sx = "409'85"; NullableSingle.Parse(sx); + string sy = "409`85"; + NullableSingle.Parse(sy); } Index: NullableDoubleTest.cs =================================================================== RCS file: /cvsroot/nullabletypes/NullableTypes/src/Tests/NullableDoubleTest.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** NullableDoubleTest.cs 20 Feb 2004 00:42:22 -0000 1.16 --- NullableDoubleTest.cs 12 Feb 2005 03:44:34 -0000 1.17 *************** *** 23,26 **** --- 23,28 ---- // 18-Feb-2004 Luca Upgrade New test: XmlSerializableEmptyElementNil for xml deserialization of a nil // value with a non empty element + // 12-Feb-2005 Luca Upgrade Code upgrade: improved test ParseFormatException to make it pass also with + // current culture German (Switzerland) de-CH LCID=2055 // *************** *** 402,405 **** --- 404,410 ---- string sx = "409'85"; NullableDouble.Parse(sx); + string sy = "409`85"; + NullableDouble.Parse(sy); + } --- NEW FILE: NullableGuidTest.cs --- // // NullableTypes.Tests.NullableGuidTest // // Authors: Damien Guard (dam...@us...) // // Date Author Changes Reasons // 28-Jan-2005 DamienG Create // namespace NullableTypes.Tests { using nu = NUnit.Framework; using nua = NUnit.Framework.Assertion; using sys = System; using sysThr = System.Threading; using sysGlb = System.Globalization; using sysXml = System.Xml; using sysXmlScm = System.Xml.Schema; [nu.TestFixture] public class NullableGuidTest { private NullableGuid Test1; private NullableGuid Test2; private NullableGuid Test3; [nu.SetUp] public void SetUp() { Test1 = new NullableGuid("9180AF33-1239-4AD0-9D59-9A0BD5407F1A"); Test2 = new NullableGuid("1C432B6D-9AF7-4665-A553-12CB71E46EE5"); Test3 = new NullableGuid("E64EDB0F-E4E1-4B35-99CD-4BEDFB2E7AF0"); } // Test constructor [nu.Test] public void Create() { // Test constructors give same results nua.AssertEquals("#A01", Test1.Value, new NullableGuid(unchecked((int)0x9180AF33), 0x1239, 0x4AD0, 0x9D, 0x59, 0x9A, 0x0B, 0xD5, 0x40, 0x7F, 0x1A).Value); byte[] test2bytes = { 0xA5, 0x53, 0x12, 0xCB, 0x71, 0xE4, 0x6E, 0xE5 }; nua.AssertEquals("#A02", Test2.Value, new NullableGuid(0x1C432B6D, unchecked((short)0x9AF7), 0x4665, test2bytes).Value); } // Test public fields [nu.Test] public void PublicFields() { // Null nua.Assert("#B06", NullableGuid.Null.IsNull); } // Test properties [nu.Test] public void Properties() { // IsNull nua.Assert("#C03", !Test1.IsNull); nua.Assert("#C04", NullableGuid.Null.IsNull); // Value nua.AssertEquals("#C07", "e64edb0f-e4e1-4b35-99cd-4bedfb2e7af0", Test3.Value.ToString()); } // Public methods [nu.Test] public void CompareTo() { } [nu.Test] [nu.ExpectedException(typeof(sys.ArgumentException))] public void CompareToWrongType() { ((sys.IComparable)Test1).CompareTo(1); } [nu.Test] public void EqualsMethods() { NullableGuid t2 = new NullableGuid(Test2.Value); nua.Assert("#E01", !Test1.Equals(Test2)); nua.Assert("#E02", !Test3.Equals(Test1)); nua.Assert("#E03", Test2.Equals(t2)); // Static Equals()-method nua.Assert("#E04", NullableGuid.Equals(Test2, t2).Value); nua.Assert("#E05", !NullableGuid.Equals (Test1, Test3).Value); } [nu.Test] public void GetHashCodeTest() { // FIXME: Better way to test HashCode nua.AssertEquals("#F01", Test1.GetHashCode (), Test1.GetHashCode ()); nua.Assert("#F02", Test1.GetHashCode () != Test2.GetHashCode ()); nua.Assert("#F03", Test2.GetHashCode () == Test2.GetHashCode ()); } [nu.Test] public void GetTypeTest() { nua.AssertEquals("#G01", "NullableTypes.NullableGuid", Test1.GetType().ToString()); nua.AssertEquals("#G02", "System.Guid", Test1.Value.GetType().ToString()); } [nu.Test] public void NotEquals() { NullableGuid t2 = new NullableGuid(Test2.Value); nua.Assert("#J01", NullableGuid.NotEquals (Test1, Test2).Value); nua.Assert("#J02", NullableGuid.NotEquals (Test2, Test1).Value); nua.Assert("#J03", NullableGuid.NotEquals (Test3, Test1).Value); nua.Assert("#J04", !NullableGuid.NotEquals (Test2, t2).Value); nua.Assert("#J05", NullableGuid.NotEquals (NullableGuid.Null, Test3).IsNull); } [nu.Test] public void Conversions() { // ToNullableString() nua.AssertEquals("#O38", "9180af33-1239-4ad0-9d59-9a0bd5407f1a", Test1.ToNullableString().ToString()); // ToNullableString() with null nua.AssertEquals("#039", NullableGuid.Null.IsNull, NullableGuid.Null.ToNullableString().IsNull); } [nu.Test] public void ThanOrEqualOperators() { NullableGuid t2 = new NullableGuid(Test2.Value); // == -operator nua.Assert("#Q01", (Test2 == t2).Value); nua.Assert("#Q02", !(Test1 == Test2).Value); nua.Assert("#Q03", (Test1 == NullableGuid.Null).IsNull); // != -operator nua.Assert("#Q04", !(t2 != Test2).Value); nua.Assert("#Q05", !(Test2 != t2).Value); nua.Assert("#Q06", (Test1 != Test3).Value); nua.Assert("#Q07", (Test1 != NullableGuid.Null).IsNull); } #region Serialization - K# [nu.Test] public void SerializableAttribute() { NullableGuid serializedDeserialized; serializedDeserialized = SerializeDeserialize(NullableGuid.Null); nua.Assert("TestK#01", serializedDeserialized.IsNull); nua.Assert("TestK#02", NullableGuid.Null.Equals(serializedDeserialized)); serializedDeserialized = SerializeDeserialize(Test1); nua.Assert("TestK#03", !serializedDeserialized.IsNull); nua.AssertEquals("TestK#04", Test1.Value, serializedDeserialized.Value); nua.Assert("TestK#05", Test1.Equals(serializedDeserialized)); } private NullableGuid SerializeDeserialize(NullableGuid x) { System.Runtime.Serialization.Formatters.Soap.SoapFormatter serializer = new System.Runtime.Serialization.Formatters.Soap.SoapFormatter(); using (sys.IO.MemoryStream stream = new sys.IO.MemoryStream()) { serializer.Serialize(stream, x); // sys.Text.Decoder d = sys.Text.Encoding.Default.GetDecoder(); // char[] output = new char[d.GetCharCount(stream.GetBuffer(), 0, (int)stream.Length)]; // d.GetChars(stream.GetBuffer(), 0, (int)stream.Length, output, 0); // sys.Console.WriteLine(new string(output)); stream.Seek(0, sys.IO.SeekOrigin.Begin); // Return stream to start NullableGuid y = (NullableGuid)serializer.Deserialize(stream); stream.Close(); return y; } } [nu.Test] public void XmlSerializable() { NullableGuid xmlSerializedDeserialized; xmlSerializedDeserialized = XmlSerializeDeserialize(NullableGuid.Null); nua.Assert("TestK#01", xmlSerializedDeserialized.IsNull); nua.Assert("TestK#02", NullableGuid.Null.Equals(xmlSerializedDeserialized)); xmlSerializedDeserialized = XmlSerializeDeserialize(Test2); nua.Assert("TestK#03", !xmlSerializedDeserialized.IsNull); nua.AssertEquals("TestK#04", Test2.Value, xmlSerializedDeserialized.Value); nua.Assert("TestK#05", Test2.Equals(xmlSerializedDeserialized)); } private NullableGuid XmlSerializeDeserialize(NullableGuid x) { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(NullableGuid)); using (sys.IO.MemoryStream stream = new sys.IO.MemoryStream()) { serializer.Serialize(stream, x); // sys.Text.Decoder d = sys.Text.Encoding.Default.GetDecoder(); // char[] output = new char[d.GetCharCount(stream.GetBuffer(), 0, (int)stream.Length)]; // d.GetChars(stream.GetBuffer(), 0, (int)stream.Length, output, 0); // sys.Console.WriteLine(new string(output)); stream.Seek(0, sys.IO.SeekOrigin.Begin); // Return stream to start NullableGuid y = (NullableGuid)serializer.Deserialize(stream); stream.Close(); return y; } } [nu.Test] public void XmlSerializableEmptyElementNil() { //<?xml version="1.0"?> //<NullableGuid xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></NullableGuid> System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(NullableGuid)); using (sys.IO.MemoryStream baseStream = new sys.IO.MemoryStream()) { using (sys.IO.StreamWriter stream = new System.IO.StreamWriter(baseStream)) { stream.WriteLine("<?xml version=\"1.0\"?>"); stream.WriteLine("<NullableGuid xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"></NullableGuid>"); stream.Flush(); baseStream.Position = 0; // Return stream to start NullableGuid y = (NullableGuid)serializer.Deserialize(baseStream); nua.Assert(y.IsNull); baseStream.Close(); stream.Close(); } } } [nu.Test] public void XmlSerializableSchema() { sysXmlScm.XmlSchema xsd = ((sysXml.Serialization.IXmlSerializable)NullableGuid.Null).GetSchema(); xsd.Compile(new sysXmlScm.ValidationEventHandler(ValidationCallBack)); ValidateXmlAgainstXmlSchema(xsd, NullableGuid.Null); ValidateXmlAgainstXmlSchema(xsd, Test1); } private void ValidateXmlAgainstXmlSchema(sysXmlScm.XmlSchema xsd, NullableGuid x) { sysXml.Serialization.XmlSerializer serializer = new sysXml.Serialization.XmlSerializer(typeof(NullableGuid)); sys.IO.MemoryStream stream = null; sys.Xml.XmlValidatingReader validator = null; try { // Get the serialized NullableGuid instance stream = new sys.IO.MemoryStream(); serializer.Serialize(stream, x); stream.Seek(0, sys.IO.SeekOrigin.Begin); // Return stream to start // Add the default namespace sysXml.XmlDocument doc = new sysXml.XmlDocument(); doc.Load(stream); sysXml.XmlAttribute defaultNs = doc.CreateAttribute("xmlns"); defaultNs.Value = "http://NullableTypes.SourceForge.Net/NullableGuidXMLSchema"; doc.DocumentElement.Attributes.Append(defaultNs); // Validate validator = new sysXml.XmlValidatingReader(doc.OuterXml, sysXml.XmlNodeType.Document, null); validator.ValidationType = sys.Xml.ValidationType.Schema; validator.Schemas.Add(xsd); validator.ValidationEventHandler += new sys.Xml.Schema.ValidationEventHandler(ValidationCallBack); while(validator.Read()); } finally { if (validator != null) validator.Close(); if (stream != null) ((sys.IDisposable)stream).Dispose(); } } private static void ValidationCallBack(object sender, sysXmlScm.ValidationEventArgs args) { throw args.Exception; } #endregion //Serialization } } Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/nullabletypes/NullableTypes/src/Tests/AssemblyInfo.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AssemblyInfo.cs 25 May 2004 22:05:07 -0000 1.10 --- AssemblyInfo.cs 12 Feb 2005 03:44:34 -0000 1.11 *************** *** 12,16 **** [assembly: AssemblyCompany("Luca Minudel")] [assembly: AssemblyProduct("NullableTypes")] // Product Name ! [assembly: AssemblyCopyright("© 2003-2004 Luca Minudel, MIT license")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] --- 12,16 ---- [assembly: AssemblyCompany("Luca Minudel")] [assembly: AssemblyProduct("NullableTypes")] // Product Name ! [assembly: AssemblyCopyright("© 2003-2005 Luca Minudel, MIT license")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] *************** *** 28,33 **** // by using the '*' as shown below: ! [assembly: AssemblyVersion("1.2.*")] ! [assembly: AssemblyInformationalVersion("1.2")] // odd beta version 1.1.* - stable will be 1.2 // --- 28,33 ---- // by using the '*' as shown below: ! [assembly: AssemblyVersion("1.3.*")] ! [assembly: AssemblyInformationalVersion("1.3.0")] // odd beta version 1.1.* - stable will be 1.2 // |