Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using NUnit
Message
 
To
10/10/2008 11:24:33
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Environment versions
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01354100
Message ID:
01354249
Views:
17
Mick,

>I have also dove straight into NUnit to have Unit tests that can be run to make sure you haven't broke anything. I have created tests for most scenarios, except delete. What is a good way to to dest the delete of entities with NUnit? Can someone who is doing this regularly show me a bit of code?

You could do something like this which creates a new entity, saves it, retrieves it, then deletes it. Notice the use of TransactionBegin() and TransactionRollback() which allows you to run this test over again since the newly created entity is removed from the database when TransactionRollback() is issued.
[Test]
public void DeleteEntity()
{
	try
	{
		this.Order.TransactionBegin();
		OrderEntity Entity = Order.NewEntity();
		Entity.CustomerID = "QUICK";
		Entity.ShipName = "QUICK Ship Name";
		Assert.IsTrue(Order.SaveEntity() == mmSaveDataResult.RulesPassed, "Rules broken");

		int orderID = orderEntity.OrderID;

		orderEntity = Order.GetOrderByOrderID(orderID);
		Assert.IsTrue(orderEntity.HasValues, "New entity not created / retrieved");

		Order.Delete(orderEntity.OrderID);

		orderEntity = Order.GetOrderByOrderID(orderID);
		Assert.IsFalse(orderEntity.HasValues, "Entity not deleted");
	}
	catch (Exception e)
	{
		throw;
	}
	finally
	{
		this.Order.TransactionRollback();
	}
}
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform