From: <gc...@us...> - 2002-12-28 21:36:37
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/data In directory sc8-pr-cvs1:/tmp/cvs-serv6799/DotNetMock.Tests/data Modified Files: mockcommandtests.cs Added Files: mockdatareadertests.cs Log Message: --- NEW FILE: mockdatareadertests.cs --- using System; using System.Data; using DotNetMock.Data; using NUnit.Framework; namespace DotNetMock.Tests.Data { [TestFixture] public class MockDataReaderTests { private MockDataReader _reader = null; [SetUp] public void Init() { _reader = new MockDataReader(); } [TearDown] public void Destroy() { _reader = null; } [Test] public void RecordsAffectedSuccess() { _reader.SetRecordsAffectedCount(1); Assertion.AssertEquals("Records affected not equal.", 1, _reader.RecordsAffected); } [Test] [ExpectedException(typeof(AssertionException))] public void RecordsAffectedFails() { _reader.SetRecordsAffectedCount(2); Assertion.AssertEquals(3, _reader.RecordsAffected); } [Test] public void CloseCountCallsSuccess() { _reader.SetExpectedCloseCalls(3); _reader.Close(); _reader.Close(); _reader.Close(); _reader.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void CloseCountCallsFails() { _reader.SetExpectedCloseCalls(1); _reader.Close(); _reader.Close(); _reader.Verify(); } [Test] public void GetSchemsTableSuccess() { DataTable dataTable = new DataTable(); dataTable.Columns.Add(new DataColumn("ID", typeof(int))); dataTable.Columns.Add(new DataColumn("Password", typeof(string))); dataTable.Columns.Add(new DataColumn("Email", typeof(string))); _reader.SetSchemaTable(dataTable); DataTable dataTable2 = new DataTable(); dataTable2.Columns.Add(new DataColumn("ID", typeof(int))); dataTable2.Columns.Add(new DataColumn("Password", typeof(string))); dataTable2.Columns.Add(new DataColumn("Email", typeof(string))); Assertion.Equals(dataTable2, _reader.GetSchemaTable()); } [Test] public void GetSchemaTableFails() { Assertion.AssertNull("Schema Table isn't empty.", _reader.GetSchemaTable()); } [Test] public void IsClosedSuccess() { _reader.SetIsClosedValue(true); Assertion.Assert(_reader.IsClosed); } [Test] public void IsCloseDefaultValue() { Assertion.Assert(!_reader.IsClosed); } [Test] public void ReadCountCallsSuccess() { _reader.SetExpectedReadCalls(3); _reader.Read(); _reader.Read(); _reader.Read(); _reader.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void ReadCountCallsFails() { _reader.SetExpectedReadCalls(2); _reader.Read(); _reader.Read(); _reader.Read(); _reader.Verify(); } [Test] public void ReadSuccess() { _reader.SetExpectedReadCalls(3); _reader.SetRows(createObjectValues()); while (_reader.Read()) { } _reader.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void ReadFailure() { _reader.SetExpectedReadCalls(2); _reader.SetRows(createObjectValues()); while (_reader.Read()) { } _reader.Verify(); } [Test] public void GetValueSuccess() { _reader.SetExpectedReadCalls(3); _reader.SetRows(createObjectValues()); int rowCount = 0; while (_reader.Read()) { for (int i = 0; i <= 1; i++) { Assertion.AssertEquals("Items not equal.", "Row " + rowCount + ", Column " + i, _reader.GetValue(i + 1)); } rowCount++; } _reader.Verify(); } [Test] public void IndexerIntSuccess() { _reader.SetExpectedReadCalls(3); _reader.SetRows(createObjectValues()); int rowCount = 0; while (_reader.Read()) { for (int i = 0; i <= 1; i++) { Assertion.AssertEquals("Items not equal.", "Row " + rowCount + ", Column " + i, _reader[i + 1]); } rowCount++; } _reader.Verify(); } [Test] [ExpectedException(typeof(IndexOutOfRangeException))] public void IndexerIntFails() { _reader.SetExpectedReadCalls(3); _reader.SetRows(createObjectValues()); int rowCount = 0; while (_reader.Read()) { for (int i = 0; i <= 1; i++) { Assertion.AssertEquals("Items not equal.", "Row " + rowCount + ", Column " + i, _reader[i + 3]); } rowCount++; } _reader.Verify(); } [Test] public void GetIntSuccess() { object[,] values = new object[2,2]; values[0,0] = 0; values[0,1] = 1; values[1,0] = 0; values[1,1] = 1; _reader.SetRows(values); _reader.SetExpectedReadCalls(3); while (_reader.Read()) { Assertion.AssertEquals(0, _reader.GetInt32(1)); Assertion.AssertEquals(1, _reader.GetInt32(2)); } _reader.Verify(); } [Test] [ExpectedException(typeof(IndexOutOfRangeException))] public void GetIntFails() { object[,] values = new object[2,2]; values[0,0] = 0; values[0,1] = 1; values[1,0] = 0; values[1,1] = 1; _reader.SetRows(values); _reader.SetExpectedReadCalls(3); while (_reader.Read()) { Assertion.AssertEquals(0, _reader.GetInt32(0)); Assertion.AssertEquals(1, _reader.GetInt32(1)); } _reader.Verify(); } [Test] public void IndexerStringSuccess() { _reader.SetExpectedReadCalls(2); DataTable dataTable = new DataTable(); dataTable.Columns.Add(new DataColumn("ID", typeof(int))); dataTable.Columns.Add(new DataColumn("Password", typeof(string))); _reader.SetSchemaTable(dataTable); object[,] values = new object[1,2]; values[0,0] = 123456; values[0,1] = "password"; _reader.SetRows(values); while (_reader.Read()) { Assertion.AssertEquals(123456, _reader["ID"]); Assertion.AssertEquals("password", _reader["Password"]); } _reader.Verify(); } [Test] [ExpectedException(typeof(IndexOutOfRangeException))] public void IndexerStringFails() { DataTable dataTable = new DataTable(); dataTable.Columns.Add(new DataColumn("ID", typeof(int))); dataTable.Columns.Add(new DataColumn("Password", typeof(string))); _reader.SetSchemaTable(dataTable); object[,] values = new object[2,2]; values[0,0] = 123456; values[0,1] = "password"; _reader.SetRows(values); while (_reader.Read()) { Assertion.AssertEquals(123456, _reader["Fakes"]); } _reader.Verify(); } private object[,] createObjectValues() { object[,] values = new object[2,2]; values[0,0] = "Row 0, Column 0"; values[0,1] = "Row 0, Column 1"; values[1,0] = "Row 1, Column 0"; values[1,1] = "Row 1, Column 1"; return values; } } } Index: mockcommandtests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/data/mockcommandtests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mockcommandtests.cs 29 Oct 2002 03:40:13 -0000 1.1 --- mockcommandtests.cs 28 Dec 2002 21:36:34 -0000 1.2 *************** *** 16,20 **** public void Destroy() { - _mockCmd.Dispose(); _mockCmd = null; } --- 16,19 ---- *************** *** 76,80 **** MockTransaction mockTransaction = new MockTransaction(); - NUnit.Framework.Assertion.AssertNull(_mockCmd.Connection); _mockCmd.Transaction = mockTransaction; NUnit.Framework.Assertion.AssertNotNull(_mockCmd.Transaction); --- 75,78 ---- *************** *** 82,85 **** --- 80,84 ---- NUnit.Framework.Assertion.AssertNotNull(_mockCmd.Connection); NUnit.Framework.Assertion.AssertEquals(typeof(MockDbConnection), _mockCmd.Connection.GetType()); + _mockCmd.Dispose(); } [Test] |