I am trying to create a simple setup for xUnit. At the moment, the function does not access to database.
So, here is my structure: I have 2 projects in my solution. First is my class library which is going to be the function to be used by the callee. The function is plus and minus 2 numbers for simplicity reason.
namespace XUnitSample.ClassLib.Interfaces
{
public interface ICal
{
int Add(int num1, int num2);
int Minus(int num1, int num2);
}
}
namespace XUnitSample.ClassLib
{
public class Cal : ICal
{
public int Add(int num1, int num2) => num1 + num2;
public int Minus(int num1, int num2) => num1 - num2;
}
}
and the second project is the xUnit test project
namespace XUnitSample.Lib
{
public class CalTest
{
[Fact]
public void Add_Add2Numbers()
{
var mock = new Mock<ICal>();
mock.Setup(x => x.Add(1, 1)).Returns(2);
}
[Theory]
[InlineData(1,2,3)]
[InlineData(1, 1, 2)]
[InlineData(1, 0, 1)]
public void Add_Add2Numbers_Theory(int num1, int num2, int expected)
{
var result = new Cal().Add(num1, num2);
Assert.Equal(expected, result);
}
[Fact]
public void Minus_Minus2Numbers()
{
var mock = new Mock<ICal>();
mock.Setup(x => x.Minus(1, 1)).Returns(0);
}
}
}
All 3 unit test can be run successfully. Any comments on this structure and good practices?