Skip to content

Commit

Permalink
Merge pull request #158 from telerik/stoilov/fix-inorder-overwrite
Browse files Browse the repository at this point in the history
OccursNever does not work with InOrder anymore
  • Loading branch information
mihail-vladov authored Sep 2, 2021
2 parents 5c7cc5f + c6fd19b commit 2b11e90
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions Telerik.JustMock/Core/MocksRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,21 +1543,33 @@ private IMethodMock GetMethodMockFromNodes(List<MethodMockMatcherTreeNode> metho
return null;
}

var resultsQ =
from node in methodMockNodes
orderby node.Id
select new
var resultList =
methodMockNodes
.OrderBy(x => x.Id)
.Select(
x =>
new
{
x.MethodMock,
Acceptable = new Lazy<bool>(() => x.MethodMock.AcceptCondition == null
|| (bool)x.MethodMock.AcceptCondition.CallOverride(invocation))
})
.ToList();

var isInOrderOverwrites =
resultList.Count() > 0
&& resultList.Where(x => x.MethodMock.IsInOrder).Any()
&& resultList.Last().MethodMock.IsInOrder;

// if one or more InOrder arrangement overwrites other ones, then skip selecting others
if (!isInOrderOverwrites)
{
var nonSequentialOrInOrder =
resultList.Where(x => !x.MethodMock.IsSequential && !x.MethodMock.IsInOrder && x.Acceptable).LastOrDefault();
if (nonSequentialOrInOrder != null)
{
node.MethodMock,
Acceptable = new Lazy<bool>(() => node.MethodMock.AcceptCondition == null || (bool)node.MethodMock.AcceptCondition.CallOverride(invocation))
};

var resultList = resultsQ.ToList();

var nonSequentialOrInOrder = resultList.Where(x => !x.MethodMock.IsSequential && !x.MethodMock.IsInOrder && x.Acceptable).LastOrDefault();
if (nonSequentialOrInOrder != null)
{
return nonSequentialOrInOrder.MethodMock;
return nonSequentialOrInOrder.MethodMock;
}
}

var inOrder = resultList.Where(x => x.MethodMock.IsInOrder && !x.MethodMock.IsUsed && x.Acceptable).FirstOrDefault();
Expand Down

0 comments on commit 2b11e90

Please sign in to comment.