Created
January 5, 2018 17:21
-
-
Save JaykeOps/9235fc475311dea781ad09e019a4ccab to your computer and use it in GitHub Desktop.
AutoFixture + AutoMoq
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 AutoFixture; | |
using AutoFixture.AutoMoq; | |
using Moq; | |
using Xunit; | |
namespace AutoFixtureSandbox.Tests | |
{ | |
public class AutoFixtureLearningTests | |
{ | |
[Fact] | |
public void CanSetTestDoubleWithAutoFixtureAutoMoq() | |
{ | |
var fixture = new Fixture(); | |
fixture.Customize(new AutoConfiguredMoqCustomization()); | |
//fixture.Inject<string>("V12"); | |
var mockEngine = fixture.Freeze<Mock<IEngine>>(); | |
var sut = fixture.Create<Car>(); | |
sut.Start(); | |
Assert.NotNull(sut.EngineModel); | |
mockEngine.Verify(engine => engine.Start(), Times.Once); | |
} | |
} | |
public class Car | |
{ | |
private readonly string model; | |
private readonly string make; | |
private readonly int productionYear; | |
private readonly IEngine engine; | |
public Car(string model, string make, int productionYear, IEngine engine) | |
{ | |
this.model = model; | |
this.make = make; | |
this.productionYear = productionYear; | |
this.engine = engine; | |
} | |
public string Model => model; | |
public string Make => make; | |
public int ProductionYear => productionYear; | |
public string EngineModel => engine.Model; | |
public void Start() => engine.Start(); | |
} | |
public interface IEngine | |
{ | |
string Model { get; } | |
void Start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment