Databases Reference
In-Depth Information
LISTING 8.2 Continued
product.UnitPrice = null;
context.Products.AddObject(product);
context.SaveChanges();
}
}
}
}
The test creates a new NorthwindEntities context object and tries to submit a new Product
instance to the database without a valid UnitPrice . You expect a ValidationException to
be thrown by the SaveChanges method, which is why the ExpectedException attribute
was applied to the test method. Visual Studio reports success if this test method if the test
does throws the expected exception. If the test does not throw an exception or throws an
exception of an unexpected type, a failure is reported.
You can run this and all other tests defined in this test project with the help of the Test
View window shown in Figure 8.7. You can find it under Test Æ Windows in the main
menu of Visual Studio.
FIGURE 8.7 Running tests using the Test View window.
The results of test execution are shown in the Test Results window (see Figure 8.8).
FIGURE 8.8 Examining execution results in the Test Results window.
Test Isolation
Poor encapsulation can cause tests that previously completed successfully to fail. It is one
of the most common reasons developers abandon automated tests. Notice that in the test
shown in Listing 8.2, a TransactionScope around the NorthwindEntities context was
 
Search WWH ::




Custom Search