-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorTest.cs
More file actions
69 lines (56 loc) · 2.12 KB
/
Copy pathCalculatorTest.cs
File metadata and controls
69 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using ExampleUnitTest.APP;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace ExampleUnitTest.Test
{
public class CalculatorTest
{
public Calculator calculator { get; set; }
public Mock<ICalculatorService> calculatorMock { get; set; }
public CalculatorTest()
{
//IcalculatorService implement ettiği CalculatorService i taklit edecek.
calculatorMock = new Mock<ICalculatorService>();
calculator = new Calculator(calculatorMock.Object);
//calculator = new Calculator(new CalculatorService());
}
[Theory]
[InlineData(2,5,7)]
[InlineData(2,3,5)]
public void Add_SimpleValues_ReturnTotalValue(int a, int b, int expectedTotal)
{
//eğer add metodu çağırılırsa return olarak expectedTotal dön diyoruz
calculatorMock.Setup(x=>x.add(a,b)).Returns(expectedTotal);
var actualTotal = calculator.add(a, b);
Assert.Equal(expectedTotal, actualTotal);
//Times.one 1 kere çalışmış olsun diyoruz
//times.never hiç çalışmazsa demek
//times atleast kaç kere çağrıldığını sorar
calculatorMock.Verify(x => x.add(a, b), Times.AtLeast(1));
}
[Theory]
[InlineData(2, 0, 0)]
[InlineData(0, 6, 0)]
public void Add_ZeroValues_ReturnTotalValue(int a, int b, int expectedTotal)
{
var actualTotal = calculator.add(a, b);
Assert.Equal(expectedTotal, actualTotal);
}
[Theory]
[InlineData(2, 6, 8)]
public void Add_CustomValues_ReturnTotalValue(int a, int b, int expectedTotal)
{
int actualTotal = 0;
calculatorMock.Setup(x => x.add(It.IsAny<int>(), It.IsAny<int>())).Callback<int,int>((x,y) => actualTotal = x + y);
calculator.add(a, b);
Assert.Equal(expectedTotal, actualTotal);
calculator.add(5, 20);
Assert.Equal(25, actualTotal);
}
}
}