Language: C#
Testing Entity Framework Models (Entities) with Type Mock Live Objects
namespace Repository.EntityFramework { //Entity Class Under Test public partial class Story { public ICollection<Tag> Tags { get { if(!TagsInternal.IsLoaded) { TagsInternal.Load(); } return TagsInternal; } } } } namespace KiGG.Repository.EntityFramework.Tests { //Test Class [Isolated] public class StoryFixture { private readonly Story _story; public StoryFixture() { _story = new Story(); } [Fact] public void Tags_Should_Call_Load_When_IsLoaded_Is_False() { //Arrange Fake Method Calls on Live Object -None Faked Instance- Isolate.WhenCalled(() => _story.TagsInternal.IsLoaded).WillReturn(false); Isolate.WhenCalled(() => _story.TagsInternal.Load()).IgnoreCall(); //Act ICollection<Tag> tags = _story.Tags; //Assert Isolate.Verify .WasCalledWithAnyArguments(()=>_story.TagsInternal.Load()); } } }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

