From: Michael D. <mik...@us...> - 2004-08-20 15:26:34
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/SqlCommandTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23509/NHibernate.Test/SqlCommandTest Modified Files: SqlStringFixture.cs Log Message: Added methods to SqlString and tests for them. Index: SqlStringFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/SqlCommandTest/SqlStringFixture.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SqlStringFixture.cs 18 Aug 2004 20:15:04 -0000 1.2 --- SqlStringFixture.cs 20 Aug 2004 15:26:23 -0000 1.3 *************** *** 33,76 **** } ! [Test] ! public void EndsWith() ! { ! SqlString sql = new SqlString( new string[] {"select", " from table" } ); ! Assert.IsTrue( sql.EndsWith("ble") ); ! Assert.IsFalse( sql.EndsWith("'") ); ! } ! ! [Test] ! public void EndsWithEmptyString() ! { ! SqlString sql = new SqlString( new string[] { "", "select", " from table", "" } ); ! Assert.IsTrue( sql.EndsWith("ble") ); ! Assert.IsFalse( sql.EndsWith("'") ); ! } ! ! [Test] ! public void EndsWithParameter() ! { ! SqlString sql = new SqlString( new object[] { "", "select", " from table where id = ", new Parameter() } ); ! Assert.IsFalse( sql.EndsWith("'") ); ! Assert.IsFalse( sql.EndsWith("") ); ! } ! ! [Test] ! public void StartsWith() ! { ! SqlString sql = new SqlString( new string[] {"select", " from table" } ); ! Assert.IsTrue( sql.StartsWith("s") ); ! Assert.IsFalse( sql.StartsWith(",") ); ! } ! ! [Test] ! public void StartsWithEmptyString() ! { ! SqlString sql = new SqlString( new string[] { "", "select", " from table" } ); ! Assert.IsTrue( sql.StartsWith("s") ); ! Assert.IsFalse( sql.StartsWith(",") ); ! } ! [Test] public void CompactWithNoParams() --- 33,37 ---- } ! [Test] public void CompactWithNoParams() *************** *** 123,126 **** --- 84,192 ---- [Test] + public void ContainsUntypedParameterWithoutParam() + { + SqlString sql = new SqlString( new string[] {"select", " from table"} ); + Assert.IsFalse( sql.ContainsUntypedParameter ); + } + + [Test] + public void ContainsUntypedParameterWithParam() + { + Parameter p1 = new Parameter(); + p1.SqlType = new SqlTypes.Int32SqlType(); + p1.Name = "p1"; + + SqlString sql = new SqlString( new object[] {"select", " from table where a = ", p1} ); + Assert.IsFalse( sql.ContainsUntypedParameter ); + } + + [Test] + public void ContainsUntypedParameterWithUntypedParam() + { + + SqlString sql = new SqlString( new object[] {"select", " from table where a = ", new Parameter()} ); + Assert.IsTrue( sql.ContainsUntypedParameter ); + } + + [Test] + public void ContainsUntypedParameterWithMixedUntypedParam() + { + Parameter p1 = new Parameter(); + p1.SqlType = new SqlTypes.Int32SqlType(); + p1.Name = "p1"; + + SqlString sql = new SqlString( new object[] {"select", " from table where a = ", new Parameter(), " and b = " , p1} ); + Assert.IsTrue( sql.ContainsUntypedParameter ); + } + + [Test] + public void EndsWith() + { + SqlString sql = new SqlString( new string[] {"select", " from table" } ); + Assert.IsTrue( sql.EndsWith("ble") ); + Assert.IsFalse( sql.EndsWith("'") ); + } + + [Test] + public void EndsWithEmptyString() + { + SqlString sql = new SqlString( new string[] { "", "select", " from table", "" } ); + Assert.IsTrue( sql.EndsWith("ble") ); + Assert.IsFalse( sql.EndsWith("'") ); + } + + [Test] + public void EndsWithParameter() + { + SqlString sql = new SqlString( new object[] { "", "select", " from table where id = ", new Parameter() } ); + Assert.IsFalse( sql.EndsWith("'") ); + Assert.IsFalse( sql.EndsWith("") ); + } + + [Test] + public void ParameterIndexesNoParams() + { + SqlString sql = new SqlString( new object[] {"select ", "from table ", "where 'a'='a'" } ); + + Assert.AreEqual( 0, sql.ParameterIndexes.Length ); + } + + [Test] + public void ParameterIndexOneParam() + { + SqlString sql = new SqlString( new object[] {"select ", "from table ", "where a = ", new Parameter() } ); + + Assert.AreEqual( 1, sql.ParameterIndexes.Length ); + Assert.AreEqual( 3, sql.ParameterIndexes[0] ); + } + + + [Test] + public void ParameterIndexManyParam() + { + SqlString sql = new SqlString( new object[] {"select ", "from table ", "where a = ", new Parameter(), " and c = ", new Parameter() } ); + + Assert.AreEqual( 2, sql.ParameterIndexes.Length ); + Assert.AreEqual( 3, sql.ParameterIndexes[0] ); + Assert.AreEqual( 5, sql.ParameterIndexes[1] ); + } + + [Test] + public void StartsWith() + { + SqlString sql = new SqlString( new string[] {"select", " from table" } ); + Assert.IsTrue( sql.StartsWith("s") ); + Assert.IsFalse( sql.StartsWith(",") ); + } + + [Test] + public void StartsWithEmptyString() + { + SqlString sql = new SqlString( new string[] { "", "select", " from table" } ); + Assert.IsTrue( sql.StartsWith("s") ); + Assert.IsFalse( sql.StartsWith(",") ); + } + + [Test] public void Substring() { |