/// <summary> /// Resets this mock's state. This includes its setups, configured default return values, and all recorded invocations. /// </summary> public void Reset() { InvokedRequests.Clear(); _fallbackSetup.Reset(); _setups.Clear(); Fallback.Respond(_ => CreateDefaultResponse()); }
/// <summary> /// Verifies that there were no requests sent other than those already verified. /// </summary> public void VerifyNoOtherRequests() { List <InvokedHttpRequest> unverifiedRequests = InvokedRequests .Cast <InvokedHttpRequest>() .Where(r => !r.IsVerified) .ToList(); if (!unverifiedRequests.Any()) { return; } string unverifiedRequestsStr = string.Join(Environment.NewLine, unverifiedRequests.Select(ir => ir.Request.ToString())); throw new HttpMockException($"There are {unverifiedRequests.Count} unverified requests:{Environment.NewLine}{unverifiedRequestsStr}"); }
private void Verify(IEnumerable <HttpCall> verifiableSetups) { List <HttpCall> expectedInvocations = verifiableSetups .Where(setup => !setup.VerifyIfInvoked()) .ToList(); if (!expectedInvocations.Any()) { return; } string invokedRequestsStr = string.Join(Environment.NewLine, InvokedRequests.Select(ir => ir.Request.ToString())); if (invokedRequestsStr.Length > 0) { invokedRequestsStr = Environment.NewLine + "Seen requests: " + invokedRequestsStr; } throw new HttpMockException($"There are {expectedInvocations.Count} unfulfilled expectations:{Environment.NewLine}{string.Join(Environment.NewLine, expectedInvocations.Select(r => '\t' + r.ToString()))}{invokedRequestsStr}"); }