|
using System;
using NUnit.Framework;
using ComPlusNHibernateTest;
namespace CPNTestHarness
{
/// <summary>
/// An NUnit test harness to test that this all works.
/// </summary>
[TestFixture]
public class TestHarness
{
public void Test01()
{
Console.WriteLine("This test will start a transaction, add two objects, and end the transaction.");
Console.WriteLine("It will then open a second transaction, delete the objects, and end.");
TransactionController tc = new TransactionController();
Table1 t1;
Table2 t2;
try
{
Console.WriteLine("Beginning transaction");
tc.BeginTransaction();
t1 = new Table1();
t1.Num = 1;
t2 = new Table2();
t2.Num = 2;
Console.WriteLine("Saving first object");
tc.Save(t1);
Console.WriteLine("Saving second object");
tc.Save(t2);
}
finally
{
Console.WriteLine("Ending transaction");
tc.EndTransaction();
}
try
{
Console.WriteLine("Beginning another transaction");
tc.BeginTransaction();
Console.WriteLine("Deleting first object");
tc.Delete(t1);
Console.WriteLine("Deleting second object");
tc.Delete(t2);
}
finally
{
Console.WriteLine("Ending transaction");
tc.EndTransaction();
}
Console.WriteLine();
}
public void Test02()
{
Console.WriteLine("This test will create one good object and attempt to delete a non-existant object.");
Console.WriteLine("The end result is that the database table should be empty when the transaction ends.");
TransactionController tc = new TransactionController();
try
{
Console.WriteLine("Beginning transaction");
tc.BeginTransaction();
Table1 t1 = new Table1();
t1.Num = 1;
Table2 t2 = new Table2();
t2.Num = 2;
Console.WriteLine("Saving first object");
tc.Save(t1);
Console.WriteLine("Attempting to delete second object");
try
{
tc.Delete(t2);
Assert.Fail("We didn't catch an exception on the delete. Something's wrong.");
}
catch
{
Console.WriteLine("Caught an exception. We're looking good.");
}
}
finally
{
Console.WriteLine("Ending transaction");
tc.EndTransaction();
}
Console.WriteLine("Verifying that both tables are empty.");
Assert.AreEqual(0, tc.GetAll(typeof(Table1)).Count);
Assert.AreEqual(0, tc.GetAll(typeof(Table2)).Count);
Console.WriteLine("Success!");
Console.WriteLine();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.