I'm trying to Mock my Linq To Sql database context, with little luck:
How do I mock System.Data.Linq.Table? Where am I going wrong.
System.InvalidCastException:
'System.Collections.Generic.List`1[My.Models.Person]' to type 'System.Data.Linq.Table`1[My.Models.Person]'
var logic =
new
PersonLogic();
var context = Mock.Create<DataContext>();
var persons=
new
List<Person>();
persons.Add(
new
Person());
Mock.Arrange(() => (IEnumerable<Person>)context.Persons).Returns(persons);
Mock.NonPublic.Arrange<DataContext>(logic,
"context"
).Returns(context);
Person returned = logic.GetPerson(1);
Assert.Equals(returned.ID, 1);
How do I mock System.Data.Linq.Table? Where am I going wrong.