This is an example of using AutoMoq.
It requires the use of NUnit and the AutoMoq NuGet packages.
As far as I can see there is no difference between the Create and Resolve methods.
ILSpy confirms that the generic resolve calls the generic create method.
using AutoMoq;
using Moq;
using NUnit.Framework;
namespace TestLib
{
public interface IFoo
{
string Execute();
}
public class Class1
{
private IFoo _foo;
public Class1(IFoo foo)
{
_foo = foo;
}
public string Write()
{
return string.Format(“>{0}<“, _foo.Execute());
}
}
[TestFixture]
public class TestMe
{
AutoMoqer _autoMoqer;
[SetUp]
public void Setup()
{
_autoMoqer = new AutoMoqer();
}
[Test]
public void A()
{
Mock<IFoo> mockFoo = _autoMoqer.GetMock<IFoo>();
mockFoo.Setup(a => a.Execute()).Returns(“Hello”);
Class1 c = _autoMoqer.Create<Class1>();
//Act and Assert
Assert.That(c.Write(), Is.EqualTo(“>Hello<“));
}
[Test]
public void B()
{
var c = _autoMoqer.Resolve<Class1>();
//Act and Assert
Assert.That(c.Write(), Is.EqualTo(“><“));
}
}
}