Skip to content

Commit 45e69f5

Browse files
committed
fixed (?) broken test
1 parent 7fa0e32 commit 45e69f5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

RubberduckTests/ComMock/MockExpressionBuilderTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq.Expressions;
4+
using System.Reflection;
45
using Moq;
56
using NUnit.Framework;
67
using Rubberduck.ComClientLibrary.UnitTesting.Mocks;
@@ -96,19 +97,20 @@ public void SetupWithCallback_Compiles()
9697
[Test]
9798
public void Verify_Compiles()
9899
{
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.
101101

102102
var mock = new Mock<ITest1>();
103103
var builder = MockExpressionBuilder.Create(mock);
104104
var expression = ArrangeSetupDoExpression();
105105

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.
109107

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);
112114
}
113115

114116
private static IReadOnlyDictionary<ParameterExpression, object> ArrangeForwardedArgs()

0 commit comments

Comments
 (0)