Created
October 19, 2011 14:06
-
-
Save giggio/1298381 to your computer and use it in GitHub Desktop.
AutoMoq problem when calling twice in a very specific scenario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AutoMoq; | |
using NUnit.Framework; | |
namespace TestProject1 | |
{ | |
[TestFixture] | |
public class UnitTest1 | |
{ | |
readonly AutoMoqer mocker = new AutoMoqer(); | |
private SomeController controller; | |
private const string Id = "the id"; | |
[SetUp] | |
public void Setup() | |
{ | |
var profile = new Profile(); | |
controller = mocker.Create<SomeController>(); | |
mocker.GetMock<IProfilerGetter>().Setup(p => p.Get(Id)).Returns(profile); | |
} | |
[Test] | |
public void CanAMockGeneratedByAutomoqBeCalledOnce() | |
{ | |
var p1 = controller.Get(Id); | |
Assert.IsNotNull(p1); | |
} | |
[Test] | |
public void CanAMockGeneratedByAutomoqBeCalledTwice() | |
{ | |
var p2 = controller.Get(Id); | |
Assert.IsNotNull(p2); | |
} | |
} | |
public class SomeController | |
{ | |
private readonly IProfilerGetter profilerGetter; | |
public SomeController(IProfilerGetter profilerGetter) | |
{ | |
this.profilerGetter = profilerGetter; | |
} | |
public Profile Get(string id) | |
{ | |
return profilerGetter.Get(id); | |
} | |
} | |
public interface IProfilerGetter | |
{ | |
Profile Get(string id); | |
} | |
public class Profile | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment