LINQ to SQL and Unit Testing
To a point, LINQ to SQL works well with unit testing. When the LINQ-to-SQL objects are in a detached state (either not submitted to the database, or detached through the detach command) and there isn't a chance of accidentally updating records or creating new records to the database, LINQ to SQL works really well with unit testing. Take a look at this example:
Customer customer = new Customer();
customer.Orders.Add(new Order { OrderKey = 1, TotalAmount = 20, OrderDate = DateTime.Now });
customer.Orders.Add(new Order { OrderKey = 2, TotalAmount = 19.50, OrderDate = DateTime.Now });
customer.Reviews.Add(new Review { ReviewKey = 1, ReviewText = "OK" })
customer.Reviews.Add(new Review { ReviewKey = 2, ReviewText = "Liked it" });
At this point, no object has been submitted to the database, or is attached to the data context, so this unit test is isolated. Although it can be a pain to setup all of the objects needed for a test, it can be done. You can start processing the test as follows:
CustomerBAL.ProcessOrders(customer);
foreach (Order order in customer.Orders)
Assert.AreEqual(true, order.IsSubmitted);
And so on. As long as the components interacting with the objects don't submit the data to the database, or do anything outlandish with the objects, this approach will work well in unit testing.