|
using System;
using System.Collections.Generic;
using System.Data;
using Vts.UnitTest;
using Clifton.Data;
namespace TransactionLoggerUnitTests
{
[TestFixture]
[ProcessTest]
public class LoggerTests
{
protected DataTable dt;
protected DataTableTransactionLog dttl;
protected DataRow row;
[TestFixtureSetUp]
public void FixtureSetup()
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("LastName", typeof(string)));
dt.Columns.Add(new DataColumn("FirstName", typeof(string)));
dttl = new DataTableTransactionLog();
dttl.SourceTable = dt;
}
[Test, Sequence(1)]
public void NewRow()
{
row = dt.NewRow();
Assertion.Assert(dttl.Log.Count == 1, "Expected one entry.");
Assertion.Assert(dttl.Log[0].TransactionType == DataTableTransactionRecord.RecordType.NewRow, "Expected new row transaction.");
}
[Test, Sequence(2)]
public void SetFields()
{
row["LastName"] = "Clifton";
row["FirstName"] = "Marc";
dt.Rows.Add(row);
Assertion.Assert(dttl.Log.Count == 3, "Expected three entries.");
Assertion.Assert(dttl.Log[1].TransactionType == DataTableTransactionRecord.RecordType.ChangeField, "Expected change field transaction.");
Assertion.Assert(dttl.Log[2].TransactionType == DataTableTransactionRecord.RecordType.ChangeField, "Expected change field transaction.");
Assertion.Assert(dttl.Log[1].NewValue.ToString()=="Clifton", "Incorrect new value.");
Assertion.Assert(dttl.Log[2].NewValue.ToString() == "Marc", "Incorrect new value.");
}
[Test, Sequence(3)]
public void CollectNothing()
{
dttl.CollectUncommittedRows();
Assertion.Assert(dt.Rows.Count == 1, "Committed row was collected!");
}
[Test, Sequence(4)]
public void CollectUncommitted()
{
dt.NewRow();
dttl.CollectUncommittedRows();
Assertion.Assert(dttl.Log.Count == 3, "Expected three entries.");
}
[Test, Sequence(5)]
public void RevertFirstNameChange()
{
dttl.Revert(2);
Assertion.Assert(dt.Rows[0]["LastName"].ToString() == "Clifton", "Incorrect value.");
Assertion.Assert(dt.Rows[0]["FirstName"]==DBNull.Value, "Incorrect new value.");
}
[Test, Sequence(6)]
public void RevertLastNameChange()
{
dttl.Revert(1);
Assertion.Assert(dt.Rows[0]["LastName"] == DBNull.Value, "Incorrect value.");
Assertion.Assert(dt.Rows[0]["FirstName"] == DBNull.Value, "Incorrect new value.");
}
[Test, Sequence(7)]
public void RevertNewRowChange()
{
dttl.Revert(0);
Assertion.Assert(dt.Rows.Count == 0, "Row should have been deleted.");
}
[Test, Sequence(8)]
public void ApplyNewRow()
{
dttl.Apply(0);
Assertion.Assert(dt.Rows.Count == 1, "Row was not added.");
Assertion.Assert(dt.Rows[0]["LastName"] == DBNull.Value, "Incorrect value.");
Assertion.Assert(dt.Rows[0]["FirstName"] == DBNull.Value, "Incorrect new value.");
}
[Test, Sequence(9)]
public void ApplyLastName()
{
dttl.Apply(1);
Assertion.Assert(dt.Rows.Count == 1, "Row was not added.");
Assertion.Assert(dt.Rows[0]["LastName"].ToString() == "Clifton", "Incorrect value.");
Assertion.Assert(dt.Rows[0]["FirstName"] == DBNull.Value, "Incorrect new value.");
}
[Test, Sequence(10)]
public void ApplyFirstName()
{
dttl.Apply(2);
Assertion.Assert(dt.Rows.Count == 1, "Row was not added.");
Assertion.Assert(dt.Rows[0]["LastName"].ToString() == "Clifton", "Incorrect value.");
Assertion.Assert(dt.Rows[0]["FirstName"].ToString() == "Marc", "Incorrect new value.");
}
}
}
|
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.