Written by:8/25/2011 9:12 PM
We left off Part 2 having outlined a skeleton architecture. Today, we will start on the heart of the system, the Business Layer. We’ll also briefly cover the concepts of Domain Driven Design (DDD) and Test Driven Development (TDD). Finally, we’ll expand on the solution and write some code that incorporates these two points. As usual, we will build upon the Great Library project.
Domain Expert: When an Access Centre shuts down, we need to move all the Goods to the nominated Regional Access Warehouse.
Data Driven Developer: Oh, that’s easy. We can just update the FK in the Goods table to the ID of the Regional Access Centre.
Domain Driven Design Developer: Ok. We’ve earlier implemented a way for Access Centres to transfer Goods between them. So, we can simply say that when an Access Centre shuts down we transfer all the Goods to the Regional Access Centre.
Let’s start off and add a Test Project to our solution. To do this:
When Unit Tests are run, each class marked by the [TestClass] attribute will run a test on any method with the [TestMethod] attribute. Expressions are tested using the Assert class, and all Asserts must pass for a method to pass its test. Also, and obviously, each method must Assert at least once to pass. We’ll add the following TestMethod:
[TestMethod]
public
void
CanAddGoodToInventory()
{
Good good =
new
Good();
AccessCentre accessCentre =
AccessCentre();
accessCentre.AddToInventory(good);
bool
expected =
true
;
actual = accessCentre.Inventory.Contains(good);
Assert.AreEqual(expected, actual,
"The Good could not be found in Inventory"
);
}
Right now, we can’t compile as Goods and Access Centres don’t even exist. This follows with the RED step in TDD. So, we’ll move onto GREEN by adding class library to our solution.
class
AccessCentre
#region Properties
IList Inventory {
get
private
set
; }
#endregion
#region Methods
AddToInventory(Good good)
AccessCentre()
Inventory =
List();
Inventory.Add(good);
0 comment(s) so far...