Exploring the sample applications

The CSLA templates come with a working PetShop sample application, in C# and Visual Basic. To get it, see Downloading the CSLA templates.

Note

Update the connection string to point to your local PetShop database.

The PetShop sample website, showing the Birds category

Unit tests

The PetShop samples include unit tests for the generated code, covering every business object type and data access layer implementation. They're a great starting point for learning how the generated code works and how CSLA performs each operation.

Unit test results for the PetShop parameterized SQL tests: 31 tests passed

The tests use NUnit. Each test follows the same pattern: it writes a description and how long it took to run. Here's one of them:

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);
}

Report a bug with a test

If you find a bug in the CSLA templates, a failing unit test against the PetShop sample that reproduces it helps a lot, along with the sample schema it needs. Open an issue on GitHub with your test. Please follow the same pattern as the existing tests.