[Adapdev-commits] Adapdev/src/Adapdev.Data.Tests Adapdev.Data.Tests.csproj.user,1.2,1.3 CategoriesDA
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-10-21 05:00:08
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27500/src/Adapdev.Data.Tests Modified Files: Adapdev.Data.Tests.csproj SchemaBuilderTest.cs Added Files: Adapdev.Data.Tests.csproj.user CategoriesDAOTest.cs Log Message: Several bug fixes for AbstractDAO Added unit tests for NUnit support Index: Adapdev.Data.Tests.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data.Tests/Adapdev.Data.Tests.csproj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Adapdev.Data.Tests.csproj 13 May 2005 03:51:26 -0000 1.5 --- Adapdev.Data.Tests.csproj 21 Oct 2005 04:59:20 -0000 1.6 *************** *** 111,114 **** --- 111,119 ---- /> <File + RelPath = "CategoriesDAOTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "ProviderInfoManagerTest.cs" SubType = "Code" *************** *** 120,123 **** --- 125,173 ---- BuildAction = "Compile" /> + <File + RelPath = "CategoriesExample\CategoriesDAO.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\CategoriesDAOBase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\CategoriesEntity.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\CategoriesEntityBase.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\CategoriesEntityCollection.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\CategoriesEntityDictionary.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\CategoriesEntityEnumerator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\DbConstants.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CategoriesExample\MockCategories.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> Index: SchemaBuilderTest.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data.Tests/SchemaBuilderTest.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SchemaBuilderTest.cs 18 Sep 2005 03:04:45 -0000 1.4 --- SchemaBuilderTest.cs 21 Oct 2005 04:59:20 -0000 1.5 *************** *** 20,36 **** [Test] ! public void BuildOleDbSchema() { DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(this._oledbConnectionString, Adapdev.Data.DbType.SQLSERVER, Adapdev.Data.DbProviderType.OLEDB); Assert.AreEqual(29, ds.Tables.Count, "Northwind should have 29 tables / views."); Assert.IsTrue(ds.Tables.Contains("Orders")); } [Test] ! public void BuildSqlServerSchema() { ! DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(this._oledbConnectionString, Adapdev.Data.DbType.SQLSERVER, Adapdev.Data.DbProviderType.OLEDB); Assert.AreEqual(29, ds.Tables.Count, "Northwind should have 29 tables / views."); Assert.IsTrue(ds.Tables.Contains("Orders")); } --- 20,51 ---- [Test] ! public void BuildSqlServerOleDbSchema() { DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(this._oledbConnectionString, Adapdev.Data.DbType.SQLSERVER, Adapdev.Data.DbProviderType.OLEDB); Assert.AreEqual(29, ds.Tables.Count, "Northwind should have 29 tables / views."); Assert.IsTrue(ds.Tables.Contains("Orders")); + Assert.AreEqual(Adapdev.Data.DbProviderType.OLEDB, ds.DatabaseProviderType, "ProviderTypes don't match."); + Assert.AreEqual(Adapdev.Data.DbType.SQLSERVER, ds.DatabaseType, "DataTypes don't match."); + + foreach(ColumnSchema column in ds.GetTable("Orders").Columns.Values) + { + Console.WriteLine("{0} : {1}", column.Name, column.DataType); + } + } [Test] ! public void BuildSqlServerSqlSchema() { ! DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(this._oledbConnectionString, Adapdev.Data.DbType.SQLSERVER, Adapdev.Data.DbProviderType.SQLSERVER); Assert.AreEqual(29, ds.Tables.Count, "Northwind should have 29 tables / views."); Assert.IsTrue(ds.Tables.Contains("Orders")); + Assert.AreEqual(Adapdev.Data.DbProviderType.SQLSERVER, ds.DatabaseProviderType, "ProviderTypes don't match."); + Assert.AreEqual(Adapdev.Data.DbType.SQLSERVER, ds.DatabaseType, "DataTypes don't match."); + + foreach(ColumnSchema column in ds.GetTable("Orders").Columns.Values) + { + Console.WriteLine("{0} : {1}", column.Name, column.DataType); + } } *************** *** 41,44 **** --- 56,61 ---- Assert.AreEqual(4, ds.Tables.Count, "codus_test should have 4 tables"); Assert.IsTrue(ds.Tables.Contains("alldatatypes")); + Assert.AreEqual(Adapdev.Data.DbProviderType.MYSQL, ds.DatabaseProviderType, "ProviderTypes don't match."); + Assert.AreEqual(Adapdev.Data.DbType.MYSQL, ds.DatabaseType, "DataTypes don't match."); } --- NEW FILE: CategoriesDAOTest.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:20 PM ******************************************/ using System; using System.Collections; using System.Data; using Test; using Test.Mock; using Adapdev.Serialization; using Adapdev.Transactions; using NUnit.Framework; namespace Test.Tests.NUnit { /// <summary> /// Summary description for ShippersDAOTest. /// </summary> /// [TestFixture] public class CategoriesDAOTest { CategoriesDAO dao = null; int total = 0; bool inserted = false; [TestFixtureSetUp] public void TestFixtureSetup() { dao = new CategoriesDAO(); total = dao.GetCount(); } [Test] public void Insert() { this.inserted = false; int count = dao.GetCount(); MockCategoriesEntity e = new MockCategoriesEntity(); dao.Save(e); Console.WriteLine("Inserted record: " + Environment.NewLine + e.ToString()); int count2 = dao.GetCount(); Assert.IsTrue(count == (count2 - 1), "Record was not inserted."); Assert.AreNotEqual(2, e.CategoryID, "CategoryId is an autoincrement and should be db assigned."); this.inserted = true; } [Test] public void InsertDistributedTransaction() { using(TransactionScope transaction = new TransactionScope()) { this.inserted = false; int count = dao.GetCount(); MockCategoriesEntity e = new MockCategoriesEntity(); dao.Save(e); Console.WriteLine("Inserted record: " + Environment.NewLine + e.ToString()); int count2 = dao.GetCount(); Assert.IsTrue(count == (count2 - 1), "Record was not inserted."); Assert.AreNotEqual(2, e.CategoryID, "CategoryId is an autoincrement and should be db assigned."); transaction.Abort(); } } [Test] public void InsertLocalTransaction() { int start = dao.GetCount(); using(IDbConnection c= dao.CreateConnection()) { c.Open(); Assert.IsTrue(c.State == ConnectionState.Open, "Connection is not open."); IDbTransaction t= c.BeginTransaction(); MockCategoriesEntity e = new MockCategoriesEntity(); dao.Save(e, c, t); Console.WriteLine("Inserted record: " + Environment.NewLine + e.ToString()); Assert.AreNotEqual(2, e.CategoryID, "CategoryId is an autoincrement and should be db assigned."); t.Rollback(); } int end = dao.GetCount(); Assert.AreEqual(start, end, "No record should have been inserted."); } [Test] public void SelectAll() { ICollection c = dao.SelectAll(); if(total > 0){ Assert.IsTrue(c.Count > 0, "No records returned."); //foreach(CategoriesEntity e in c) //{ // Console.WriteLine(e.ToString()); //} } } [Test] [Ignore("")] public void TestToString(){ ArrayList al = new ArrayList(dao.SelectAllWithLimit(1)); CategoriesEntity s = (CategoriesEntity)al[0]; Console.WriteLine(s.ToString()); } [Test] [Ignore("")] public void TestSerialize(){ ArrayList al = new ArrayList(dao.SelectAllWithLimit(1)); CategoriesEntity s = (CategoriesEntity)al[0]; Console.WriteLine(Serializer.SerializeToXml(s)); } [Test,Ignore("Only use this on a development database.")] public void Update() { if(this.inserted){ ArrayList al = new ArrayList(dao.SelectAllWithLimit(1, Adapdev.Data.Sql.OrderBy.DESCENDING, new string[]{CategoriesDAO.TABLE_PRIMARYKEY})); CategoriesEntity s = (CategoriesEntity)al[0]; Console.WriteLine("Record to be updated: "); Console.WriteLine(s.ToString()); s.CategoryName = "test"; s.Description = "test"; s.Picture = System.Text.Encoding.ASCII.GetBytes("Test String2"); dao.Update(s); Console.WriteLine("Updated record:"); Console.WriteLine(s.ToString()); CategoriesEntity s2 = (CategoriesEntity)dao.SelectById(s.CategoryID); Assert.AreEqual( s.CategoryID.ToString().Trim() , s2.CategoryID.ToString().Trim(), "Objects should be equal." ); Assert.AreEqual( s.CategoryName.ToString().Trim() , s2.CategoryName.ToString().Trim(), "Objects should be equal." ); Assert.AreEqual( s.Description.ToString().Trim() , s2.Description.ToString().Trim(), "Objects should be equal." ); Assert.AreEqual( s.Picture.ToString().Trim() , s2.Picture.ToString().Trim(), "Objects should be equal." ); }else{ throw new Exception("No test record inserted, so unable to perform update."); } } [TestFixtureTearDown] public void Delete() { if(inserted){ ArrayList al = new ArrayList(dao.SelectAllWithLimit(1, Adapdev.Data.Sql.OrderBy.DESCENDING, new string[]{CategoriesDAO.TABLE_PRIMARYKEY})); int count1 = dao.GetCount(); CategoriesEntity s = (CategoriesEntity)al[0]; Console.WriteLine("Deleted Record:"); Console.WriteLine(s.ToString()); dao.Delete(s.CategoryID); int count2 = dao.GetCount(); Assert.IsTrue(count2 == (count1 - 1), "Unable to delete record."); this.inserted = false; } } } } --- NEW FILE: Adapdev.Data.Tests.csproj.user --- <VisualStudioProject> <CSHARP LastOpenVersion = "7.10.3077" > <Build> <Settings ReferencePath = "D:\projects\Adapdev\Adapdev\lib\" > <Config Name = "Debug" EnableASPDebugging = "false" EnableASPXDebugging = "false" EnableUnmanagedDebugging = "false" EnableSQLServerDebugging = "false" RemoteDebugEnabled = "false" RemoteDebugMachine = "" StartAction = "Project" StartArguments = "" StartPage = "" StartProgram = "" StartURL = "" StartWorkingDirectory = "" StartWithIE = "false" /> <Config Name = "Release" EnableASPDebugging = "false" EnableASPXDebugging = "false" EnableUnmanagedDebugging = "false" EnableSQLServerDebugging = "false" RemoteDebugEnabled = "false" RemoteDebugMachine = "" StartAction = "Project" StartArguments = "" StartPage = "" StartProgram = "" StartURL = "" StartWorkingDirectory = "" StartWithIE = "false" /> </Settings> </Build> <OtherProjectSettings CopyProjectDestinationFolder = "" CopyProjectUncPath = "" CopyProjectOption = "0" ProjectView = "ProjectFiles" ProjectTrust = "0" /> </CSHARP> </VisualStudioProject> |