Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TDD the Bizobj
Message
De
19/11/2003 20:20:08
 
 
À
11/11/2003 18:08:59
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Divers
Thread ID:
00848909
Message ID:
00851703
Vues:
80
Further adventures:
I've gone round and round with my TDD adventures, and I realize that many of my problems have to do with my level of understanding (read lack of) of C# and MM.net. Yet, right now, I have a Solution that consists of 2 projects:
1. mmApplication which is the main project and contains the following a main.cs based on the MM windows forms main.cs, but without the windows stuff.
2. the second project is the standard Orders Business Object to which I've added some tests (see below). In this TestFixture the first two tests are
successful, but the second two fail with:
TestCase 'Acme.OrderSystem.Business.TestOrders.TestDataSet' failed: System.NullReferenceException : Object reference not set to an instance of an object.
Since I check to make sure that the app is running first in my tests i'm not sure why this isn't working -
Any ideas?

Mike

1. mmApplication
-----------------------------------------------
using System;
using System.Data;


using OakLeaf.MM.Main;
using OakLeaf.MM.Main.Patterns;
using OakLeaf.MM.Main.Managers;
using OakLeaf.MM.Main.Data;
//using OakLeaf.MM.Main.Windows.Forms;
//using OakLeaf.MM.NorthwindSample.Main.Windows.Forms;
using Acme.OrderSystem.Business;


namespace mmApplication
{
	/// <summary>
	/// Main application entry class
	/// </summary>
	class AppMainEntry : mmMainEntry
	{
		/// <summary>
		/// Static field that contains a reference to the application object
		/// </summary>
		public static mmApplication.AppBase App;
	
		/// <summary>
		/// Main application entry point
		/// </summary>
		public static void Main()
		{
			try
			{
				// Instantiate the Application Object
				App = new AppBase();

				// Instantiate the Order 
				Acme.OrderSystem.Business.Orders  orders = new Acme.OrderSystem.Business.Orders();

				// Get a dataset
				mmDataSet ds;
				ds = orders.GetAllOrders();
				
				// Instantiate the main application form
//				Application.Run(new MainForm());


			}
			catch (Exception e)
			{
				// Write the error to the application log
				mmAppBase.Log.WriteException(e);

				// Display the Exception form
				//mmExceptionForm ExceptForm = new mmExceptionForm(e.Message, e.StackTrace);
				//ExceptForm.ShowDialog();
			}
			finally
			{
			}
		}
	}
}
----------------------------------------
2. Orders.cs
using System;
using System.Data;
using System.Xml;

using OakLeaf.MM.Main;
using OakLeaf.MM.Main.Patterns;
using OakLeaf.MM.Main.Managers;
using OakLeaf.MM.Main.Business;
using OakLeaf.MM.Main.Data;

using NUnit.Framework;

//using mmApplication;

namespace Acme.OrderSystem.Business
{
	/// <summary>
	/// Summary description for Orders.
	/// </summary>
	public class Orders : ABusinessObject 
	{
		public Orders()
		{
			this.TableName = "Orders";
			this.PrimaryKey = "OrderID";

		}
		public DataSet GetOrdersByCustomerID(string customerID)
		{
			return this.GetDataSet("SELECT * From Orders WHERE CustomerID = '" +
				customerID + "'");
		}

		public DataSet GetOrderByOrderID(int orderID)
		{
			return this.GetDataSet("SELECT * FROM Orders WHERE OrderID = " + orderID);
		}

		public mmDataSet GetAllOrders()
		{
			DataSet ds = new DataSet();
			return (mmDataSet) this.GetDataSet("Select * from Orders");
		}
	
	}
	

	[TestFixture]
	public class TestOrders
	{
		public Orders orders;
		public mmAppBase app;

		[TestFixtureSetUp]
		public void Setup()
		{
			this.app = new mmAppBase();
			this.orders = new Orders();
			
		}

		[Test]
		public void IsAppRunning()
		{
			Assert.IsTrue( mmAppBase.IsRunning );
		}

		[Test]
		public void TestTableName()
		{
			Assert.AreEqual( "Orders", orders.TableName );
		}

		[Test]
		public void TestDataSet()
		{
			DataSet ds = orders.GetAllOrders();
			Assert.AreEqual(false, ds.HasChanges() );
		}
		[Test]
		public void TestGetAllOrders()
		{
			DataSet ds = orders.GetAllOrders();
			Assert.AreEqual(ds.Tables["Orders"].Rows.Count, 0 ); 
		}
	}
}
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform