Click here to Skip to main content
12,630,455 members (28,696 online)
Click here to Skip to main content
Articles » Database » Database » Utilities » Downloads

Stats

57.6K views
1K downloads
67 bookmarked
Posted

DataTable Synchronization Manager

, 4 Mar 2006
Adds synchronization to the DataTable Transaction Logger.
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Marc Clifton
United States United States
Marc is the creator of two open source projects, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.

Marc lives in Philmont, NY.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 4 Mar 2006
Article Copyright 2006 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid