adapdev-commits Mailing List for Adapdev.NET (Page 21)
Status: Beta
Brought to you by:
intesar66
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
(26) |
Apr
(59) |
May
(37) |
Jun
(53) |
Jul
(13) |
Aug
(7) |
Sep
(5) |
Oct
(74) |
Nov
(404) |
Dec
(14) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(10) |
Feb
(26) |
Mar
(64) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: jhbate <jh...@us...> - 2005-11-06 09:48:33
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30966/src/Adapdev.Data/Schema Modified Files: TableSchemaDictionary.cs Log Message: Changes made for schema xml serialization. Uses the interface IXmlSerializable to support the reading and wrting of the IDictionary type Index: TableSchemaDictionary.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/TableSchemaDictionary.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TableSchemaDictionary.cs 28 Feb 2005 01:31:48 -0000 1.1.1.1 --- TableSchemaDictionary.cs 6 Nov 2005 09:48:24 -0000 1.2 *************** *** 4,11 **** using System.Collections; using System.Text; [Serializable] ! public class TableSchemaDictionary : DictionaryBase { public TableSchema this[String key] { --- 4,16 ---- using System.Collections; using System.Text; + using System.Xml.Serialization; [Serializable] ! public class TableSchemaDictionary : DictionaryBase, IXmlSerializable { + + private const string nameSpace = ""; + private const string tableDictionaryElement = "TableDictionary"; + public TableSchema this[String key] { *************** *** 13,17 **** set { Dictionary[key] = value; } } ! public ICollection Keys { --- 18,22 ---- set { Dictionary[key] = value; } } ! public ICollection Keys { *************** *** 48,52 **** --- 53,121 ---- return sb.ToString(); } + #region IXmlSerializable Members + /// <summary> + /// XmlWriter that is used to write the TableSchemaDictionary as it implements IDictory that is not serializable + /// using the normal methods. This uses the interface IXmlSerializable which isn't offically supported but still + /// exists in the next framework + /// </summary> + /// <param name="writer">System.Xml.XmlWriter</param> + public void WriteXml(System.Xml.XmlWriter writer) + { + XmlSerializer keySer = new XmlSerializer(typeof(String)); + XmlSerializer valueSer = new XmlSerializer(typeof(TableSchema)); + + writer.WriteStartElement(tableDictionaryElement,nameSpace); + foreach(object key in Dictionary.Keys){ + + writer.WriteStartElement("key", nameSpace); + keySer.Serialize(writer,key); + writer.WriteEndElement(); + + writer.WriteStartElement("value", nameSpace); + object value = Dictionary[key]; + valueSer.Serialize(writer, value); + writer.WriteEndElement(); + } + writer.WriteEndElement(); + } + + public System.Xml.Schema.XmlSchema GetSchema() + { + return null; + } + + /// <summary> + /// Custom XmlReader to read the TableSchemaDictionary + /// </summary> + /// <param name="reader">System.Xml.XmlReader</param> + public void ReadXml(System.Xml.XmlReader reader) + { + XmlSerializer keySer = new XmlSerializer(typeof(String)); + XmlSerializer valueSer = new XmlSerializer(typeof(TableSchema)); + + reader.Read(); + reader.ReadStartElement(tableDictionaryElement,nameSpace); + + while(reader.Name != tableDictionaryElement && reader.NodeType != System.Xml.XmlNodeType.EndElement) + { + reader.ReadStartElement("key", nameSpace); + object key = keySer.Deserialize(reader); + reader.ReadEndElement(); + + reader.ReadStartElement("value", nameSpace); + object value = valueSer.Deserialize(reader); + reader.ReadEndElement(); + + Dictionary.Add(key, value); + reader.MoveToContent(); + //navigate past the end element tags to the next table + do{ + reader.Skip(); + }while(reader.NodeType == System.Xml.XmlNodeType.EndElement && reader.Name != tableDictionaryElement); + } + reader.ReadEndElement(); + } + #endregion } } \ No newline at end of file |
From: jhbate <jh...@us...> - 2005-11-06 09:47:26
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30737/src/Adapdev.Data/Schema Modified Files: TableSchema.cs Log Message: Changes made for schema xml serialization. Uses custom SchemaDataRewritableAttribute attribute to indicate if a property is to be uppdated. Added Xml tags to properties Index: TableSchema.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/TableSchema.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TableSchema.cs 18 Sep 2005 03:04:45 -0000 1.4 --- TableSchema.cs 6 Nov 2005 09:47:18 -0000 1.5 *************** *** 3,7 **** --- 3,10 ---- using System; using System.Collections; + using System.Xml.Serialization; + using Adapdev.Attributes; using Adapdev.Text; + /// <summary> *************** *** 9,14 **** /// </summary> [Serializable] ! public class TableSchema { protected TableType tableType = TableType.TABLE; protected bool _active = true; --- 12,18 ---- /// </summary> [Serializable] ! public class TableSchema { + protected TableType tableType = TableType.TABLE; protected bool _active = true; *************** *** 55,59 **** /// </summary> /// <param name="name">The name of the ColumnSchema to retrieve</param> ! /// <returns></returns> public ColumnSchema GetColumn(string name) { --- 59,63 ---- /// </summary> /// <param name="name">The name of the ColumnSchema to retrieve</param> ! /// <returns></returns> public ColumnSchema GetColumn(string name) { *************** *** 70,138 **** } ! /// <summary> ! /// Returns a collection of ColumnSchemas ! /// </summary> ! /// <returns></returns> ! public ColumnSchemaDictionary Columns ! { ! get{return this.columns;} ! set{this.columns = value;} ! } ! ! /// <summary> ! /// Returns a collection of ColumnSchemas that are primary keys ! /// </summary> ! /// <returns></returns> ! public ColumnSchemaDictionary PrimaryKeys ! { ! get ! { ! ColumnSchemaDictionary pks = new ColumnSchemaDictionary(); ! foreach(ColumnSchema c in this.columns.Values) ! { ! if(c.IsPrimaryKey)pks[c.Name] = c; ! } ! return pks; ! } ! } /// <summary> ! /// Returns a collection of ColumnSchemas that are foreign keys /// </summary> /// <returns></returns> ! public ColumnSchemaDictionary ForeignKeys { get { ! ColumnSchemaDictionary fks = new ColumnSchemaDictionary(); ! foreach(ColumnSchema c in this.columns.Values) { ! if(c.IsForeignKey)fks[c.Name] = c; } ! return fks; } } /// <summary> - /// Gets the number of primary keys - /// </summary> - /// <returns></returns> - public int PrimaryKeyCount - { - get - { - int i = 0; - foreach (ColumnSchema c in columns.Values) - { - if(c.IsPrimaryKey)i++; - } - return i; - } - } - - /// <summary> /// Gets the number of foreign keys /// </summary> /// <returns></returns> public int ForeignKeyCount { --- 74,104 ---- } ! /// <summary> ! /// Gets the number of primary keys /// </summary> /// <returns></returns> ! [XmlAttribute] ! [SchemaDataRewritableAttribute(false)] ! public int PrimaryKeyCount { get { ! int i = 0; ! foreach (ColumnSchema c in columns.Values) { ! if(c.IsPrimaryKey)i++; } ! return i; } } /// <summary> /// Gets the number of foreign keys /// </summary> /// <returns></returns> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public int ForeignKeyCount { *************** *** 184,187 **** --- 150,154 ---- /// </summary> /// <returns></returns> + [XmlIgnore] public SortedList OrdinalColumns { *************** *** 201,204 **** --- 168,172 ---- /// </summary> /// <returns></returns> + [XmlIgnore] public SortedList SortedColumns { *************** *** 218,221 **** --- 186,191 ---- /// </summary> /// <returns></returns> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string ProperName { *************** *** 228,231 **** --- 198,203 ---- /// be part of a DatabaseSchema, but ignored for various reasons /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public bool IsActive { *************** *** 237,240 **** --- 209,214 ---- /// The table name /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public string Name { *************** *** 246,249 **** --- 220,225 ---- /// The table alias /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string Alias { *************** *** 256,259 **** --- 232,237 ---- } + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public bool HasForeignKeys { *************** *** 265,268 **** --- 243,248 ---- } + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public bool HasPrimaryKeys { *************** *** 274,277 **** --- 254,304 ---- } + /// <summary> + /// Returns a collection of ColumnSchemas + /// </summary> + /// <returns></returns> + [XmlElement(Type = typeof(ColumnSchemaDictionary), ElementName = "Columns")] + public ColumnSchemaDictionary Columns + { + get{return this.columns;} + set{this.columns = value;} + } + + /// <summary> + /// Returns a collection of ColumnSchemas that are primary keys + /// </summary> + /// <returns></returns> + [XmlElement(Type = typeof(ColumnSchemaDictionary), ElementName = "PrimaryKeys")] + public ColumnSchemaDictionary PrimaryKeys + { + get + { + ColumnSchemaDictionary pks = new ColumnSchemaDictionary(); + foreach(ColumnSchema c in this.columns.Values) + { + if(c.IsPrimaryKey)pks[c.Name] = c; + } + return pks; + } + } + + /// <summary> + /// Returns a collection of ColumnSchemas that are foreign keys + /// </summary> + /// <returns></returns> + [XmlElement(Type = typeof(ColumnSchemaDictionary), ElementName = "ForeignKeys")] + public ColumnSchemaDictionary ForeignKeys + { + get + { + ColumnSchemaDictionary fks = new ColumnSchemaDictionary(); + foreach(ColumnSchema c in this.columns.Values) + { + if(c.IsForeignKey)fks[c.Name] = c; + } + return fks; + } + } + public override string ToString() { |
From: jhbate <jh...@us...> - 2005-11-06 09:46:57
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30632/src/Adapdev.Data/Schema Modified Files: ColumnSchemaDictionary.cs Log Message: Changes made for schema xml serialization. Uses the interface IXmlSerializable to support the reading and wrting of the IDictionary type Index: ColumnSchemaDictionary.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/ColumnSchemaDictionary.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ColumnSchemaDictionary.cs 28 Feb 2005 01:31:47 -0000 1.1.1.1 --- ColumnSchemaDictionary.cs 6 Nov 2005 09:46:49 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- using System.Collections; using System.Text; + using System.Xml.Serialization; /// <summary> *************** *** 10,15 **** /// [Serializable] ! public class ColumnSchemaDictionary : DictionaryBase { public ColumnSchema this[String key] { --- 11,19 ---- /// [Serializable] ! public class ColumnSchemaDictionary : DictionaryBase, IXmlSerializable { + private const string nameSpace = ""; + private const string columnDictionaryElement = "ColumnDictionary"; + public ColumnSchema this[String key] { *************** *** 52,57 **** --- 56,120 ---- return sb.ToString(); } + #region IXmlSerializable Members + /// <summary> + /// XmlWriter that is used to write the ColumnSchemaDictionary as it implements IDictory that is not serializable + /// using the normal methods. This uses the interface IXmlSerializable which isn't offically supported but still + /// exists in the next framework + /// </summary> + /// <param name="writer">System.Xml.XmlWriter</param> + public void WriteXml(System.Xml.XmlWriter writer) + { + XmlSerializer keySer = new XmlSerializer(typeof(String)); + XmlSerializer valueSer = new XmlSerializer(typeof(ColumnSchema)); + + writer.WriteStartElement(columnDictionaryElement, nameSpace); + foreach(object key in Dictionary.Keys) + { + writer.WriteStartElement("key", nameSpace); + keySer.Serialize(writer,key); + writer.WriteEndElement(); + + writer.WriteStartElement("value", nameSpace); + object value = Dictionary[key]; + valueSer.Serialize(writer, value); + writer.WriteEndElement(); + } + writer.WriteEndElement(); + } + public System.Xml.Schema.XmlSchema GetSchema() + { + return null; + } + /// <summary> + /// Custom XmlReader to read the ColumnSchemaDictionary + /// </summary> + /// <param name="reader">System.Xml.XmlReader</param> + public void ReadXml(System.Xml.XmlReader reader) + { + XmlSerializer keySer = new XmlSerializer(typeof(String)); + XmlSerializer valueSer = new XmlSerializer(typeof(ColumnSchema)); + + reader.Read(); + reader.ReadStartElement(columnDictionaryElement, nameSpace); + + while(reader.NodeType != System.Xml.XmlNodeType.EndElement) + { + + reader.ReadStartElement("key", nameSpace); + object key = keySer.Deserialize(reader); + reader.ReadEndElement(); + + reader.ReadStartElement("value", nameSpace); + object value = valueSer.Deserialize(reader); + reader.ReadEndElement(); + + Dictionary.Add(key, value); + reader.MoveToContent(); + } + reader.ReadEndElement(); + } + #endregion } } \ No newline at end of file |
From: jhbate <jh...@us...> - 2005-11-06 09:44:25
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30219/src/Adapdev.Data/Schema Added Files: CompareDatabaseSchemas.cs LoadDatabaseSchema.cs SaveDatabaseSchema.cs SchemaConstants.cs Log Message: added to support the schema XML serialization --- NEW FILE: SaveDatabaseSchema.cs --- using System; namespace Adapdev.Data.Schema { using System.IO; using System.Xml.Serialization; /// <summary> /// Summary description for SaveDatabaseSchema. /// </summary> public class SaveDatabaseSchema { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private DatabaseSchema _dbSchema; private String schemaFile; private String _savedSchemaName; public SaveDatabaseSchema(DatabaseSchema dbSchema, String savedSchemaName) { this._dbSchema = dbSchema; this._savedSchemaName = savedSchemaName; } public void Save() { schemaFile = System.IO.Path.Combine(SchemaConstants.SCHEMAPATH,_savedSchemaName); XmlSerializer dbSerializer = new XmlSerializer(typeof(DatabaseSchema)); StreamWriter schemaWriter = new StreamWriter(schemaFile); dbSerializer.Serialize(schemaWriter, _dbSchema); schemaWriter.Close(); } } } --- NEW FILE: LoadDatabaseSchema.cs --- using System; namespace Adapdev.Data.Schema { using System.Collections; using System.IO; using System.Xml.Serialization; /// <summary> /// Summary description for LoadDatabaseSchema. /// </summary> public class LoadDatabaseSchema { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private DatabaseSchema _dbSchema; private String schemaFile; private String _savedSchemaName; public LoadDatabaseSchema(String savedSchemaName, DatabaseSchema dbSchema) { this._savedSchemaName = savedSchemaName; this._dbSchema = dbSchema; } public DatabaseSchema Load() { schemaFile = System.IO.Path.Combine(SchemaConstants.SCHEMAPATH,this._savedSchemaName); if(File.Exists(schemaFile)) { XmlSerializer dbSerializer = new XmlSerializer(typeof(DatabaseSchema)); FileStream dbStream = new FileStream(schemaFile, FileMode.Open); _dbSchema = (DatabaseSchema) dbSerializer.Deserialize(dbStream); dbStream.Close(); } return _dbSchema; } } } --- NEW FILE: SchemaConstants.cs --- using System; namespace Adapdev.Data.Schema { /// <summary> /// Summary description for Constants Associated with the Schema /// </summary> public class SchemaConstants { public static readonly string SCHEMAPATH = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); } } --- NEW FILE: CompareDatabaseSchemas.cs --- using System; namespace Adapdev.Data.Schema { using System.Reflection; using Adapdev.Attributes; /// <summary> /// Summary description for CompareSchemasCommand. /// </summary> public class CompareDatabaseSchemas { private DatabaseSchema _databaseSchema; private DatabaseSchema _savedDatabaseSchema; public CompareDatabaseSchemas(DatabaseSchema databaseSchema, DatabaseSchema savedDatabaseSchema) { this._databaseSchema = databaseSchema; this._savedDatabaseSchema = savedDatabaseSchema; } /// <summary> /// Compare the saved Schema and the database Schema by iterating through the DatabaseSchema's tables /// </summary> /// <returns>DatabaseSchema - the updated DatabaseSchema</returns> public DatabaseSchema Compare() { foreach(TableSchema table in _databaseSchema.SortedTables.Values) { //If the table exists check it otherwise add the table if(null != this._savedDatabaseSchema.GetTable(table.Name)) { foreach (PropertyInfo property in table.GetType().GetProperties()) { foreach (object attribute in property.GetCustomAttributes(typeof(SchemaDataRewritableAttribute),true)) { if(isRewritable(attribute, property)) { rewritePropertyForTable(table, property); } } } findAndUpdateColumns(table); } else { this._savedDatabaseSchema.AddTable(table); } } return _savedDatabaseSchema; } /// <summary> /// Iterate through the ColumnSchema's for a TableSchema and update properties that are rewritable from the Database Schema /// </summary> /// <param name="table">TableSchema table that we will check it's ColumnSchema's</param> private void findAndUpdateColumns(TableSchema table) { foreach(ColumnSchema column in table.SortedColumns.Values) { //If the column exists check it otherwise add the column if(null != this._savedDatabaseSchema.GetTable(table.Name).GetColumn(column.Name)) { foreach (PropertyInfo property in column.GetType().GetProperties()) { foreach(object attribute in property.GetCustomAttributes(typeof(SchemaDataRewritableAttribute),true)) { if(isRewritable(attribute,property)) { rewritePropertyForColumn(table,column,property); } } } } else { this._savedDatabaseSchema.GetTable(table.Name).AddColumn(column); } } } /// <summary> /// Rewrite the TableSchema proprety to match that from the Database /// </summary> /// <param name="tableToUpdateFrom">TableSchema object that we will use to update from</param> /// <param name="property">PropertyInfo</param> private void rewritePropertyForTable(TableSchema tableToUpdateFrom, PropertyInfo property) { TableSchema tableToUpdate = this._savedDatabaseSchema.GetTable(tableToUpdateFrom.Name); PropertyInfo tablePropertyToUpdate = tableToUpdate.GetType().GetProperty(property.Name); tablePropertyToUpdate.SetValue(this._savedDatabaseSchema.GetTable(tableToUpdateFrom.Name), property.GetValue(tableToUpdateFrom,null),null); } /// <summary> /// Rewrite the ColumnSchema proprety to match that from the Database /// </summary> /// <param name="tableToUpdateFrom">TableSchema object that we will use to update from</param> /// <param name="columnToUpdateFrom">ColumnSchema object that we will use to update from</param> /// <param name="property">PropertyInfo</param> private void rewritePropertyForColumn(TableSchema tableToUpdateFrom, ColumnSchema columnToUpdateFrom, PropertyInfo property) { ColumnSchema columnToUpdate = this._savedDatabaseSchema.GetTable(tableToUpdateFrom.Name).GetColumn(columnToUpdateFrom.Name); PropertyInfo columnPropertyToUpdate = columnToUpdate.GetType().GetProperty(property.Name); columnPropertyToUpdate.SetValue(columnToUpdate, property.GetValue(columnToUpdateFrom, null),null); } /// <summary> /// Is the SchemaDataRewritableAttribute set to update. /// </summary> /// <param name="attribute">The custom attribute for the property</param> /// <param name="property">The Schema PropertyInfo</param> /// <returns>bool</returns> private bool isRewritable(object attribute,PropertyInfo property) { return ((SchemaDataRewritableAttribute) attribute).Rewrite && property.CanWrite; } } } |
From: jhbate <jh...@us...> - 2005-11-06 09:41:37
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29764/src/Adapdev.Data/Schema Modified Files: ColumnSchema.cs Log Message: Changes made for schema xml serialization. Uses custom SchemaDataRewritableAttribute attribute to indicate if a property is to be uppdated. Added Xml tags to properties Index: ColumnSchema.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/ColumnSchema.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ColumnSchema.cs 23 Oct 2005 07:27:20 -0000 1.5 --- ColumnSchema.cs 6 Nov 2005 09:41:27 -0000 1.6 *************** *** 3,6 **** --- 3,8 ---- using System; using System.Collections; + using System.Xml.Serialization; + using Adapdev.Attributes; using Adapdev.Text; *************** *** 34,37 **** --- 36,41 ---- /// Specifies whether the column is readonly /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public bool IsReadOnly { *************** *** 45,48 **** --- 49,54 ---- /// be part of a TableSchema, but ignored for various reasons /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public bool IsActive { *************** *** 54,57 **** --- 60,65 ---- /// The ordinal number of the column /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public int Ordinal { *************** *** 63,66 **** --- 71,76 ---- /// Specifies whether the column allows nulls /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public bool AllowNulls { *************** *** 72,75 **** --- 82,87 ---- /// Specifies whether the column is unique /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public bool IsUnique { *************** *** 81,84 **** --- 93,98 ---- /// Specifies whether the column is an autoincrement column /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public bool IsAutoIncrement { *************** *** 90,93 **** --- 104,109 ---- /// Specifies whether the column is a primary key /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public bool IsPrimaryKey { *************** *** 99,102 **** --- 115,120 ---- /// Specifies whether the column is a foreign key /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public bool IsForeignKey { *************** *** 108,111 **** --- 126,131 ---- /// Specifies whether the column is a key (primary or foreign) /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public bool IsKey { *************** *** 120,123 **** --- 140,145 ---- /// The .NET Object equivalent for the column /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public string NetType { *************** *** 129,132 **** --- 151,156 ---- /// The database type /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public string DataType { *************** *** 138,141 **** --- 162,167 ---- /// The column length /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public int Length { *************** *** 147,150 **** --- 173,178 ---- /// The column name /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public string Name { *************** *** 156,159 **** --- 184,189 ---- /// The column alias /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string Alias { *************** *** 169,172 **** --- 199,204 ---- /// The numeric id (assigned by ADO.NET) for the specified data type /// </summary> + [XmlAttribute] + [SchemaDataRewritableAttribute(true)] public int DataTypeId { *************** *** 179,182 **** --- 211,216 ---- /// </summary> /// <value></value> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string DefaultValue { *************** *** 189,192 **** --- 223,228 ---- /// </summary> /// <value></value> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string DefaultTestValue { *************** *** 199,202 **** --- 235,239 ---- /// </summary> /// <value></value> + [XmlIgnore] public ArrayList ForeignKeyTables { *************** *** 210,213 **** --- 247,252 ---- /// </summary> /// <returns></returns> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string ProperName { *************** *** 220,223 **** --- 259,264 ---- /// </summary> /// <returns></returns> + [XmlAttribute] + [SchemaDataRewritableAttribute(false)] public string MemberName { |
From: jhbate <jh...@us...> - 2005-11-06 09:30:28
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev/Attributes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27558/src/Adapdev/Attributes Added Files: SchemaDataRewritableAttribute.cs Log Message: Added attribute for the Schema Serialization. Used to say if a property is to be updated with the value from the latest database schema loaded --- NEW FILE: SchemaDataRewritableAttribute.cs --- using System; namespace Adapdev.Attributes { /// <summary> /// Summary description for CompareAttribute. /// /// Add this attribute to Schema properties that should or shouldn't be updated when performing /// a CompareDatabaseSchema between the saved schema and DB schema's /// </summary> [AttributeUsage(AttributeTargets.Property)] public class SchemaDataRewritableAttribute : Attribute { private bool _rewrite; /// <summary> /// SchemaDataRewritableAttribute /// </summary> /// <param name="rewrite">bool - is this property going to be rewritten from the DatabaseSchema</param> public SchemaDataRewritableAttribute(bool rewrite) { this._rewrite = rewrite; } /// <summary> /// Is this Schema property it be re-written from the Database schama /// </summary> public bool Rewrite { get{return this._rewrite;} set{this._rewrite = value;} } } } |
From: jhbate <jh...@us...> - 2005-11-06 09:28:36
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev/Attributes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27073/Attributes Log Message: Directory /cvsroot/adapdev/Adapdev/src/Adapdev/Attributes added to the repository |
From: Sean M. <int...@us...> - 2005-11-02 13:45:26
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Cache.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev.Cache.Tests Modified Files: CacheManagerTest.cs Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests Index: CacheManagerTest.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Cache.Tests/CacheManagerTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CacheManagerTest.cs 25 May 2005 05:17:46 -0000 1.1 --- CacheManagerTest.cs 2 Nov 2005 13:45:12 -0000 1.2 *************** *** 25,28 **** --- 25,44 ---- } + + [Test] + public void SetCache() + { + Assert.AreEqual(typeof(ImmutableInMemoryCache), CacheManager.Cache.GetType()); + + CacheManager.Cache.Add(1, new SuppliersEntity()); + Assert.AreEqual(1, CacheManager.Cache.Count); + + CacheManager.SetCache(CacheType.MutableInMemory); + Assert.AreEqual(1, CacheManager.Cache.Count, "Cache has switched BUT should have been copied, so count should be 1."); + + CacheManager.SetCache(CacheType.ImmutableInMemory, false); + Assert.AreEqual(0, CacheManager.Cache.Count, "Cache has switched BUT should not have been copied, so count should be 0."); + + } } } |
From: Sean M. <int...@us...> - 2005-11-02 13:45:23
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev.Tests Modified Files: ObjectComparerTest.cs Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests Index: ObjectComparerTest.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Tests/ObjectComparerTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ObjectComparerTest.cs 3 Jun 2005 04:32:59 -0000 1.1 --- ObjectComparerTest.cs 2 Nov 2005 13:45:13 -0000 1.2 *************** *** 1,4 **** --- 1,7 ---- using System; + using System.Text; + using System.Threading; using Adapdev.Mock; + using Adapdev.Serialization; using NUnit.Framework; *************** *** 34,37 **** --- 37,92 ---- } + + [Test] + public void FailAreEqualWithFields() + { + DateTime now = DateTime.Now; + + SuppliersEntity e1 = new SuppliersEntity(); + e1.Address = "Test"; + e1.SupplierID = 12; + e1.Created = now; + + Thread.Sleep(1000); + + SuppliersEntity e2 = new SuppliersEntity(); + e2.Address = "Test"; + e2.SupplierID = 12; + e2.Created = now; + + //Console.WriteLine(e1); + //Console.WriteLine(e2); + + Assert.IsFalse(ObjectComparer.AreEqual(e1, e2, true), "Objects should not be equal because InternalCreated is different."); + } + + [Test] + public void FailAreEqualWithFieldsSerialization() + { + DateTime now = DateTime.Now; + + SuppliersEntity e1 = new SuppliersEntity(); + e1.Address = "Test"; + e1.SupplierID = 12; + e1.Created = now; + + SuppliersEntity e2 = new SuppliersEntity(); + e2.Address = "Test"; + e2.SupplierID = 12; + e2.Created = now; + + string a = Serializer.SerializeToXml(e1); + string b = Serializer.SerializeToXml(e2); + + Console.WriteLine(a); + Console.WriteLine(b); + Assert.IsTrue(a == b, "Objects should be equal."); + + e2.Created = DateTime.Now.AddHours(1); + + // byte[] c = Serializer.SerializeToBinary(e2); + // + // Assert.IsFalse(a == c, "Objects should not be equal."); + } } } |
From: Sean M. <int...@us...> - 2005-11-02 13:45:23
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev.Data Modified Files: Adapdev.Data.csproj Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests Index: Adapdev.Data.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Adapdev.Data.csproj,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Adapdev.Data.csproj 18 Sep 2005 03:04:45 -0000 1.11 --- Adapdev.Data.csproj 2 Nov 2005 13:45:13 -0000 1.12 *************** *** 236,239 **** --- 236,244 ---- /> <File + RelPath = "Schema\AssociationType.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Schema\ColumnSchema.cs" SubType = "Code" |
From: Sean M. <int...@us...> - 2005-11-02 13:45:23
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev.Data/Schema Modified Files: ForeignKeyAssociation.cs Added Files: AssociationType.cs Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests --- NEW FILE: AssociationType.cs --- using System; namespace Adapdev.Data.Schema { /// <summary> /// Summary description for AssociationType. /// </summary> public enum AssociationType { OneToOne, OneToMany, ManyToMany, ManyToOne } } Index: ForeignKeyAssociation.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Schema/ForeignKeyAssociation.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForeignKeyAssociation.cs 25 Mar 2005 02:16:30 -0000 1.1 --- ForeignKeyAssociation.cs 2 Nov 2005 13:45:13 -0000 1.2 *************** *** 13,16 **** --- 13,17 ---- private TableSchema _foreignTable = null; private ColumnSchema _columnSchema = null; + private AssociationType _association = AssociationType.OneToMany; public ColumnSchema ForeignColumn *************** *** 20,23 **** --- 21,29 ---- } + public string ForeignColumnName + { + get{return this._foreignColumn.Name;} + } + public ColumnSchema Column { *************** *** 26,29 **** --- 32,40 ---- } + public string ColumnName + { + get{return this._columnSchema.Name;} + } + public TableSchema ForeignTable { *************** *** 32,35 **** --- 43,62 ---- } + public string ForeignTableName + { + get{return this._foreignTable.Name;} + } + + public string ForeignKeyName + { + get{return this.ColumnName + "-" + this.ForeignTableName + "." + this.ForeignColumnName;} + } + + public AssociationType AssociationType + { + get { return _association; } + set { _association = value; } + } + public ForeignKeyAssociation(ColumnSchema columnSchema, ColumnSchema foreignColumn, TableSchema foreignTable) { *************** *** 39,42 **** --- 66,70 ---- } + public override string ToString() { |
From: Sean M. <int...@us...> - 2005-11-02 13:45:23
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev.Cache Modified Files: Adapdev.Cache.csproj CacheManager.cs Added Files: CacheType.cs Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests --- NEW FILE: CacheType.cs --- using System; namespace Adapdev.Cache { /// <summary> /// Summary description for CacheType. /// </summary> public enum CacheType { File, ImmutableInMemory, MutableInMemory } } Index: Adapdev.Cache.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Cache/Adapdev.Cache.csproj,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Adapdev.Cache.csproj 2 Jun 2005 03:25:59 -0000 1.6 --- Adapdev.Cache.csproj 2 Nov 2005 13:45:12 -0000 1.7 *************** *** 136,139 **** --- 136,144 ---- /> <File + RelPath = "CacheType.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "CacheUtil.cs" SubType = "Code" Index: CacheManager.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Cache/CacheManager.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CacheManager.cs 20 Jun 2005 01:47:49 -0000 1.3 --- CacheManager.cs 2 Nov 2005 13:45:12 -0000 1.4 *************** *** 31,34 **** --- 31,65 ---- } } + + public static void SetCache(CacheType cacheType, bool copyExisting) + { + ICache cache = null; + + switch(cacheType) + { + case CacheType.File: + cache = new FileCache(); + if(copyExisting) cache.Copy(Cache); + Cache = cache; + break; + case CacheType.ImmutableInMemory: + cache = new ImmutableInMemoryCache(); + if(copyExisting) cache.Copy(Cache); + Cache = cache; + break; + case CacheType.MutableInMemory: + cache = new MutableInMemoryCache(); + if(copyExisting) cache.Copy(Cache); + Cache = cache; + break; + default: + break; + } + } + + public static void SetCache(CacheType cacheType) + { + SetCache(cacheType, true); + } } } |
From: Sean M. <int...@us...> - 2005-11-02 13:45:23
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev Modified Files: ObjectComparer.cs Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests Index: ObjectComparer.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev/ObjectComparer.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ObjectComparer.cs 25 May 2005 05:17:49 -0000 1.3 --- ObjectComparer.cs 2 Nov 2005 13:45:13 -0000 1.4 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Reflection; using Adapdev.Reflection; *************** *** 15,18 **** --- 16,24 ---- public static bool AreEqual(object x, object y) { + return AreEqual(x, y, false); + } + + public static bool AreEqual(object x, object y, bool includeFields) + { Type t = x.GetType(); ClassAccessor accessor = ClassAccessorCache.Get(t); *************** *** 31,34 **** --- 37,46 ---- return false; } + + if(includeFields) + { + if(!AreFieldsEqual(x, y)) return false; + } + return true; } *************** *** 38,41 **** --- 50,62 ---- } } + + private static bool AreFieldsEqual(object x, object y) + { + foreach(FieldInfo field in x.GetType().GetFields()) + { + if(!(field.GetValue(x).ToString().Equals(field.GetValue(y).ToString()))) return false; + } + return true; + } } } |
From: Sean M. <int...@us...> - 2005-11-02 13:45:23
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev/Mock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/src/Adapdev/Mock Modified Files: SuppliersEntity.cs Log Message: Improved ObjectComparer to include field comparisons Added AssociationType for ForeignKeyAssociations Improved CacheManager and associated tests Index: SuppliersEntity.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev/Mock/SuppliersEntity.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SuppliersEntity.cs 25 May 2005 05:17:49 -0000 1.1 --- SuppliersEntity.cs 2 Nov 2005 13:45:13 -0000 1.2 *************** *** 28,31 **** --- 28,32 ---- private System.Int32 _SupplierID = 0; private System.DateTime _Created = DateTime.Now; + public System.DateTime InternalCreated = DateTime.Now; |
From: Sean M. <int...@us...> - 2005-11-01 05:41:53
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3474/src/Adapdev.UnitTest.Core.AdapdevTests Modified Files: Adapdev.UnitTest.Core.AdapdevTests.csproj AdapdevAttributes.cs Added Files: MultiThreadedRepeatTest.cs Log Message: Added multi-threading for repeated tests Index: Adapdev.UnitTest.Core.AdapdevTests.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests/Adapdev.UnitTest.Core.AdapdevTests.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Adapdev.UnitTest.Core.AdapdevTests.csproj 26 Oct 2005 05:27:45 -0000 1.2 --- Adapdev.UnitTest.Core.AdapdevTests.csproj 1 Nov 2005 05:41:40 -0000 1.3 *************** *** 100,103 **** --- 100,108 ---- /> <File + RelPath = "MultiThreadedRepeatTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "MultiThreadedTest.cs" SubType = "Code" --- NEW FILE: MultiThreadedRepeatTest.cs --- using System; using System.Threading; using Adapdev.UnitTest; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for MultiThreadedTest. /// </summary> /// [TestFixture(IsMultiThreaded=true)] public class MultiThreadedRepeatTest { int i = 0; [Test, Repeat(5)] public void ThreadedRepeat() { i = 0; int a = 0; while(a <= 10) { i += 1; Thread.Sleep(5); a++; Console.WriteLine("Thread {0}: {1}", AppDomain.GetCurrentThreadId(), i); } Assert.IsFalse(i==10, "i equals 10, which means it was not interrupted by other Threads."); } } } Index: AdapdevAttributes.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests/AdapdevAttributes.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AdapdevAttributes.cs 26 Oct 2005 05:27:45 -0000 1.2 --- AdapdevAttributes.cs 1 Nov 2005 05:41:40 -0000 1.3 *************** *** 172,184 **** } - // A Test that is repeated a set number of times on multiple threads - [Test(Description="A Test that is repeated 5X, with a 3 second delay between each run.")] - [Repeat(5)] - public void MultiThreadedRepeat() - { - Console.WriteLine("Repeat with delay"); - Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); - } - // Runs once at the end of each Test iteration [TearDown] --- 172,175 ---- |
From: Sean M. <int...@us...> - 2005-11-01 05:41:53
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3474/src/Adapdev.UnitTest.Core Modified Files: Adapdev.UnitTest.Core.csproj RunTestFixtureCommand.cs Added Files: RunTestCommand.cs RunTestIterationCommand.cs Log Message: Added multi-threading for repeated tests --- NEW FILE: RunTestCommand.cs --- using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; using Adapdev.Commands; using Adapdev.Diagnostics; using Adapdev.Threading; using log4net; namespace Adapdev.UnitTest.Core { /// <summary> /// Summary description for NonThreadedRunTestCommand. /// </summary> public class RunTestCommand : ICommand { // create the logger private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // setup the logging levels private bool _debugMode = log.IsDebugEnabled; private bool _infoMode = log.IsInfoEnabled; private TestEventDispatcher _dispatcher = null; private Test _test = null; private TestFixture _testFixture = null; private Type _type = null; private object o = null; private TestFixtureIteration _testFixtureIteration = null; public RunTestCommand(TestEventDispatcher dispatcher, Test test, TestFixture tf, Type type, object o, TestFixtureIteration tfi) { this._dispatcher = dispatcher; this._test = test; this._testFixture = tf; this.o = o; this._testFixtureIteration = tfi; this._type = type; } public void Execute() { try { MethodInfo m = _type.GetMethod(_test.Method); TestResult tr = new TestResult(_test); tr.TestId = _test.Id; tr.Description = _test.Description; if(this._debugMode) log.Debug("Running T " + _test.Name); if (!_test.Ignore && _test.ShouldRun) { if(_dispatcher != null)_dispatcher.OnTestStarted(new TestEventArgs(_test)); this.RunTestIteration(tr, m); } else { TestIteration ti = new TestIteration(); ti.Name = _test.Name; ti.State = TestState.Ignore; ti.Result = _test.IgnoreReason; tr.AddIteration(ti); } if (_testFixture.ShouldShow) _testFixtureIteration.AddTestResult(tr); if(_dispatcher != null)_dispatcher.OnTestCompleted(new TestResultEventArgs(tr)); } catch (Exception e) { Console.WriteLine(e.Message + " " + e.StackTrace); } finally { } } private void RunTestIteration(TestResult testResult, MethodInfo method) { if(this._testFixture.IsMultiThreaded) { using(ThreadPoolWait threadPool = new ThreadPoolWait()) { for (int i = 1; i <= _test.RepeatCount; i++) { RunTestIterationCommand command = new RunTestIterationCommand(this._dispatcher, this._test, this._testFixture, this._type, this.o, this._testFixtureIteration, method, i, testResult); threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); } threadPool.WaitOne(); } } else { for (int i = 1; i <= _test.RepeatCount; i++) { new RunTestIterationCommand(this._dispatcher, this._test, this._testFixture, this._type, this.o, this._testFixtureIteration, method, i, testResult).Execute(); } } } public void Execute(object o){this.Execute();} } } Index: Adapdev.UnitTest.Core.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/Adapdev.UnitTest.Core.csproj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Adapdev.UnitTest.Core.csproj 26 Oct 2005 05:27:45 -0000 1.5 --- Adapdev.UnitTest.Core.csproj 1 Nov 2005 05:41:40 -0000 1.6 *************** *** 182,186 **** /> <File ! RelPath = "RunNonThreadedTestCommand.cs" SubType = "Code" BuildAction = "Compile" --- 182,186 ---- /> <File ! RelPath = "RunTestCommand.cs" SubType = "Code" BuildAction = "Compile" *************** *** 192,196 **** /> <File ! RelPath = "RunThreadedTestCommand.cs" SubType = "Code" BuildAction = "Compile" --- 192,196 ---- /> <File ! RelPath = "RunTestIterationCommand.cs" SubType = "Code" BuildAction = "Compile" Index: RunTestFixtureCommand.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/RunTestFixtureCommand.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RunTestFixtureCommand.cs 26 Oct 2005 05:27:45 -0000 1.1 --- RunTestFixtureCommand.cs 1 Nov 2005 05:41:40 -0000 1.2 *************** *** 96,114 **** if(this._testFixture.IsMultiThreaded) { - // ArrayList threads = new ArrayList(); - // foreach (Test test in this._testFixture.GetTests()) - // { - // RunNonThreadedTestCommand command = new RunNonThreadedTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); - // Thread thread = new Thread(new ThreadStart(command.Execute)); - // threads.Add(thread); - // thread.Start(); - // } - // foreach(Thread t in threads) t.Join(); - using(ThreadPoolWait threadPool = new ThreadPoolWait()) { foreach (Test test in this._testFixture.GetTests()) { ! RunNonThreadedTestCommand command = new RunNonThreadedTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); } --- 96,104 ---- if(this._testFixture.IsMultiThreaded) { using(ThreadPoolWait threadPool = new ThreadPoolWait()) { foreach (Test test in this._testFixture.GetTests()) { ! RunTestCommand command = new RunTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); } *************** *** 120,124 **** foreach (Test test in this._testFixture.GetTests()) { ! new RunNonThreadedTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration).Execute(); } } --- 110,114 ---- foreach (Test test in this._testFixture.GetTests()) { ! new RunTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration).Execute(); } } --- NEW FILE: RunTestIterationCommand.cs --- using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; using Adapdev.Diagnostics; namespace Adapdev.UnitTest.Core { /// <summary> /// Summary description for RunTestIterationCommand. /// </summary> public class RunTestIterationCommand { private TestEventDispatcher _dispatcher = null; private Test _test = null; private TestFixture _testFixture = null; private object o = null; private int i = 0; private Type _type = null; private TestFixtureIteration _testFixtureIteration = null; private MethodInfo _method = null; private IPerfTimer timer = PerfTimerFactory.GetPerfTimer(PerfTimerType.HIRESSECONDS); private TestResult tr = null; public RunTestIterationCommand(TestEventDispatcher dispatcher, Test test, TestFixture tf, Type type, object o, TestFixtureIteration tfi, MethodInfo method, int iteration, TestResult tr) { this._dispatcher = dispatcher; this._test = test; this._testFixture = tf; this.o = o; this.i = iteration; this._type = type; this._testFixtureIteration = tfi; this._method = method; this.tr = tr; } public void Execute() { TextWriter consoleOut = Console.Out; TextWriter errorOut = Console.Error; StringWriter consoleWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); StringWriter debugWriter = new StringWriter(); StringWriter traceWriter = new StringWriter(); Console.SetOut(consoleWriter); Console.SetError(errorWriter); TextWriterTraceListener debug = new TextWriterTraceListener(debugWriter); TextWriterTraceListener error = new TextWriterTraceListener(traceWriter); Debug.Listeners.Add(debug); Trace.Listeners.Add(error); if (_test.RepeatDelay > 0) { Thread.Sleep(_test.RepeatDelay); Console.WriteLine("Sleeping..." + _test.RepeatDelay); } TestIteration ti = new TestIteration(); ti.Name = _test.Name; ti.Iteration = i; ti.Thread = AppDomain.GetCurrentThreadId().ToString(); long kStart = 0; long kEnd = 0; if(_dispatcher != null)_dispatcher.OnTestIterationStarted(new TestEventArgs(_test)); try { this.RunTestSetUps(_dispatcher, _testFixture, _test.Name, o, _type); kStart = Process.GetCurrentProcess().WorkingSet; timer.Start(); new RunMethodCommand(this._method, o).Execute(); timer.Stop(); ti.Duration = timer.Duration; kEnd = Process.GetCurrentProcess().WorkingSet; ti.MemoryUsed = (kEnd - kStart)/1024; if (_test.MaxKMemory > 0 && _test.MaxKMemory < ti.MemoryUsed) { ti.State = TestState.Fail; ti.Result = "Memory usage exceeded MaxK limit of " + _test.MaxKMemory; } else if (_test.MinOperationsPerSecond > 0 && ti.GetOpsPerSecond() < _test.MinOperationsPerSecond) { ti.State = TestState.Fail; ti.Result = "Ops per second was less than minimum limit of " + _test.MinOperationsPerSecond; } else if (_test.ExpectedExceptionType != null && _test.ExpectedExceptionType.Length > 0) { ti.State = TestState.Fail; ti.Result = "ExceptedException type " + _test.ExpectedExceptionType + " was not thrown."; } else { ti.State = TestState.Pass; } this.RunTestTearDowns(_dispatcher, _testFixture, _test.Name, o, _type); } catch (Exception e) { timer.Stop(); ti.Duration = timer.Duration; kEnd = Process.GetCurrentProcess().WorkingSet; if (_test.ExpectedExceptionType != null && _test.ExpectedExceptionType.Length > 0) { Type t = null; foreach(Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { try { t = ass.GetType(_test.ExpectedExceptionType, true, true); break; } catch(Exception){} } if(t == null) throw new TypeLoadException("Unable to locate " + _test.ExpectedExceptionType + ". Please make sure it is correct."); if (e.InnerException.GetType().IsSubclassOf(t) || e.InnerException.GetType() == t) { if(_test.ExpectedExceptionMessage != null && _test.ExpectedExceptionMessage.Length > 0) { if(_test.ExpectedExceptionMessage.ToLower() == e.InnerException.Message.ToLower()) { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ti.State = TestState.Pass; } else { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was thrown, but wrong message. Message: " + e.InnerException.Message + " - Expected: " + _test.ExpectedExceptionMessage; ti.State = TestState.Fail; } } else { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ti.State = TestState.Pass; } } else { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was NOT thrown. Message: " + e.InnerException.Message; ti.State = TestState.Fail; } ti.ExceptionType = e.InnerException.GetType().FullName; ti.FullStackTrace = e.InnerException.StackTrace; ti.MemoryUsed = (kEnd - kStart)/1024; } // TODO : Fix incrementing of tests in GUI when IgnoreException is thrown else if(e.InnerException.GetType() == typeof(IgnoreException) || e.InnerException.GetType() == typeof(IgnoreException)) { ti.Result = e.InnerException.Message; ti.State = TestState.ForcedIgnore; ti.ExceptionType = e.InnerException.GetType().FullName; ti.FullStackTrace = e.InnerException.StackTrace; } else { ti.Result = e.InnerException.Message; ti.ExceptionType = e.InnerException.GetType().FullName; ti.FullStackTrace = e.InnerException.StackTrace; ti.State = TestState.Fail; } this.RunTestTearDowns(_dispatcher, _testFixture, _test.Name, o, _type); } ti.ConsoleOutput = consoleWriter.ToString(); ti.ConsoleError = errorWriter.ToString(); ti.DebugOutput = debugWriter.ToString(); ti.TraceOutput = traceWriter.ToString(); lock(this){tr.AddIteration(ti);} if(_dispatcher != null)_dispatcher.OnTestIterationCompleted(new TestIterationEventArgs(ti)); Console.SetOut(consoleOut); Console.SetError(errorOut); Debug.Listeners.Remove(debug); Trace.Listeners.Remove(error); debug.Dispose(); error.Dispose(); } protected void RunTestSetUps(TestEventDispatcher _dispatcher, TestFixture tf, string name, object instance, Type type) { foreach (TestHelper t in tf.GetTestSetUps()) { try { // Console.WriteLine(t.Method); if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); MethodInfo m = type.GetMethod(t.Method); m.Invoke(instance, null); } } catch (Exception e) { Console.Write(e); } } } protected void RunTestTearDowns(TestEventDispatcher _dispatcher, TestFixture tf, string name, object instance, Type type) { foreach (TestHelper t in tf.GetTestTearDowns()) { try { if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); MethodInfo m = type.GetMethod(t.Method); m.Invoke(instance, null); } } catch (Exception e) { Console.Write(e); } } } public void Execute(object o){this.Execute();} } } |
From: Sean M. <int...@us...> - 2005-11-01 05:41:52
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3474/src/Adapdev.UnitTest.Core.Tests Modified Files: AdapdevLocalTestEngineTest.cs Log Message: Added multi-threading for repeated tests Index: AdapdevLocalTestEngineTest.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.Tests/AdapdevLocalTestEngineTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AdapdevLocalTestEngineTest.cs 26 Oct 2005 05:27:45 -0000 1.2 --- AdapdevLocalTestEngineTest.cs 1 Nov 2005 05:41:40 -0000 1.3 *************** *** 34,41 **** TestAssemblyResult result = engine.Run(engine.GetTestAssembly()); - //Assert.AreEqual(18, result.Passed); - //Assert.AreEqual(2, result.Failed); ! Console.WriteLine(new Adapdev.UnitTest.Core.TextFormatter(new TestAssemblyResult[]{result}).GetText()); } } --- 34,43 ---- TestAssemblyResult result = engine.Run(engine.GetTestAssembly()); ! Console.WriteLine(new Adapdev.UnitTest.Core.TextFormatter(new TestAssemblyResult[]{result}, true, true, true).GetText()); ! ! Assert.AreEqual(20, result.Passed); ! Assert.AreEqual(2, result.Failed); ! } } |
From: Sean M. <int...@us...> - 2005-11-01 05:40:54
|
Update of /cvsroot/adapdev/Adapdev/cvssrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3325/cvssrc Log Message: Directory /cvsroot/adapdev/Adapdev/cvssrc added to the repository |
From: Sean M. <int...@us...> - 2005-10-26 05:28:00
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17136/src/Adapdev.UnitTest Modified Files: Adapdev.UnitTest.csproj RepeatAttribute.cs TestAttribute.cs TestFixtureAttribute.cs Added Files: RollbackTransaction.cs TestContext.cs Transaction.cs Log Message: Added multi-threading support to testing engine Index: TestAttribute.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest/TestAttribute.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TestAttribute.cs 21 Oct 2005 23:42:45 -0000 1.2 --- TestAttribute.cs 26 Oct 2005 05:27:45 -0000 1.3 *************** *** 73,76 **** --- 73,77 ---- set{this._testType = value;} } + } } \ No newline at end of file --- NEW FILE: TestContext.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for TestContext. /// </summary> public class TestContext { public TestContext() { // // TODO: Add constructor logic here // } } } --- NEW FILE: RollbackTransaction.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for RollbackTransaction. /// </summary> /// [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class RollbackTransaction : Attribute { } } Index: Adapdev.UnitTest.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest/Adapdev.UnitTest.csproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Adapdev.UnitTest.csproj 21 Oct 2005 23:42:45 -0000 1.4 --- Adapdev.UnitTest.csproj 26 Oct 2005 05:27:45 -0000 1.5 *************** *** 146,149 **** --- 146,154 ---- /> <File + RelPath = "RollbackTransaction.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "SetUpAttribute.cs" SubType = "Code" *************** *** 161,164 **** --- 166,174 ---- /> <File + RelPath = "TestContext.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TestFixtureAttribute.cs" SubType = "Code" *************** *** 190,193 **** --- 200,208 ---- BuildAction = "Compile" /> + <File + RelPath = "Transaction.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> Index: RepeatAttribute.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest/RepeatAttribute.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** RepeatAttribute.cs 28 Feb 2005 01:32:19 -0000 1.1.1.1 --- RepeatAttribute.cs 26 Oct 2005 05:27:45 -0000 1.2 *************** *** 96,99 **** --- 96,101 ---- delayBetweenReps = delay; } + + } } \ No newline at end of file Index: TestFixtureAttribute.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest/TestFixtureAttribute.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TestFixtureAttribute.cs 28 Feb 2005 01:32:20 -0000 1.1.1.1 --- TestFixtureAttribute.cs 26 Oct 2005 05:27:45 -0000 1.2 *************** *** 62,65 **** --- 62,73 ---- public sealed class TestFixtureAttribute : Attribute { + private bool _multiThreaded = false; + + public bool IsMultiThreaded + { + get { return _multiThreaded; } + set { _multiThreaded = value; } + } + } } \ No newline at end of file --- NEW FILE: Transaction.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for Transaction. /// </summary> /// [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class Transaction : Attribute { } } |
From: Sean M. <int...@us...> - 2005-10-26 05:28:00
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17136/src/Adapdev.UnitTest.Core Modified Files: AbstractTest.cs Adapdev.UnitTest.Core.csproj Adapdev.UnitTest.Core.csproj.user TestRunner.cs TestSuiteBuilder.cs TextFormatter.cs Added Files: RunMethodCommand.cs RunNonThreadedTestCommand.cs RunTestFixtureCommand.cs RunThreadedTestCommand.cs Log Message: Added multi-threading support to testing engine Index: TestSuiteBuilder.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestSuiteBuilder.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TestSuiteBuilder.cs 23 Oct 2005 07:27:20 -0000 1.9 --- TestSuiteBuilder.cs 26 Oct 2005 05:27:45 -0000 1.10 *************** *** 143,146 **** --- 143,153 ---- tf.FullName = t.FullName; + if (TypeHelper.HasCustomAttribute(t, typeof (Adapdev.UnitTest.TestFixtureAttribute))) + { + Adapdev.UnitTest.TestFixtureAttribute tfa = (Adapdev.UnitTest.TestFixtureAttribute) TypeHelper.GetFirstCustomAttribute(t, typeof (Adapdev.UnitTest.TestFixtureAttribute)); + tf.IsMultiThreaded = tfa.IsMultiThreaded; + } + + this.ProcessCommonAttributes(t, tf); --- NEW FILE: RunMethodCommand.cs --- using System; using System.Reflection; using Adapdev.Commands; namespace Adapdev.UnitTest.Core { /// <summary> /// Summary description for RunMethodCommand. /// </summary> public class RunMethodCommand : ICommand { private MethodInfo _method = null; private object _o = null; public RunMethodCommand(MethodInfo method, object o) { this._method = method; this._o = o; } public void Execute() { this._method.Invoke(this._o, null); } } } Index: AbstractTest.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/AbstractTest.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractTest.cs 5 Jun 2005 08:50:31 -0000 1.3 --- AbstractTest.cs 26 Oct 2005 05:27:45 -0000 1.4 *************** *** 60,63 **** --- 60,65 ---- protected string _fullName = String.Empty; private static int _globalid = 0; + private bool _isMultiThreaded = false; + public AbstractTest() *************** *** 160,163 **** --- 162,171 ---- } + public bool IsMultiThreaded + { + get { return _isMultiThreaded; } + set { _isMultiThreaded = value; } + } + public abstract int GetTestCount(); } Index: Adapdev.UnitTest.Core.csproj.user =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/Adapdev.UnitTest.Core.csproj.user,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Adapdev.UnitTest.Core.csproj.user 21 Oct 2005 04:59:20 -0000 1.3 --- Adapdev.UnitTest.Core.csproj.user 26 Oct 2005 05:27:45 -0000 1.4 *************** *** 41,45 **** CopyProjectUncPath = "" CopyProjectOption = "0" ! ProjectView = "ProjectFiles" ProjectTrust = "0" /> --- 41,45 ---- CopyProjectUncPath = "" CopyProjectOption = "0" ! ProjectView = "ShowAllFiles" ProjectTrust = "0" /> --- NEW FILE: RunTestFixtureCommand.cs --- using System; using System.Collections; using System.Reflection; using System.Threading; using Adapdev.Commands; using Adapdev.Threading; namespace Adapdev.UnitTest.Core { /// <summary> /// Summary description for TestFixtureCommand. /// </summary> public class RunTestFixtureCommand : ICommand { private TestEventDispatcher _dispatcher = null; private TestFixture _testFixture = null; private Assembly _assembly = null; private string _className = String.Empty; private TestFixtureResult _testFixtureResult = null; private TestFixtureIteration _testFixtureIteration = null; private Type _type = null; private object _o = null; public RunTestFixtureCommand(TestEventDispatcher dispatcher, TestFixture tf, Assembly assembly, string className, TestFixtureResult testFixtureResult) { this._dispatcher = dispatcher; this._testFixture = tf; this._assembly = assembly; this._className = className; this._testFixtureResult = testFixtureResult; } public void Execute() { if(_dispatcher != null)_dispatcher.OnTestFixtureStarted(new TestFixtureEventArgs(this._testFixture)); for (int j = 1; j <= this._testFixture.RepeatCount; j++) { this._type = null; this._testFixtureIteration = null; if (this._testFixture.RepeatDelay > 0) Thread.Sleep(this._testFixture.RepeatDelay); this._testFixtureIteration = new TestFixtureIteration(); if(_dispatcher != null)this._dispatcher.OnTestFixtureIterationStarted(new TestFixtureEventArgs(this._testFixture)); this._o = this._assembly.CreateInstance(this._className); this._type = this._assembly.GetType(this._className, true); this.RunTestFixtureSetUps(this._testFixture, this._o, this._type); RunTests(); this.RunTestFixtureTearDowns(this._testFixture, this._o, this._type); this._testFixtureIteration.Iteration = j; this._testFixtureResult.AddIteration(this._testFixtureIteration); if(_dispatcher != null)_dispatcher.OnTestFixtureIterationCompleted(new TestFixtureIterationEventArgs(this._testFixtureIteration)); } if(_dispatcher != null)_dispatcher.OnTestFixtureCompleted(new TestFixtureResultEventArgs(this._testFixtureResult)); } protected void RunTestFixtureSetUps(TestFixture tf, object instance, Type type) { foreach (BaseTestHelper t in tf.GetFixtureSetUps()) { try { if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); MethodInfo m = type.GetMethod(t.Method); m.Invoke(instance, null); } catch (Exception e) { Console.Write(e); } } } protected void RunTestFixtureTearDowns(TestFixture tf, object instance, Type type) { foreach (BaseTestHelper t in tf.GetFixtureTearDowns()) { try { if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); MethodInfo m = type.GetMethod(t.Method); m.Invoke(instance, null); } catch (Exception e) { Console.Write(e); } } } private void RunTests() { if(this._testFixture.IsMultiThreaded) { // ArrayList threads = new ArrayList(); // foreach (Test test in this._testFixture.GetTests()) // { // RunNonThreadedTestCommand command = new RunNonThreadedTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); // Thread thread = new Thread(new ThreadStart(command.Execute)); // threads.Add(thread); // thread.Start(); // } // foreach(Thread t in threads) t.Join(); using(ThreadPoolWait threadPool = new ThreadPoolWait()) { foreach (Test test in this._testFixture.GetTests()) { RunNonThreadedTestCommand command = new RunNonThreadedTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration); threadPool.QueueUserWorkItem(new WaitCallback(command.Execute)); } threadPool.WaitOne(); } } else { foreach (Test test in this._testFixture.GetTests()) { new RunNonThreadedTestCommand(this._dispatcher, test, this._testFixture, this._type, this._o, this._testFixtureIteration).Execute(); } } } } } --- NEW FILE: RunThreadedTestCommand.cs --- using System; using System.Reflection; using System.Threading; using Adapdev.Commands; namespace Adapdev.UnitTest.Core { /// <summary> /// Summary description for ThreadedRunTestCommand. /// </summary> public class RunThreadedTestCommand : ICommand { private TestEventDispatcher _dispatcher = null; private Test _test = null; private TestFixture _testFixture = null; private Type _type = null; private object o = null; private TestFixtureIteration _testFixtureIteration = null; private Thread _running = null; public RunThreadedTestCommand(TestEventDispatcher dispatcher, Test test, TestFixture tf, Type type, object o, TestFixtureIteration tfi) { this._dispatcher = dispatcher; this._test = test; this._testFixture = tf; this.o = o; this._testFixtureIteration = tfi; this._type = type; } public void Execute() { Thread thread = new Thread(new ThreadStart(Run)); thread.Priority = ThreadPriority.AboveNormal; this._running = thread; thread.Start(); } public Thread TestThread { get{return this._running;} } private void Run() { new RunNonThreadedTestCommand(this._dispatcher, this._test, this._testFixture, this._type, this.o, this._testFixtureIteration).Execute(); } } } Index: Adapdev.UnitTest.Core.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/Adapdev.UnitTest.Core.csproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Adapdev.UnitTest.Core.csproj 23 Oct 2005 07:27:20 -0000 1.4 --- Adapdev.UnitTest.Core.csproj 26 Oct 2005 05:27:45 -0000 1.5 *************** *** 177,180 **** --- 177,200 ---- /> <File + RelPath = "RunMethodCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "RunNonThreadedTestCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "RunTestFixtureCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "RunThreadedTestCommand.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Test.cs" SubType = "Code" Index: TestRunner.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestRunner.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TestRunner.cs 22 Oct 2005 17:15:38 -0000 1.8 --- TestRunner.cs 26 Oct 2005 05:27:45 -0000 1.9 *************** *** 65,71 **** private bool _infoMode = log.IsInfoEnabled; - /// <summary> - /// The list of assemblies to load - /// </summary> private IPerfTimer timer = PerfTimerFactory.GetPerfTimer(PerfTimerType.HIRESSECONDS); --- 65,68 ---- *************** *** 174,381 **** if(this._debugMode) log.Debug("Running TF " + tf.Name); ! if(_dispatcher != null)_dispatcher.OnTestFixtureStarted(new TestFixtureEventArgs(tf)); ! for (int j = 1; j <= tf.RepeatCount; j++) ! { ! if (tf.RepeatDelay > 0) Thread.Sleep(tf.RepeatDelay); ! TestFixtureIteration tfi = new TestFixtureIteration(); ! if(_dispatcher != null)this._dispatcher.OnTestFixtureIterationStarted(new TestFixtureEventArgs(tf)); ! ! o = a.CreateInstance(classname); ! Type type = a.GetType(classname, true); ! ! this.RunTestFixtureSetUps(tf, o, type); ! ! foreach (Test test in tf.GetTests()) ! { ! try ! { ! MethodInfo m = type.GetMethod(test.Method); ! TestResult tr = new TestResult(test); ! tr.TestId = test.Id; ! tr.Description = test.Description; ! ! if(this._debugMode) log.Debug("Running T " + test.Name); ! ! if (!test.Ignore && test.ShouldRun) ! { ! ! if(_dispatcher != null)_dispatcher.OnTestStarted(new TestEventArgs(test)); ! for (int i = 1; i <= test.RepeatCount; i++) ! { ! ! TextWriter consoleOut = Console.Out; ! TextWriter errorOut = Console.Error; ! StringWriter consoleWriter = new StringWriter(); ! StringWriter errorWriter = new StringWriter(); ! StringWriter debugWriter = new StringWriter(); ! StringWriter traceWriter = new StringWriter(); ! ! Console.SetOut(consoleWriter); ! Console.SetError(errorWriter); ! TextWriterTraceListener debug = new TextWriterTraceListener(debugWriter); ! TextWriterTraceListener error = new TextWriterTraceListener(traceWriter); ! Debug.Listeners.Add(debug); ! Trace.Listeners.Add(error); ! ! ! if (test.RepeatDelay > 0) ! { ! Thread.Sleep(test.RepeatDelay); ! Console.WriteLine("Sleeping..." + test.RepeatDelay); ! } ! TestIteration ti = new TestIteration(); ! ti.Name = test.Name; ! ti.Iteration = i; ! ti.Thread = AppDomain.GetCurrentThreadId().ToString(); ! long kStart = 0; ! long kEnd = 0; ! if(_dispatcher != null)this._dispatcher.OnTestIterationStarted(new TestEventArgs(test)); ! ! try ! { ! this.RunTestSetUps(tf, test.Name, o, type); ! kStart = Process.GetCurrentProcess().WorkingSet; ! timer.Start(); ! m.Invoke(o, null); ! timer.Stop(); ! ti.Duration = timer.Duration; ! kEnd = Process.GetCurrentProcess().WorkingSet; ! ti.MemoryUsed = (kEnd - kStart)/1024; ! ! if (test.MaxKMemory > 0 && test.MaxKMemory < ti.MemoryUsed) ! { ! ti.State = TestState.Fail; ! ti.Result = "Memory usage exceeded MaxK limit of " + test.MaxKMemory; ! } ! else if (test.MinOperationsPerSecond > 0 && ti.GetOpsPerSecond() < test.MinOperationsPerSecond) ! { ! ti.State = TestState.Fail; ! ti.Result = "Ops per second was less than minimum limit of " + test.MinOperationsPerSecond; ! } ! else if (test.ExpectedExceptionType != null && test.ExpectedExceptionType.Length > 0) ! { ! ti.State = TestState.Fail; ! ti.Result = "ExceptedException type " + test.ExpectedExceptionType + " was not thrown."; ! } ! else ! { ! ti.State = TestState.Pass; ! } ! ! this.RunTestTearDowns(tf, test.Name, o, type); ! } ! catch (Exception e) ! { ! timer.Stop(); ! ti.Duration = timer.Duration; ! kEnd = Process.GetCurrentProcess().WorkingSet; ! if (test.ExpectedExceptionType != null && test.ExpectedExceptionType.Length > 0) ! { ! Type t = null; ! foreach(Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) ! { ! try ! { ! t = ass.GetType(test.ExpectedExceptionType, true, true); ! break; ! } ! catch(Exception){} ! } ! ! if(t == null) throw new TypeLoadException("Unable to locate " + test.ExpectedExceptionType + ". Please make sure it is correct."); ! if (e.InnerException.GetType().IsSubclassOf(t) || e.InnerException.GetType() == t) ! { ! if(test.ExpectedExceptionMessage != null && test.ExpectedExceptionMessage.Length > 0) ! { ! if(test.ExpectedExceptionMessage.ToLower() == e.InnerException.Message.ToLower()) ! { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Pass; ! } ! else ! { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown, but wrong message. Message: " + e.InnerException.Message + " - Expected: " + test.ExpectedExceptionMessage; ! ti.State = TestState.Fail; ! } ! } ! else ! { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Pass; ! } ! } ! else ! { ! ti.Result = "Expected Exception: " + test.ExpectedExceptionType + " was NOT thrown. Message: " + e.InnerException.Message; ! ti.State = TestState.Fail; ! } ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ! ti.MemoryUsed = (kEnd - kStart)/1024; ! ! } ! // TODO : Fix incrementing of tests in GUI when IgnoreException is thrown ! else if(e.InnerException.GetType() == typeof(IgnoreException) || e.InnerException.GetType() == typeof(IgnoreException)) ! { ! ti.Result = e.InnerException.Message; ! ti.State = TestState.ForcedIgnore; ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ! } ! else ! { ! ti.Result = e.InnerException.Message; ! ti.ExceptionType = e.InnerException.GetType().FullName; ! ti.FullStackTrace = e.InnerException.StackTrace; ! ti.State = TestState.Fail; ! } ! this.RunTestTearDowns(tf, test.Name, o, type); ! } ! ! ti.ConsoleOutput = consoleWriter.ToString(); ! ti.ConsoleError = errorWriter.ToString(); ! ti.DebugOutput = debugWriter.ToString(); ! ti.TraceOutput = traceWriter.ToString(); ! ! tr.AddIteration(ti); ! if(_dispatcher != null)_dispatcher.OnTestIterationCompleted(new TestIterationEventArgs(ti)); ! ! Console.SetOut(consoleOut); ! Console.SetError(errorOut); ! Debug.Listeners.Remove(debug); ! Trace.Listeners.Remove(error); ! ! debug.Dispose(); ! error.Dispose(); ! } ! ! } ! else ! { ! TestIteration ti = new TestIteration(); ! ti.Name = test.Name; ! ti.State = TestState.Ignore; ! ti.Result = test.IgnoreReason; ! tr.AddIteration(ti); ! } ! ! if (tf.ShouldShow) tfi.AddTestResult(tr); ! if(_dispatcher != null)_dispatcher.OnTestCompleted(new TestResultEventArgs(tr)); ! } ! catch (Exception e) ! { ! Console.WriteLine(e.Message + " " + e.StackTrace); ! } ! finally ! { ! } ! } ! ! this.RunTestFixtureTearDowns(tf, o, type); ! tfi.Iteration = j; ! testFixtureResult.AddIteration(tfi); ! if(_dispatcher != null)_dispatcher.OnTestFixtureIterationCompleted(new TestFixtureIterationEventArgs(tfi)); ! } ! if(_dispatcher != null)_dispatcher.OnTestFixtureCompleted(new TestFixtureResultEventArgs(testFixtureResult)); } catch (Exception e) --- 171,175 ---- if(this._debugMode) log.Debug("Running TF " + tf.Name); ! RunTestFixture(tf, a, classname, testFixtureResult); } catch (Exception e) *************** *** 386,395 **** } ! // Not currently used...but meant to be for multi-threaded tests ! public double ThreadedTestRunner(MethodInfo method, object o) { ! IPerfTimer t = PerfTimerFactory.GetPerfTimer(PerfTimerType.HIRESSECONDS); ! method.Invoke(o, null); ! return 0.00; } --- 180,186 ---- } ! private void RunTestFixture(TestFixture tf, Assembly a, string classname, TestFixtureResult testFixtureResult) { ! new RunTestFixtureCommand(this._dispatcher, tf, a, classname, testFixtureResult).Execute(); } *************** *** 399,476 **** } - protected void RunTestFixtureSetUps(TestFixture tf, object instance, Type type) - { - foreach (BaseTestHelper t in tf.GetFixtureSetUps()) - { - try - { - if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); - MethodInfo m = type.GetMethod(t.Method); - m.Invoke(instance, null); - } - catch (Exception e) - { - Console.Write(e); - } - } - } - - protected void RunTestFixtureTearDowns(TestFixture tf, object instance, Type type) - { - foreach (BaseTestHelper t in tf.GetFixtureTearDowns()) - { - try - { - if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); - MethodInfo m = type.GetMethod(t.Method); - m.Invoke(instance, null); - } - catch (Exception e) - { - Console.Write(e); - } - } - } - - protected void RunTestSetUps(TestFixture tf, string name, object instance, Type type) - { - foreach (TestHelper t in tf.GetTestSetUps()) - { - try - { - // Console.WriteLine(t.Method); - if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) - { - if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); - MethodInfo m = type.GetMethod(t.Method); - m.Invoke(instance, null); - } - } - catch (Exception e) - { - Console.Write(e); - } - } - } - protected void RunTestTearDowns(TestFixture tf, string name, object instance, Type type) - { - foreach (TestHelper t in tf.GetTestTearDowns()) - { - try - { - if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) - { - if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); - MethodInfo m = type.GetMethod(t.Method); - m.Invoke(instance, null); - } - } - catch (Exception e) - { - Console.Write(e); - } - } - } public void SetConsole(TextWriter tw) --- 190,194 ---- Index: TextFormatter.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TextFormatter.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TextFormatter.cs 22 Oct 2005 17:15:38 -0000 1.6 --- TextFormatter.cs 26 Oct 2005 05:27:45 -0000 1.7 *************** *** 88,92 **** sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "{0} - {1}\r\n", tar.Name, tar.State); //sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "Time: {0}s\r\n", tar.GetTotalDuration()); ! if((tar is TestResult) && ((tar as TestResult).Description.Length > 0)) sb.AppendFormat(this.GetNesting(nesting + 2) + "Description: {0}\r\n", (tar as TestResult).Description); if(showFailure && (ati is TestIteration)) --- 88,95 ---- sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "{0} - {1}\r\n", tar.Name, tar.State); //sb.AppendFormat(this.GetNesting(nesting + 1) + this.GetMarker(tar) + "Time: {0}s\r\n", tar.GetTotalDuration()); ! if((tar is TestResult) && ((tar as TestResult).Description.Length > 0)) ! { ! sb.AppendFormat(this.GetNesting(nesting + 2) + "Description: {0}\r\n", (tar as TestResult).Description); ! } if(showFailure && (ati is TestIteration)) *************** *** 97,100 **** --- 100,109 ---- } + if(ati is TestIteration) + { + sb.Append(this.GetNesting(nesting + 2) + "Thread Id: " + (ati as TestIteration).Thread + Environment.NewLine); + sb.Append(this.GetNesting(nesting + 2) + "Time: " + (ati as TestIteration).Duration + Environment.NewLine); + } + if(showOutput && ati.ConsoleOutput.Length > 0) { --- NEW FILE: RunNonThreadedTestCommand.cs --- using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; using Adapdev.Commands; using Adapdev.Diagnostics; using log4net; namespace Adapdev.UnitTest.Core { /// <summary> /// Summary description for NonThreadedRunTestCommand. /// </summary> public class RunNonThreadedTestCommand : ICommand { private MethodInfo _method = null; private object _o = null; // create the logger private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // setup the logging levels private bool _debugMode = log.IsDebugEnabled; private bool _infoMode = log.IsInfoEnabled; private IPerfTimer timer = PerfTimerFactory.GetPerfTimer(PerfTimerType.HIRESSECONDS); private TestEventDispatcher _dispatcher = null; private Test _test = null; private TestFixture _testFixture = null; private Type _type = null; private object o = null; private TestFixtureIteration _testFixtureIteration = null; public RunNonThreadedTestCommand(TestEventDispatcher dispatcher, Test test, TestFixture tf, Type type, object o, TestFixtureIteration tfi) { this._dispatcher = dispatcher; this._test = test; this._testFixture = tf; this.o = o; this._testFixtureIteration = tfi; this._type = type; } public void Execute() { try { MethodInfo m = _type.GetMethod(_test.Method); TestResult tr = new TestResult(_test); tr.TestId = _test.Id; tr.Description = _test.Description; if(this._debugMode) log.Debug("Running T " + _test.Name); if (!_test.Ignore && _test.ShouldRun) { if(_dispatcher != null)_dispatcher.OnTestStarted(new TestEventArgs(_test)); for (int i = 1; i <= _test.RepeatCount; i++) { TextWriter consoleOut = Console.Out; TextWriter errorOut = Console.Error; StringWriter consoleWriter = new StringWriter(); StringWriter errorWriter = new StringWriter(); StringWriter debugWriter = new StringWriter(); StringWriter traceWriter = new StringWriter(); //Console.SetOut(consoleWriter); Console.SetError(errorWriter); TextWriterTraceListener debug = new TextWriterTraceListener(debugWriter); TextWriterTraceListener error = new TextWriterTraceListener(traceWriter); Debug.Listeners.Add(debug); Trace.Listeners.Add(error); if (_test.RepeatDelay > 0) { Thread.Sleep(_test.RepeatDelay); Console.WriteLine("Sleeping..." + _test.RepeatDelay); } TestIteration ti = new TestIteration(); ti.Name = _test.Name; ti.Iteration = i; ti.Thread = AppDomain.GetCurrentThreadId().ToString(); long kStart = 0; long kEnd = 0; if(_dispatcher != null)_dispatcher.OnTestIterationStarted(new TestEventArgs(_test)); try { this.RunTestSetUps(_dispatcher, _testFixture, _test.Name, o, _type); kStart = Process.GetCurrentProcess().WorkingSet; timer.Start(); new RunMethodCommand(m, o).Execute(); timer.Stop(); ti.Duration = timer.Duration; kEnd = Process.GetCurrentProcess().WorkingSet; ti.MemoryUsed = (kEnd - kStart)/1024; if (_test.MaxKMemory > 0 && _test.MaxKMemory < ti.MemoryUsed) { ti.State = TestState.Fail; ti.Result = "Memory usage exceeded MaxK limit of " + _test.MaxKMemory; } else if (_test.MinOperationsPerSecond > 0 && ti.GetOpsPerSecond() < _test.MinOperationsPerSecond) { ti.State = TestState.Fail; ti.Result = "Ops per second was less than minimum limit of " + _test.MinOperationsPerSecond; } else if (_test.ExpectedExceptionType != null && _test.ExpectedExceptionType.Length > 0) { ti.State = TestState.Fail; ti.Result = "ExceptedException type " + _test.ExpectedExceptionType + " was not thrown."; } else { ti.State = TestState.Pass; } this.RunTestTearDowns(_dispatcher, _testFixture, _test.Name, o, _type); } catch (Exception e) { timer.Stop(); ti.Duration = timer.Duration; kEnd = Process.GetCurrentProcess().WorkingSet; if (_test.ExpectedExceptionType != null && _test.ExpectedExceptionType.Length > 0) { Type t = null; foreach(Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { try { t = ass.GetType(_test.ExpectedExceptionType, true, true); break; } catch(Exception){} } if(t == null) throw new TypeLoadException("Unable to locate " + _test.ExpectedExceptionType + ". Please make sure it is correct."); if (e.InnerException.GetType().IsSubclassOf(t) || e.InnerException.GetType() == t) { if(_test.ExpectedExceptionMessage != null && _test.ExpectedExceptionMessage.Length > 0) { if(_test.ExpectedExceptionMessage.ToLower() == e.InnerException.Message.ToLower()) { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ti.State = TestState.Pass; } else { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was thrown, but wrong message. Message: " + e.InnerException.Message + " - Expected: " + _test.ExpectedExceptionMessage; ti.State = TestState.Fail; } } else { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was thrown. Message: " + e.InnerException.Message; ti.State = TestState.Pass; } } else { ti.Result = "Expected Exception: " + _test.ExpectedExceptionType + " was NOT thrown. Message: " + e.InnerException.Message; ti.State = TestState.Fail; } ti.ExceptionType = e.InnerException.GetType().FullName; ti.FullStackTrace = e.InnerException.StackTrace; ti.MemoryUsed = (kEnd - kStart)/1024; } // TODO : Fix incrementing of tests in GUI when IgnoreException is thrown else if(e.InnerException.GetType() == typeof(IgnoreException) || e.InnerException.GetType() == typeof(IgnoreException)) { ti.Result = e.InnerException.Message; ti.State = TestState.ForcedIgnore; ti.ExceptionType = e.InnerException.GetType().FullName; ti.FullStackTrace = e.InnerException.StackTrace; } else { ti.Result = e.InnerException.Message; ti.ExceptionType = e.InnerException.GetType().FullName; ti.FullStackTrace = e.InnerException.StackTrace; ti.State = TestState.Fail; } this.RunTestTearDowns(_dispatcher, _testFixture, _test.Name, o, _type); } ti.ConsoleOutput = consoleWriter.ToString(); ti.ConsoleError = errorWriter.ToString(); ti.DebugOutput = debugWriter.ToString(); ti.TraceOutput = traceWriter.ToString(); lock(this){tr.AddIteration(ti);} if(_dispatcher != null)_dispatcher.OnTestIterationCompleted(new TestIterationEventArgs(ti)); Console.SetOut(consoleOut); Console.SetError(errorOut); Debug.Listeners.Remove(debug); Trace.Listeners.Remove(error); debug.Dispose(); error.Dispose(); } } else { TestIteration ti = new TestIteration(); ti.Name = _test.Name; ti.State = TestState.Ignore; ti.Result = _test.IgnoreReason; tr.AddIteration(ti); } if (_testFixture.ShouldShow) _testFixtureIteration.AddTestResult(tr); if(_dispatcher != null)_dispatcher.OnTestCompleted(new TestResultEventArgs(tr)); } catch (Exception e) { Console.WriteLine(e.Message + " " + e.StackTrace); } finally { } } protected void RunTestSetUps(TestEventDispatcher _dispatcher, TestFixture tf, string name, object instance, Type type) { foreach (TestHelper t in tf.GetTestSetUps()) { try { // Console.WriteLine(t.Method); if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); MethodInfo m = type.GetMethod(t.Method); m.Invoke(instance, null); } } catch (Exception e) { Console.Write(e); } } } protected void RunTestTearDowns(TestEventDispatcher _dispatcher, TestFixture tf, string name, object instance, Type type) { foreach (TestHelper t in tf.GetTestTearDowns()) { try { if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { if(_dispatcher != null)_dispatcher.OnBaseTestHelperStarted(new BaseTestHelperEventArgs(t)); MethodInfo m = type.GetMethod(t.Method); m.Invoke(instance, null); } } catch (Exception e) { Console.Write(e); } } } public void Execute(object o){this.Execute();} } } |
From: Sean M. <int...@us...> - 2005-10-26 05:28:00
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev/Threading In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17136/src/Adapdev/Threading Added Files: ThreadPoolWait.cs Log Message: Added multi-threading support to testing engine --- NEW FILE: ThreadPoolWait.cs --- // Stephen Toub // st...@mi... // http://msdn.microsoft.com/msdnmag/issues/04/10/NETMatters/ using System; using System.Threading; using System.Collections; namespace Adapdev.Threading { /// <summary>ThreadPool utility class that allows for easily waiting on queued delegates.</summary> public class ThreadPoolWait : IDisposable { /// <summary>Number of items remaining to be executed.</summary> private int _remainingWorkItems = 1; /// <summary>Event that signals whether all items have been executed.</summary> private ManualResetEvent _done = new ManualResetEvent(false); /// <summary>Queues a user work item to the ThreadPool.</summary> /// <param name="callback">The work item to be queued.</param> public void QueueUserWorkItem(WaitCallback callback) { QueueUserWorkItem(callback, null); } /// <summary>Queues a user work item to the ThreadPool.</summary> /// <param name="callback">The work item to be queued.</param> /// <param name="state">State to be passed to the queued work item</param> public void QueueUserWorkItem(WaitCallback callback, object state) { ThrowIfDisposed(); QueuedCallback qc = new QueuedCallback(); qc.Callback = callback; qc.State = state; Interlocked.Increment(ref _remainingWorkItems); ThreadPool.QueueUserWorkItem(new WaitCallback(HandleWorkItem), qc); } /// <summary>Wait for all items to finish executing.</summary> public bool WaitOne() { return WaitOne(-1, false); } /// <summary>Wait for all items to finish executing.</summary> public bool WaitOne(TimeSpan timeout, bool exitContext) { return WaitOne((int)timeout.TotalMilliseconds, exitContext); } /// <summary>Wait for all items to finish executing.</summary> public bool WaitOne(int millisecondsTimeout, bool exitContext) { ThrowIfDisposed(); DoneWorkItem(); bool rv = _done.WaitOne(millisecondsTimeout, exitContext); // If the event is set, then we'll return true, but first // reset so that this instance can be used again. If the // event isn't set, put back the 1 unit removed by calling // DoneWorkItem. The next time WaitOne is called, // this unit will be removed by the call to DoneWorkItem. if (rv) { _remainingWorkItems = 1; _done.Reset(); } else Interlocked.Increment(ref _remainingWorkItems); return rv; } /// <summary>Executes the callback passed as state and signals its completion when it has finished executing.</summary> /// <param name="state"></param> private void HandleWorkItem(object state) { QueuedCallback qc = (QueuedCallback)state; try { qc.Callback(qc.State); } finally { DoneWorkItem(); } } /// <summary>Decrements the number of remaining items, signaling the ManualResetEvent if 0 are left.</summary> private void DoneWorkItem() { if (Interlocked.Decrement(ref _remainingWorkItems) == 0) _done.Set(); } /// <summary>State class that wraps a WaitCallback and the state object to be passed to it.</summary> private class QueuedCallback { /// <summary>A callback delegate queued to the ThreadPool.</summary> public WaitCallback Callback; /// <summary>The state to be passed to the callback.</summary> public object State; } /// <summary>Throws an exception if this instance has already been disposed.</summary> private void ThrowIfDisposed() { if (_done == null) throw new ObjectDisposedException(GetType().Name); } /// <summary>Disposes this ThreadPoolWait.</summary> public void Dispose() { if (_done != null) { ((IDisposable)_done).Dispose(); _done = null; } } } } |
From: Sean M. <int...@us...> - 2005-10-26 05:28:00
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17136/src/Adapdev.UnitTest.Core.Tests Modified Files: AdapdevLocalTestEngineTest.cs Log Message: Added multi-threading support to testing engine Index: AdapdevLocalTestEngineTest.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.Tests/AdapdevLocalTestEngineTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AdapdevLocalTestEngineTest.cs 23 Oct 2005 07:27:20 -0000 1.1 --- AdapdevLocalTestEngineTest.cs 26 Oct 2005 05:27:45 -0000 1.2 *************** *** 34,39 **** TestAssemblyResult result = engine.Run(engine.GetTestAssembly()); ! Assert.AreEqual(13, result.Passed); ! Assert.AreEqual(2, result.Failed); } } --- 34,41 ---- TestAssemblyResult result = engine.Run(engine.GetTestAssembly()); ! //Assert.AreEqual(18, result.Passed); ! //Assert.AreEqual(2, result.Failed); ! ! Console.WriteLine(new Adapdev.UnitTest.Core.TextFormatter(new TestAssemblyResult[]{result}).GetText()); } } |
From: Sean M. <int...@us...> - 2005-10-26 05:28:00
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17136/src/Adapdev Modified Files: Adapdev.csproj Log Message: Added multi-threading support to testing engine Index: Adapdev.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev/Adapdev.csproj,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Adapdev.csproj 1 Aug 2005 21:04:47 -0000 1.9 --- Adapdev.csproj 26 Oct 2005 05:27:45 -0000 1.10 *************** *** 566,569 **** --- 566,574 ---- /> <File + RelPath = "Threading\ThreadPoolWait.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Transactions\TransactionScope.cs" SubType = "Code" |
From: Sean M. <int...@us...> - 2005-10-26 05:27:59
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17136/src/Adapdev.UnitTest.Core.AdapdevTests Modified Files: Adapdev.UnitTest.Core.AdapdevTests.csproj AdapdevAttributes.cs Added Files: MultiThreadedTest.cs Log Message: Added multi-threading support to testing engine --- NEW FILE: MultiThreadedTest.cs --- using System; using System.Threading; using Adapdev.UnitTest; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for MultiThreadedTest. /// </summary> /// [TestFixture(IsMultiThreaded=true)] public class MultiThreadedTest { int i = 0; [Test] public void Thread1() { i = 0; int a = 0; while(a <= 10) { i += 4; Console.WriteLine("Thread1: " + i.ToString()); Thread.Sleep(5); a++; } Console.WriteLine("Thread1: " + i.ToString()); Assert.IsFalse(i==44, "i equals 44, which means it was not interrupted by Thread2."); } [Test] public void Thread2() { i = 0; int a = 0; while(a <= 10) { i += 10; Console.WriteLine("Thread2: " + i.ToString()); Thread.Sleep(5); a++; } Console.WriteLine("Thread2: " + i.ToString()); Assert.IsFalse(i==110, "i equals 110, which means it was not interrupted by Thread1."); } } } Index: Adapdev.UnitTest.Core.AdapdevTests.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests/Adapdev.UnitTest.Core.AdapdevTests.csproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Adapdev.UnitTest.Core.AdapdevTests.csproj 23 Oct 2005 07:27:21 -0000 1.1 --- Adapdev.UnitTest.Core.AdapdevTests.csproj 26 Oct 2005 05:27:45 -0000 1.2 *************** *** 77,81 **** <Reference Name = "System.XML" ! AssemblyName = "System.XML" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> --- 77,81 ---- <Reference Name = "System.XML" ! AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> *************** *** 99,102 **** --- 99,107 ---- BuildAction = "Compile" /> + <File + RelPath = "MultiThreadedTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> Index: AdapdevAttributes.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests/AdapdevAttributes.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AdapdevAttributes.cs 23 Oct 2005 07:27:21 -0000 1.1 --- AdapdevAttributes.cs 26 Oct 2005 05:27:45 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Threading; using Adapdev.UnitTest; *************** *** 64,67 **** --- 65,69 ---- { Console.WriteLine("Test with description"); + Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); } *************** *** 156,159 **** --- 158,162 ---- { Console.WriteLine("Repeat"); + Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); } *************** *** 166,169 **** --- 169,182 ---- { Console.WriteLine("Repeat with delay"); + Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); + } + + // A Test that is repeated a set number of times on multiple threads + [Test(Description="A Test that is repeated 5X, with a 3 second delay between each run.")] + [Repeat(5)] + public void MultiThreadedRepeat() + { + Console.WriteLine("Repeat with delay"); + Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); } |
From: Sean M. <int...@us...> - 2005-10-23 07:32:42
|
Update of /cvsroot/adapdev/Adapdev/lib/nunit/222 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26768/lib/nunit/222 Added Files: mock-assembly.dll nonamespace-assembly.dll notestfixtures-assembly.dll nunit.core.dll nunit.extensions.dll nunit.framework.dll nunit.framework.tests.dll nunit.framework.tests.dll.config nunit.mocks.dll nunit.testutilities.dll nunit.util.dll Log Message: Revised nunit \lib hierarchy so that its more maintainable --- NEW FILE: notestfixtures-assembly.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.framework.tests.dll.config --- <?xml version="1.0" encoding="utf-8" ?> <configuration> <!-- This is the configuration file for the NUnitTests.nunit test project. You may need to create a similar configuration file for your own test project. In your own configuration file, the include any appSettings that you require. The <NUnit> section is only needed if you want to use a non-default value for any of the settings. --> <configSections> <sectionGroup name="NUnit"> <section name="TestCaseBuilder" type="System.Configuration.NameValueSectionHandler"/> <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/> </sectionGroup> </configSections> <appSettings> <!-- User application and configured property settings go here.--> <!-- Example: <add key="settingName" value="settingValue"/> --> <add key="test.setting" value="54321" /> </appSettings> <NUnit> <TestCaseBuilder> <!-- Set to true to recognize old style test cases starting with "Test..." --> <add key="OldStyleTestCases" value="false" /> </TestCaseBuilder> <TestRunner> <!-- Valid values are STA,MTA. Others ignored. --> <add key="ApartmentState" value="MTA" /> <!-- See ThreadPriority enum for other valid values --> <add key="ThreadPriority" value="Normal" /> </TestRunner> </NUnit> <!-- The following <runtime> section allows running nunit tests under .NET 1.0 by redirecting assemblies. The appliesTo attribute causes the section to be ignored except under .NET 1.0. --> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705"> <dependentAssembly> <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Drawing" publicKeyToken="b03f5f7f11d50a3a" culture=""/> <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Windows.Forms" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture=""/> <bindingRedirect oldVersion="1.0.5000.0" newVersion="1.0.3300.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> --- NEW FILE: nunit.framework.tests.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.testutilities.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.extensions.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.core.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: mock-assembly.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nonamespace-assembly.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.util.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.framework.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.mocks.dll --- (This appears to be a binary file; contents omitted.) |