|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq.Expressions; |
| 4 | +using System.Reflection; |
4 | 5 | using Moq; |
5 | 6 | using NUnit.Framework; |
6 | 7 | using Rubberduck.ComClientLibrary.UnitTesting.Mocks; |
@@ -96,19 +97,20 @@ public void SetupWithCallback_Compiles() |
96 | 97 | [Test] |
97 | 98 | public void Verify_Compiles() |
98 | 99 | { |
99 | | - const int expected = 1; |
100 | | - var expectedTimes = Moq.Times.Once().ToRubberduckTimes(); |
| 100 | + // Moq.Mock<T>.Verify throws if it's invoked and the verification fails. |
101 | 101 |
|
102 | 102 | var mock = new Mock<ITest1>(); |
103 | 103 | var builder = MockExpressionBuilder.Create(mock); |
104 | 104 | var expression = ArrangeSetupDoExpression(); |
105 | 105 |
|
106 | | - builder.As(typeof(ITest1)) |
107 | | - .Verify(expression, expectedTimes, ArrangeForwardedArgs()) |
108 | | - .Execute(); |
| 106 | + var badTimes = Moq.Times.Once().ToRubberduckTimes(); // test would be inconclusive with exactly 1 invoke. |
109 | 107 |
|
110 | | - mock.Object.Do(); |
111 | | - Assert.AreEqual(expected, mock.Invocations.Count); |
| 108 | + // inner exception would be the MockException. |
| 109 | + var exception = Assert.Catch<TargetInvocationException>(() => |
| 110 | + builder.As(typeof(ITest1)) |
| 111 | + .Verify(expression, badTimes, ArrangeForwardedArgs()) |
| 112 | + .Execute()); |
| 113 | + Assert.IsTrue(exception.InnerException is MockException); |
112 | 114 | } |
113 | 115 |
|
114 | 116 | private static IReadOnlyDictionary<ParameterExpression, object> ArrangeForwardedArgs() |
|
0 commit comments