Here is a sample I am working with. My repository works with a LINQ data context against SQL Server 2008. I would like to assert that my repository works without actually adding records to the database. I am not sure I am doing the correctly. I would like to write tests for my Add, Edit, Delete, and List functions. This is about as simple as it gets for repo's. Can you give me a hand figuring this out?
I have interfaces and classes for my problem domain; and interfaces and classes for my repositories. What must I do to mock my repositories for testing?
Thanks,
John
I have interfaces and classes for my problem domain; and interfaces and classes for my repositories. What must I do to mock my repositories for testing?
[TestFixture] |
class TextHTMLRepositoryTests |
{ |
TextHTMLRepository _repo; |
[TestFixtureSetUp] |
public void TestSetup() |
{ |
_repo = Mock.Create<TextHTMLRepository>(); |
} |
[Test] |
public void CreateMockRepo() |
{ |
Assert.IsNotNull(_repo); |
} |
[Test] |
public void NullListTest() |
{ |
var _texts = _repo.List(); |
Assert.IsNull(_texts); |
} |
[Test] |
public void PostTest() // This test fails |
{ |
TextHTML _text = Mock.Create<TextHTML>(); |
_text.TextID = 1; |
Mock.Assert(() => _repo.Post(_text)); |
} |
[TestFixtureTearDown] |
public void TestTearDown() |
{ |
// TODO: Tear down loose objects |
} |
} |
Thanks,
John