public ProviderServiceInteraction GetMatchingTestScopedInteraction(ProviderServiceRequest request) { if (TestScopedInteractions == null || !TestScopedInteractions.Any()) { throw new PactFailureException(String.Format("No interaction found for {0} {1}.", request.Method.ToString().ToUpperInvariant(), request.Path)); } var matchingInteractions = new List <ProviderServiceInteraction>(); foreach (var testScopedInteraction in TestScopedInteractions) { var requestComparisonResult = _requestComparer.Compare(testScopedInteraction.Request, request); if (requestComparisonResult != null && !requestComparisonResult.HasFailure) { matchingInteractions.Add(testScopedInteraction); } } if (matchingInteractions == null || !matchingInteractions.Any()) { throw new PactFailureException(String.Format("No interaction found for {0} {1}.", request.Method.ToString().ToUpperInvariant(), request.Path)); } if (matchingInteractions.Count() > 1) { throw new PactFailureException(String.Format("More than one interaction found for {0} {1}.", request.Method.ToString().ToUpperInvariant(), request.Path)); } return(matchingInteractions.Single()); }
public ProviderServiceInteraction GetMatchingTestScopedInteraction(ProviderServiceRequest request) { if (TestScopedInteractions == null || !TestScopedInteractions.Any()) { throw new PactFailureException("No mock interactions have been registered"); } var matchingInteractions = new List <ProviderServiceInteraction>(); foreach (var testScopedInteraction in TestScopedInteractions) { _requestComparer.Compare(testScopedInteraction.Request, request); try { _reporter.ThrowIfAnyErrors(); } catch (Exception) { _reporter.ClearErrors(); continue; } matchingInteractions.Add(testScopedInteraction); } if (matchingInteractions == null || !matchingInteractions.Any()) { throw new PactFailureException("No matching mock interaction has been registered for the current request"); } if (matchingInteractions.Count() > 1) { throw new PactFailureException("More than one matching mock interaction has been registered for the current request"); } return(matchingInteractions.Single()); }
public ProviderServiceInteraction GetMatchingTestScopedInteraction(HttpVerb method, string pathWithQuery) { if (TestScopedInteractions == null || !TestScopedInteractions.Any()) { throw new PactFailureException("No mock interactions have been registered"); } var matchingInteractions = TestScopedInteractions.Where(x => x.Request != null && x.Request.Method == method && x.Request.PathWithQuery() == pathWithQuery).ToList(); if (matchingInteractions == null || !matchingInteractions.Any()) { throw new PactFailureException("No matching mock interaction has been registered for the current request"); } if (matchingInteractions.Count() > 1) { throw new PactFailureException("More than one matching mock interaction has been registered for the current request"); } return(matchingInteractions.Single()); }