From c6fd19b179c8e127e706485fa4e85be3a6142493 Mon Sep 17 00:00:00 2001 From: Ivo Stoilov Date: Tue, 31 Aug 2021 12:28:05 +0300 Subject: [PATCH] OccursNever does not work with InOrder anymore o fixed the case when if one or more arrangements are overwritten by InOrder one --- Telerik.JustMock/Core/MocksRepository.cs | 40 +++++++++++++++--------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Telerik.JustMock/Core/MocksRepository.cs b/Telerik.JustMock/Core/MocksRepository.cs index fe48049d..a45db0ff 100644 --- a/Telerik.JustMock/Core/MocksRepository.cs +++ b/Telerik.JustMock/Core/MocksRepository.cs @@ -1543,21 +1543,33 @@ private IMethodMock GetMethodMockFromNodes(List 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(() => 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(() => 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();