Skip to content

Commit d2f2b6c

Browse files
committed
Merge pull request #32 from Particular/hotfix-5.1.1
Change Validate to run all checks for type
2 parents ce651b6 + 92507a7 commit d2f2b6c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/NServiceBus.Testing.Tests/InvocationTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ public void DeferMessageBasicNegative()
171171

172172
exp.Validate(i);
173173
}
174+
175+
[Test]
176+
public void RunAllInvocations()
177+
{
178+
var invocationCount = 0;
179+
180+
var i = new PublishInvocation<MessageA> { Message = new MessageA() };
181+
var j = new PublishInvocation<MessageA> { Message = new MessageA() };
182+
var exp = new ExpectedPublishInvocation<MessageA> { Check = m => { invocationCount++; return true; } };
183+
184+
exp.Validate(i, j);
185+
186+
Assert.That(() => invocationCount, Is.EqualTo(2));
187+
}
174188
}
175189

176190
public class MessageA

src/NServiceBus.Testing/Invocations.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ abstract class ExpectedInvocation<T> : IExpectedInvocation where T : ActualInvoc
1515
{
1616
public void Validate(params ActualInvocation[] invocations)
1717
{
18-
var calls = invocations.Where(i => typeof(T) == i.GetType());
19-
var success = calls.Any(c =>
20-
{
21-
var result = Validate(c as T);
22-
23-
return result;
24-
});
18+
var calls = invocations.Where(i => typeof(T) == i.GetType()).Cast<T>();
19+
var callResults = calls.Select(c => Validate(c)).ToArray(); // Force enumeration
20+
21+
var success = callResults.Any(result => result);
2522

2623
if ((!success && !Negate) || (Negate && success))
2724
throw new Exception(string.Format("{0} not fulfilled.\nCalls made:\n{1}", filter(GetType()), string.Join("\n", invocations.Select(i => filter(i.GetType())))));

0 commit comments

Comments
 (0)