-
Notifications
You must be signed in to change notification settings - Fork 5
/
FluentMockMethodVerifier.cs
46 lines (34 loc) · 1.65 KB
/
FluentMockMethodVerifier.cs
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
using System;
using System.Linq.Expressions;
using Moq;
namespace SparkyTestHelpers.Moq
{
public class FluentMockMethodVerifier<T> : FluentMockVerifier where T : class
{
public Expression<Action<T>> Expression { get; }
private readonly Mock<T> _mock;
internal FluentMockMethodVerifier(Mock<T> mock, Expression<Action<T>> methodExpression)
{
_mock = mock;
Expression = methodExpression;
}
internal override void ShouldHaveBeenCalled()
=> _mock.Verify(Expression);
internal override void ShouldHaveBeenCalledOnce()
=> _mock.Verify(Expression, Times.Once);
internal override void ShouldHaveBeenCalledAtLeastOnce()
=> _mock.Verify(Expression, Times.AtLeastOnce);
internal override void ShouldHaveBeenCalledAtMostOnce()
=> _mock.Verify(Expression, Times.AtMostOnce);
internal override void ShouldHaveCallCount(int callCount) =>
_mock.Verify(Expression, Times.Exactly(callCount));
internal override void ShouldHaveCallCountBetween(int callCountFrom, int callCountTo, Range rangeKind = Range.Inclusive)
=> _mock.Verify(Expression, Times.Between(callCountFrom, callCountTo, rangeKind));
internal override void ShouldHaveCallCountOfAtLeast(int callCount)
=> _mock.Verify(Expression, Times.AtLeast(callCount));
internal override void ShouldHaveCallCountOfAtMost(int callCount)
=> _mock.Verify(Expression, Times.AtMost(callCount));
internal override void ShouldNotHaveBeenCalled() =>
_mock.Verify(Expression, Times.Never);
}
}