示例#1
0
        /// <summary>
        /// Gets set of assertions that verify if creation operation meets convention.
        /// E.g. if created element is returned properly from Web API or if POST method is used, etc.
        /// </summary>
        public static IEnumerable <IAssertion> CreateResource()
        {
            // Request
            foreach (var assertion in ApiConventionFor.CreationRequest())
            {
                yield return(assertion);
            }

            // Response
            yield return(ApiConventionFor.ResponseStatusIs(HttpStatusCode.Created));

            yield return(new VerifyResponseHeader(
                             "Location",
                             (operation, value)
                             =>
            {
                if (String.IsNullOrWhiteSpace(value) == false)
                {
                    return Assertion.Ok;
                }

                return Assertion.Failure(
                    $"There is no 'Location' header returned in response:\n\n{operation.Response.ToHttpLook()}"
                    );
            })
                         .Expected("Convention: Location header (pointing to newly created element) is returned with response."));

            yield return(ApiConventionFor.ResponseContentTypeIs(MediaTypeNames.Application.Json));
        }
示例#2
0
        public static IEnumerable <IAssertion> Http404NotFound()
        {
            // Request
            yield return(ApiConventionFor.RequestMethodIs(HttpMethod.Get));

            // Response
            yield return(ApiConventionFor.ResponseStatusIs(HttpStatusCode.NotFound));
        }
示例#3
0
        public static IEnumerable <IAssertion> GetListOfResources()
        {
            // Request
            yield return(ApiConventionFor.RequestMethodIs(HttpMethod.Get));

            // Response
            yield return(ApiConventionFor.ResponseStatusIs(HttpStatusCode.OK));

            yield return(ApiConventionFor.ResponseContentTypeIs(MediaTypeNames.Application.Json));
        }
示例#4
0
        public static IEnumerable <IAssertion> GetSingleResourceThatDoNotExist()
        {
            // Request
            yield return(ApiConventionFor.RequestMethodIs(HttpMethod.Get));

            // Response
            yield return(ApiConventionFor.ResponseStatusIs(HttpStatusCode.NotFound));

            yield return(ApiConventionFor.ResponseContentTypeIs(MediaType.Application.ProblemJson));
        }
示例#5
0
        private static IEnumerable <IAssertion> BadRequest()
        {
            yield return(ApiConventionFor.ResponseStatusIs(HttpStatusCode.BadRequest));

            yield return(new VerifyResponseBody("title", (operation, token) => ApiConventionFor.ValidateIfNodeExists(operation, token, "title"))
                         .Expected("Convention: error JSON contains \"title\" node"));

            yield return(new VerifyResponseBody("traceId", (operation, token) => ApiConventionFor.ValidateIfNodeExists(operation, token, "traceId"))
                         .Expected("Convention: error JSON contains \"traceId\" node"));

            // TODO: Add other ProblemDetails fields
        }
示例#6
0
        public static IEnumerable <IAssertion> CreateResourceWithValidationError()
        {
            foreach (var assertion in ApiConventionFor.CreationRequest().Concat(ApiConventionFor.BadRequest()))
            {
                yield return(assertion);
            }

            yield return(new VerifyResponseHeader(
                             "Location",
                             (operation, value)
                             =>
            {
                if (String.IsNullOrWhiteSpace(value))
                {
                    return Assertion.Ok;
                }

                return Assertion.Failure(
                    $"There is 'Location' header returned in response and it shouldn't be:\n\n{operation.Response.ToHttpLook()}"
                    );
            }).Expected("Convention: There is NO \"Location\" header returned in response"));
        }
示例#7
0
 private static IEnumerable <IAssertion> CreationRequest()
 {
     yield return(ApiConventionFor.RequestMethodIs(HttpMethod.Post));
 }