Skip to content

Instantly share code, notes, and snippets.

@giggio
Created October 19, 2011 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giggio/1298381 to your computer and use it in GitHub Desktop.
Save giggio/1298381 to your computer and use it in GitHub Desktop.
AutoMoq problem when calling twice in a very specific scenario
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