Created
January 5, 2018 11:41
-
-
Save JaykeOps/a93d73cf8394a924bb6ed6c753682733 to your computer and use it in GitHub Desktop.
AutoFixture - Populating Theory InlineData with anonymous data and SUT
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 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