Class to be unit tested:
public class A
{
B _objectB;
C _objectC;
public A(B objectB, C objectC)
{
_objectB = objectB;
_objectC = objectC;
}
public virtual int Operation(int number1, int number2)
{
int result = 0;
result += _objectB.Multiply(number1, number2);
result += _objectC.Divide(number1, number2);
return result;
}
}
Unit test:
using Xunit;
public class ATest
{
[Fact]
public void Operation_WithCorrectParameters_ShouldPass()
{
//Arrange
int number1 = 10;
int number2 = 5;
var sut = new A(new B(), new C());
//Act
var result = sut.Operation(number1, number2);
//Assert
Assert.Equal(52, result);
}
}
public class A
{
B _objectB;
C _objectC;
public A(B objectB, C objectC)
{
_objectB = objectB;
_objectC = objectC;
}
public virtual int Operation(int number1, int number2)
{
int result = 0;
result += _objectB.Multiply(number1, number2);
result += _objectC.Divide(number1, number2);
return result;
}
}
Unit test:
using Xunit;
public class ATest
{
[Fact]
public void Operation_WithCorrectParameters_ShouldPass()
{
//Arrange
int number1 = 10;
int number2 = 5;
var sut = new A(new B(), new C());
//Act
var result = sut.Operation(number1, number2);
//Assert
Assert.Equal(52, result);
}
}
No comments:
Post a Comment