Lazy Exceptions for Fake LINQ Queries
Posted by: K. Scott Allen,
on 22 Jun 2011 |
View original | Bookmarked: 0 time(s)
If you want to simulate an exception from an IQueryable data source, be careful about when the exception is thrown. As an example, let's use the following interface. public interface IContext
{
IQueryable<Person> People { get; set; }
}
To simulate an IllegalOperationException from the data source, you might setup a mock with the following code.
var mockContext = new Mock<IContext>();
mockContext.SetupGet(c => c.People)
.Throws<InvalidOperationException>();
But,...