Thread: [Adapdev-commits] Adapdev/src/Adapdev.Data.Tests Adapdev.Data.Tests.csproj,1.9,1.10 CategoriesDAOTes
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 05:33:36
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19977/src/Adapdev.Data.Tests Added Files: Adapdev.Data.Tests.csproj CategoriesDAOTest.cs ProviderInfoManagerTest.cs SchemaBuilderTest.cs Log Message: Reposting to the repository after it got hosed --- NEW FILE: Adapdev.Data.Tests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{07695A4B-39A8-41CB-A21B-E61B3990C20F}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.Data.Tests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.Data.Tests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "Adapdev.Data" Project = "{08C5794D-44ED-4E75-A1C1-48A28C3D0044}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "Adapdev" Project = "{CC30A321-2569-4B1F-8E1A-781B5509B56D}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "log4net" AssemblyName = "log4net" HintPath = "..\..\lib\log4net.dll" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\..\lib\nunit.framework.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CategoriesDAOTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ProviderInfoManagerTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SchemaBuilderTest.cs" SubType = "Code" 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> </CSHARP> </VisualStudioProject> --- NEW FILE: SchemaBuilderTest.cs --- using System; using NUnit.Framework; namespace Adapdev.Data.Tests { using Adapdev.Data; using Adapdev.Data.Schema; /// <summary> /// Summary description for SchemaBuilderTest. /// </summary> /// [TestFixture] public class SchemaBuilderTest { private string _oledbConnectionString = "Provider=sqloledb;Data Source=localhost;Initial Catalog=northwind;User Id=sa;Password=;"; private string _sqlserverConnectionString = "Data Source=localhost; Initial Catalog=northwind; User ID=sa; Password=; Trusted_Connection=false;"; private string _mysqlConnectionString = "Data Source=localhost;Database=codus_test;User ID=;Password=;"; [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); } } [Test] public void BuildMySqlSchema() { DatabaseSchema ds = SchemaBuilder.CreateDatabaseSchema(this._mysqlConnectionString, Adapdev.Data.DbType.MYSQL, Adapdev.Data.DbProviderType.MYSQL); 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."); } [Test,Ignore("")] public void PrintMySqlSchema() { int i = 0; Console.WriteLine(new MySqlSchemaBuilder(null, ref i).PrintReaderSchema(this._mysqlConnectionString, "alldatatypes")); } [Test] public void ProviderConfig() { ProviderConfig pc = new ProviderConfig(); Assert.AreEqual(5 ,pc.ConnectionTypes.Count, "Should have 5 Connection Types in the ProviderConfig collection"); Assert.IsTrue(pc.ConnectionTypes.Contains("Microsoft Access"),"Could not find Microsoft Access"); Assert.IsTrue(pc.ConnectionTypes.Contains("SQL Server"),"Could not find SQL Server"); Assert.IsTrue(pc.ConnectionTypes.Contains("SQL Server - Trusted"), "Could not find SQL Server - Trusted"); Assert.IsTrue(pc.ConnectionTypes.Contains("Oracle"), "Could not find Oracle"); Assert.IsTrue(pc.ConnectionTypes.Contains("Oracle - Trusted"), "Could not find Oracle -Trusted"); } [Test] public void ConnectionTypes() { DbConnectionTypes ct = new DbConnectionTypes(); Assert.AreEqual(0, ct.Count, "Should be zero items"); ct.Add("test", new DbConnectionType()); Assert.AreEqual(1, ct.Count, "Should be one item"); Assert.IsTrue(ct.Contains("test"),"Should contain test"); ct.Remove("test"); Assert.AreEqual(0, ct.Count, "Should be zero items after deleting the item"); ct.Add(new DbConnectionType("zarniwoop",DbType.SQLSERVER, "OLEDB",true, true, true, true, false)); ct.Add(new DbConnectionType("beeblebrox",DbType.SQLSERVER, "OLEDB",true, true, true, true, false)); ct.Add(new DbConnectionType("magrathea",DbType.SQLSERVER, "OLEDB",true, true, true, true, false)); ct.Add(new DbConnectionType("marvin",DbType.SQLSERVER, "OLEDB",true, true, true, true, false)); ct.Add(new DbConnectionType("vogon",DbType.SQLSERVER, "OLEDB",true, true, true, true, false)); Assert.AreEqual("beeblebrox", ct.GetByIndex(0).Name); Assert.AreEqual("magrathea", ct.GetByIndex(1).Name); Assert.AreEqual("marvin", ct.GetByIndex(2).Name); Assert.AreEqual("vogon", ct.GetByIndex(3).Name); Assert.AreEqual("zarniwoop", ct.GetByIndex(4).Name); ct.Clear(); Assert.AreEqual(0, ct.Count, "Should be zero items after clearing the collection"); } [Test] public void ConnectionType() { DbConnectionType ct = new DbConnectionType(); Assert.IsNotNull(ct); ct = new DbConnectionType("TestType",DbType.SQLSERVER, "OLEDB", true, true, true, true, false); Assert.IsFalse(ct.SupportsFile); Assert.IsTrue(ct.SupportsServer); ct.SupportsServer = false; Assert.IsTrue(ct.SupportsFile); Assert.IsFalse(ct.SupportsServer); ct.DbType = DbType.ACCESS; Assert.AreEqual("ACCESS", ct.DbTypeName); } [Test] [ExpectedException(typeof(ApplicationException))] public void ConnectionTypeInternalFails() { DbConnectionType ct = new DbConnectionType("TestType",DbType.SQLSERVER, "OLEDB", true, true, true, true, false); Assert.AreEqual("OLEDB", ct.InternalProviderName); Assert.IsNull(ct.InternalProvider); } [Test] public void ConnectionProviders() { DbConnectionProviders cp = new DbConnectionProviders(); Assert.AreEqual(0, cp.Count, "Should be zero items"); cp.Add("test", new DbConnectionProvider()); Assert.AreEqual(1, cp.Count, "Should be one item"); Assert.IsTrue(cp.Contains("test"),"Should contain test"); cp.Remove("test"); Assert.AreEqual(0, cp.Count, "Should be zero items after deleting the item"); DbConnectionType ct = new DbConnectionType("TestType",DbType.SQLSERVER,"OLEDB", true, true, true, true, false); ct.Providers = cp; cp.Add(new DbConnectionProvider("zarniwoop","SQLSERVER", "provider=mssqlserver", ct)); cp.Add(new DbConnectionProvider("beeblebrox","SQLSERVER", "provider=mssqlserver", ct)); cp.Add(new DbConnectionProvider("magrathea","SQLSERVER", "provider=mssqlserver", ct)); cp.Add(new DbConnectionProvider("marvin","SQLSERVER", "provider=mssqlserver", ct)); cp.Add(new DbConnectionProvider("vogon","SQLSERVER", "provider=mssqlserver", ct)); Assert.AreEqual("beeblebrox", cp.GetByIndex(0).Name, "Items out of order"); Assert.AreEqual("magrathea", cp.GetByIndex(1).Name, "Items out of order"); Assert.AreEqual("marvin", cp.GetByIndex(2).Name, "Items out of order"); Assert.AreEqual("vogon", cp.GetByIndex(3).Name, "Items out of order"); Assert.AreEqual("zarniwoop", cp.GetByIndex(4).Name, "Items out of order"); cp.Clear(); Assert.AreEqual(0, cp.Count, "Should be zero items after clearing the collection"); } [Test] public void ConnectionProvider() { DbConnectionType ct = new DbConnectionType("TestType",DbType.SQLSERVER,"OLEDB", true, true, true, true, false); DbConnectionProvider cp = new DbConnectionProvider(); Assert.IsNotNull(cp); cp = new DbConnectionProvider("TestProvider1", "SQLSERVER", "provider=mssqlserver", ct); ct.Providers.Add(cp); cp = new DbConnectionProvider("TestProvider2", "OLEDB", "provider=mssqlserver", ct); ct.Providers.Add(cp); Assert.AreEqual(2, ct.Providers.Count, "Should be two providers."); cp.DbType = DbType.ACCESS; Assert.AreEqual("ACCESS", cp.DbTypeName); cp.ProviderType = DbProviderType.OLEDB; Assert.AreEqual("OLEDB", cp.ProviderTypeName); ct.InternalProviderName = "TestProvider2"; Assert.AreEqual("TestProvider2", ct.InternalProvider.Name, "Internal Provider should be 'TestProvider2'"); Assert.IsNotNull(cp.Parent,"Parent should not be Null. Should be 'TestType'"); Assert.IsNotNull(cp.Parent.InternalProvider,"Internal provider should be defined"); Assert.AreEqual(cp.Parent.InternalProvider.ConnectionString("TestServer"), cp.ConnectionString("TestServer")); cp = new DbConnectionProvider("TestProvider","OLEDB", "{0},{1},{2},{3}", ct); Assert.AreEqual("A,B,C,D", cp.ConnectionString("A","B","C","D")); } } } --- 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: ProviderInfoManagerTest.cs --- using System; using Adapdev.Data; using NUnit.Framework; namespace Adapdev.Data.Tests { /// <summary> /// Summary description for ProviderInfoManagerTest. /// </summary> /// [TestFixture] public class ProviderInfoManagerTest { [Test] public void GetDefaultValue() { int oracleId = ProviderInfoManager.GetInstance().GetIdByName(DbProviderType.ORACLE,"CHAR"); Assert.AreEqual(129, oracleId, "Oracle types don't match."); int sqlId = ProviderInfoManager.GetInstance().GetIdByName(DbProviderType.SQLSERVER, "CHAR"); Assert.AreEqual(129, sqlId, "Sql Server types don't match."); } } } |