Created
February 13, 2022 10:55
-
-
Save danielwertheim/da4f246a9e76c2f12a1aabcc0ae17790 to your computer and use it in GitHub Desktop.
Autofixture with AutoMoq
This file contains hidden or 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
namespace Tests.UnitTests | |
{ | |
using AutoFixture; | |
using AutoFixture.AutoMoq; | |
using AutoFixture.Xunit2; | |
using System; | |
public class InlineAutoMoqDataAttribute : InlineAutoDataAttribute | |
{ | |
public InlineAutoMoqDataAttribute(params object[] objects) | |
: base(new AutoMoqDataAttribute(), objects) | |
{ | |
} | |
} | |
public class AutoMoqDataAttribute : AutoDataAttribute | |
{ | |
public AutoMoqDataAttribute() | |
: this(null) | |
{ | |
} | |
protected AutoMoqDataAttribute(Action<IFixture>? cfg) | |
: base(() => | |
{ | |
var fixture = new Fixture(); | |
fixture.Customize(new AutoMoqCustomization | |
{ | |
ConfigureMembers = true, | |
GenerateDelegates = true, | |
}); | |
cfg?.Invoke(fixture); | |
return fixture; | |
}) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment