Skip to content

Instantly share code, notes, and snippets.

@JaykeOps
Created January 5, 2018 11:41
Show Gist options
  • Save JaykeOps/a93d73cf8394a924bb6ed6c753682733 to your computer and use it in GitHub Desktop.
Save JaykeOps/a93d73cf8394a924bb6ed6c753682733 to your computer and use it in GitHub Desktop.
AutoFixture - Populating Theory InlineData with anonymous data and SUT
using Ploeh.AutoFixture.Xunit2;
using Xunit;
namespace AutoFixtureSandbox.Tests
{
public class AutoFixtureLearningTests
{
[Theory]
[AutoData]
public void CanAddNumber(decimal x, Calculator sut)
{
sut.AddDecimal(x);
Assert.Equal(sut.Value, x);
}
//Test will run three times even if it isn't shown in test list
[Theory]
[InlineAutoData]
[InlineAutoData]
[InlineAutoData(-100)] //Input x will be -100
public void CanAddNumberTwoTimes(decimal x, decimal y, Calculator sut)
{
sut.AddDecimal(x);
sut.AddDecimal(y);
Assert.Equal(sut.Value, x + y);
}
}
public class Calculator
{
private decimal value;
public void AddDecimal(decimal x) => value += x;
public decimal Value => value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment