Esempio n. 1
0
        public void Compare(ProviderServiceRequest request1, ProviderServiceRequest request2)
        {
            if (request1 == null)
            {
                throw new CompareFailedException("Expected request cannot be null");
            }

            _httpMethodComparer.Compare(request1.Method, request2.Method);

            _httpPathComparer.Compare(request1.Path, request2.Path);

            _httpQueryStringComparer.Compare(request1.Query, request2.Query);

            if (request1.Headers != null && request1.Headers.Any())
            {
                if (request2.Headers == null)
                {
                    throw new CompareFailedException("Headers are null");
                }

                _httpHeaderComparer.Compare(request1.Headers, request2.Headers);
            }

            if (request1.Body != null)
            {
                _httpBodyComparer.Validate(request2.Body, request1.Body, true);
            }
        }
        public void Compare(ProviderServiceRequest expected, ProviderServiceRequest actual)
        {
            if (expected == null)
            {
                _reporter.ReportError("Expected request cannot be null");
                return;
            }

            _httpMethodComparer.Compare(expected.Method, actual.Method);

            _httpPathComparer.Compare(expected.Path, actual.Path);

            _httpQueryStringComparer.Compare(expected.Query, actual.Query);

            if (expected.Headers != null && expected.Headers.Any())
            {
                if (actual.Headers == null)
                {
                    _reporter.ReportError("Headers are null");
                }

                _httpHeaderComparer.Compare(expected.Headers, actual.Headers);
            }

            if (expected.Body != null)
            {
                _httpBodyComparer.Validate(expected.Body, actual.Body, true);
            }
        }
        public ComparisonResult Compare(ProviderServiceRequest expected, ProviderServiceRequest actual)
        {
            var result = new ComparisonResult("sends a request which");

            if (expected == null)
            {
                result.RecordFailure(new ErrorMessageComparisonFailure("Expected request cannot be null"));
                return(result);
            }

            var methodResult = _httpMethodComparer.Compare(expected.Method, actual.Method);

            result.AddChildResult(methodResult);

            var pathResult = _httpPathComparer.Compare(expected.Path, actual.Path);

            result.AddChildResult(pathResult);

            var queryResult = _httpQueryStringComparer.Compare(expected.Query, actual.Query);

            result.AddChildResult(queryResult);

            if (expected.Headers != null && expected.Headers.Any())
            {
                var headerResult = _httpHeaderComparer.Compare(expected.Headers, actual.Headers);
                result.AddChildResult(headerResult);
            }

            if (expected.Body != null)
            {
                var bodyResult = _httpBodyComparer.Compare(expected.Body, actual.Body, expected.MatchingRules);
                result.AddChildResult(bodyResult);
            }
            else if (expected.Body == null &&
                     expected.ShouldSerializeBody() && //Body was explicitly set
                     actual.Body != null)
            {
                result.RecordFailure(new ErrorMessageComparisonFailure("Expected request body was explicitly set to null however the actual request body was not null"));
            }

            return(result);
        }