Пример #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> 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"));
        }