Exploring the sample applications

During the development of the CSLA templates, we thought what better way to test the templates than to write a sample application. So we wrote a working PetShop Sample application in C# and Visual Basic that can be downloaded here

Please make sure that you update the connection string to point to a local PetShop database instance.

We took the PetShop sample applications a step further by writing unit tests against the generated code. You can find unit tests for all the business object types and Data Access Layer implementations. This is a great starting point for learning more about the generated code.

These NUnit tests will give you a good understanding of how different operations are performed in CSLA. Feel free to contact support or our forums with any unit tests you think we don't have.  If you find a bug in the CSLA templates, its a huge help to the community and us if you submit a failing unit test for the PetShop sample application that can reproduce your bug. This ensures we have more test ability and no regressions in future versions. However, any unit test will be appreciated along with the respected sample schema.

When contributing new unit tests, please try to follow our common testing pattern for consistency that outputs a description and how long it took to run the test. Below is an example of one of our unit tests.

public void Step_01_Insert_Duplicate()
{
    Console.WriteLine("1. Testing Duplicate Records.");
    Stopwatch watch = Stopwatch.StartNew();
    //Insert should fail as there should be a duplicate key.
    Category category = Category.NewCategory();
    category.CategoryId = TestCategoryID;
    category.Name = TestUtility.Instance.RandomString(80, false);
    category.Description = TestUtility.Instance.RandomString(255, false);
    try
    {
        Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString());
        category = category.Save();
        // Fail as a duplicate record was entered.
        Assert.Fail("Fail as a duplicate record was entered and an exception was not thrown.");
    }
    catch (Exception)
    {
        Assert.IsTrue(true);
    }
    Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds);
}