Last active
November 1, 2016 00:07
-
-
Save mattwcole/c1ff12429f3f2126e8004151afd58628 to your computer and use it in GitHub Desktop.
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 System; | |
using Autofac.Extras.Moq; | |
using Moq; | |
using NUnit.Framework; | |
namespace Sandbox | |
{ | |
public class AutoMockFunctionTests | |
{ | |
[Test] | |
public void FooTest() | |
{ | |
using (var autoMock = AutoMock.GetLoose()) | |
{ | |
var foo = Mock.Of<IFoo>(f => f.DoFoo() == "fooResult"); | |
Func<string, IFoo> fooFactory = x => foo; | |
autoMock.Provide(fooFactory); | |
var sut = autoMock.Create<ClassUnderTest>(); | |
var result = sut.Do("factoryParam"); | |
Assert.That(result, Is.EqualTo("fooResult")); | |
} | |
} | |
} | |
public class ClassUnderTest | |
{ | |
private readonly Func<string, IFoo> _fooFactory; | |
public ClassUnderTest(Func<string, IFoo> fooFactory) | |
{ | |
_fooFactory = fooFactory; | |
} | |
public string Do(string value) | |
{ | |
var foo = _fooFactory(value); | |
return foo.DoFoo(); | |
} | |
} | |
public interface IFoo | |
{ | |
string DoFoo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment