Skip to content

Instantly share code, notes, and snippets.

@moodmosaic
Last active December 16, 2015 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moodmosaic/5434611 to your computer and use it in GitHub Desktop.
Save moodmosaic/5434611 to your computer and use it in GitHub Desktop.
A discussion branch for a question on Stack Overflow about using AutoFixture declaratively.
// http://stackoverflow.com/questions/16145284/autofixture-how-to-express-the-following-code-declaratively/16145954?noredirect=1#16145284
public class Tests
{
[Theory]
[InlineAutoMockData(@"-o=C:\Temp\someFile -p=1")]
[InlineAutoMockData(@"-p=1 -o=C:\Temp\someFile")]
public void ParseMissingParameterShouldReturnCorrectResult(
string argsString,
SomeClass sut)
{
}
[Theory]
[InlineAutoMockData(@"-o=C:\Temp\someFile -p=1")]
[InlineAutoMockData(@"-p=1 -o=C:\Temp\someFile")]
public void ParseMissingParameterShouldReturnCorrectResult2(
string argsString,
[Frozen]Mock<IFoo> mock,
[Frozen]Mock<IBar> stub,
SomeClass sut)
{
}
}
internal class InlineAutoMockDataAttribute : CompositeDataAttribute
{
internal InlineAutoMockDataAttribute(params object[] values)
: base(
new InlineDataAttribute(values),
new AutoDataAttribute(
new Fixture().Customize(
new CompositeCustomization(
new AutoFakeItEasyCustomization()))))
{
}
}
public class SomeClass : IQux
{
private readonly IFoo foo;
public SomeClass(IFoo foo)
{
this.foo = foo;
}
public IFoo Foo
{
get { return this.foo; }
}
}
public interface IQux
{
}
public interface IFoo
{
}
public interface IBar
{
}
public class Foo : IFoo
{
public Foo(IBar bar)
{
}
}
public class Bar : IBar
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment