private void TestXmlSerializableObject(string path, XmlRawObjectBase original) { using (Stream wrt = new FileStream(path, FileMode.Create)) { using (IStructuredWriter writer = SimpleStructuredWriter.CreateWriter(wrt, new SimpleServiceContainer())) { writer.WriteObjectElement("Before", 3712); writer.WriteObjectElement("data", original); writer.WriteObjectElement("After", 3712 * 2); } } using (Stream str = new FileStream(path, FileMode.Open)) { using (IStructuredReader reader = SimpleStructuredReader.CreateReader(str, null)) { Assert.That(reader.ReadObjectElement("Before"), Is.EqualTo(3712)); if (original.BugWhileReading == BugRead.ThrowApplicationException) { Assert.Throws <ApplicationException>(() => reader.ReadObjectElement("data")); // Even if an exception is thrown, we can continue to read the data. } else if (original.BugWhileReading == BugRead.None) { CheckExactTypeAndValue(original.GetType(), original, reader.ReadObjectElement("data")); } else { XmlRawObjectBase read = (XmlRawObjectBase)reader.ReadObjectElement("data"); Assert.That(read.BugWhileReading == original.BugWhileReading); } Assert.That(reader.ReadObjectElement("After"), Is.EqualTo(3712 * 2), "Whatever happens above, one can continue to read."); } } }
private void TestXmlSerializableObject( string path, XmlRawObjectBase original ) { using( Stream wrt = new FileStream( path, FileMode.Create ) ) { using( IStructuredWriter writer = SimpleStructuredWriter.CreateWriter( wrt, new SimpleServiceContainer() ) ) { writer.WriteObjectElement( "Before", 3712 ); writer.WriteObjectElement( "data", original ); writer.WriteObjectElement( "After", 3712*2 ); } } using( Stream str = new FileStream( path, FileMode.Open ) ) { using( IStructuredReader reader = SimpleStructuredReader.CreateReader( str, null ) ) { Assert.That( reader.ReadObjectElement( "Before" ), Is.EqualTo( 3712 ) ); if( original.BugWhileReading == BugRead.ThrowApplicationException ) { Assert.Throws<ApplicationException>( () => reader.ReadObjectElement( "data" ) ); // Even if an exception is thrown, we can continue to read the data. } else if( original.BugWhileReading == BugRead.None ) { CheckExactTypeAndValue( original.GetType(), original, reader.ReadObjectElement( "data" ) ); } else { XmlRawObjectBase read = (XmlRawObjectBase)reader.ReadObjectElement( "data" ); Assert.That( read.BugWhileReading == original.BugWhileReading ); } Assert.That( reader.ReadObjectElement( "After" ), Is.EqualTo( 3712 * 2 ), "Whatever happens above, one can continue to read." ); } } }
public bool Equals(XmlRawObjectBase other) { return(other != null && Name == other.Name && Power == other.Power); }
public bool Equals( XmlRawObjectBase other ) { return other != null && Name == other.Name && Power == other.Power; }