Exemple #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));
        }
Exemple #2
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));
        }
Exemple #3
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));
        }