Ejemplo n.º 1
0
            public void When_verifying_at_or_above_call_count_should_be_true(int verifyCount, bool expected)
            {
                IsSent atLeastOnce = IsSent.AtLeastOnce();

                // Assert
                atLeastOnce.Verify(verifyCount).Should().Be(expected);
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Verifies that a request matching the specified match conditions has been sent.
        /// </summary>
        /// <param name="matching">The conditions to match.</param>
        /// <param name="times">The number of times a request is allowed to be sent.</param>
        /// <param name="because">The reasoning for this expectation.</param>
        public async Task VerifyAsync(Action <RequestMatching> matching, IsSent times, string because = null)
        {
            if (matching is null)
            {
                throw new ArgumentNullException(nameof(matching));
            }

            if (times is null)
            {
                times = IsSent.AtLeastOnce();
            }

            var rm = new RequestMatching();

            matching(rm);

            IReadOnlyCollection <IAsyncHttpRequestMatcher> matchers        = rm.Build();
            IReadOnlyList <IInvokedHttpRequest>            matchedRequests = InvokedRequests;

            if (matchers.Count > 0)
            {
                var list = new List <IInvokedHttpRequest>();
                foreach (IInvokedHttpRequest invokedHttpRequest in InvokedRequests)
                {
                    var requestContext = new MockHttpRequestContext(invokedHttpRequest.Request);
                    if (await matchers.AllAsync(requestContext).ConfigureAwait(false))
                    {
                        list.Add(invokedHttpRequest);
                    }
                }

                matchedRequests = list;
            }

            if (!times.Verify(matchedRequests.Count))
            {
                throw new HttpMockException(times.GetErrorMessage(matchedRequests.Count, BecauseMessage(because)));
            }

            foreach (InvokedHttpRequest r in matchedRequests.Cast <InvokedHttpRequest>())
            {
                r.MarkAsVerified();
            }
        }