Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using NUnit
Message
 
À
10/10/2008 11:24:33
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Versions des environnements
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01354100
Message ID:
01354249
Vues:
18
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform