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