Databases Reference
In-Depth Information
FIGURE 8.6 Adding a new unit test to the project.
You can now create your first test, or test method, to verify that the UnitPrice property of
the Product entity is required at the same time the entity instance is saved to the database.
Listing 8.2 shows the complete implementation of this test. As you can see, the test
method is called UnitPrice_IsRequired , with an underscore serving as a separator
between the name of the property under test and the description of the test itself. Because
you could have multiple tests for the same property, using underscores helps to organize
the test methods in logical groups.
LISTING 8.2 Testing Required UnitPrice Proper ty of the Product Entity
using System.ComponentModel.DataAnnotations;
using System.Transactions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DataModel
{
[TestClass]
public class ProductTest
{
[TestMethod]
[ExpectedException(typeof(ValidationException))]
public void UnitPrice_IsRequired()
{
using (new TransactionScope())
using (NorthwindEntities context = new NorthwindEntities())
{
var product = new Product();
Search WWH ::




Custom Search