Ejemplo n.º 1
0
        public void WhenAGETByIdRequestIsSubmittedToTheCompositeWithAnInvalidResourceIdentifier(
            string compositeCategoryName,
            string compositeName,
            string resourceIdentifier)
        {
            // Default the category to test, if not specified
            compositeCategoryName = GetCompositeCategoryName(compositeCategoryName);

            var httpClient = FeatureContext.Current.Get<HttpClient>();

            var pluralizedCompositeName = CompositeTermInflector.MakePlural(compositeName);

            ScenarioContext.Current.Set(pluralizedCompositeName, ScenarioContextKeys.PluralizedCompositeName);

            var uri = OwinUriHelper.BuildCompositeUri(
                string.Format(
                    "{0}/{1}/{2}",
                    compositeCategoryName,
                    pluralizedCompositeName,
                    resourceIdentifier));

            var getResponseMessage = httpClient.GetAsync(uri)
                                               .GetResultSafely();

            // Save the response, and the resource collection name for the scenario
            ScenarioContext.Current.Set(getResponseMessage);
        }
Ejemplo n.º 2
0
        public void WhenAGETByExampleRequestIsSubmittedToTheCompositeUsingTheFollowingParameters(
            string requestPattern,
            string compositeCategoryName,
            string resourceName,
            Table parameters)
        {
            // Default the category to test, if not specified
            compositeCategoryName = GetCompositeCategoryName(compositeCategoryName);

            ScenarioContext.Current.Set(requestPattern, ScenarioContextKeys.RequestPattern);

            var valueByName = parameters.Rows.ToDictionary(
                r => r["Name"],
                r => (object) r["Value"],
                StringComparer.InvariantCultureIgnoreCase);

            ScenarioContext.Current.Set(valueByName, ScenarioContextKeys.RequestParameters);

            var pluralizedCompositeName = CompositeTermInflector.MakePlural(resourceName);
            ScenarioContext.Current.Set(pluralizedCompositeName, ScenarioContextKeys.PluralizedCompositeName);

            var uri = OwinUriHelper.BuildCompositeUri(
                string.Format(
                    "{0}/{1}?{2}",
                    compositeCategoryName,
                    pluralizedCompositeName,
                    string.Join("&", valueByName.Select(kvp => Uri.EscapeDataString(kvp.Key) + "=" + Uri.EscapeDataString(kvp.Value.ToString())))));

            var httpClient = FeatureContext.Current.Get<HttpClient>();

            var getResponseMessage = httpClient.GetAsync(uri)
                                               .GetResultSafely();

            // Save the response, and the resource collection name for the scenario
            ScenarioContext.Current.Set(getResponseMessage);
        }
Ejemplo n.º 3
0
        public void WhenAGetAlldRequestIsSubmittedToTheCompositeWithAFilteredQuery(
            string compositeCategoryName,
            string compositeName,
            string hasParameters)
        {
            var httpClient = FeatureContext.Current.Get<HttpClient>();

            var pluralizedCompositeName = CompositeTermInflector.MakePlural(compositeName);

            compositeCategoryName = GetCompositeCategoryName(compositeCategoryName);

            var queryParameterDictionary = new Dictionary<string, QueryParameterObject>();

            if (!string.IsNullOrEmpty(hasParameters))
            {
                queryParameterDictionary =
                    ScenarioContext.Current.Get<Dictionary<string, QueryParameterObject>>(ScenarioContextKeys.CompositeQueryParameterDictionary);
            }

            ScenarioContext.Current.Set(pluralizedCompositeName, ScenarioContextKeys.PluralizedCompositeName);

            string queryStringParameterText = string.Join(
                "&",

                // Add the criteria 
                queryParameterDictionary.Select(
                                             kvp =>
                                             {
                                                 string parameterName = kvp.Value.Name;

                                                 if (IsDescriptorParameter(kvp.Value.Name))
                                                 {
                                                     parameterName = ScenarioContext.Current.Get<string>(
                                                         ScenarioContextKeys.CompositeQueryStringDescriptorParameter);
                                                 }

                                                 return $"{parameterName}={Uri.EscapeDataString(kvp.Value.Value.ToString())}";
                                             })

                                         // Add the correlation Id
                                        .Concat(
                                             new[]
                                             {
                                                 SpecialQueryStringParameters.CorrelationId + "=" + EstablishRequestCorrelationIdForScenario()
                                             }));

            var uri = OwinUriHelper.BuildCompositeUri(
                string.Format(
                    "{0}/{1}{2}{3}",
                    compositeCategoryName,
                    pluralizedCompositeName,
                    queryStringParameterText.Length > 0
                        ? "?"
                        : string.Empty,
                    queryStringParameterText));

            var getResponseMessage = httpClient.GetAsync(uri)
                                               .GetResultSafely();

            // Save the response, and the resource collection name for the scenario
            ScenarioContext.Current.Set(getResponseMessage);
        }
Ejemplo n.º 4
0
        public void WhenAGETRequestIsSubmittedToTheCompositeWithParameters(
            string requestPattern,
            string compositeCategoryName,
            string compositeName,
            string excludeCorrelationText,
            Table parametersTable)
        {
            ScenarioContext.Current.Set(requestPattern, ScenarioContextKeys.RequestPattern);

            // Default the category to test, if not specified
            compositeCategoryName = GetCompositeCategoryName(compositeCategoryName);

            var httpClient = FeatureContext.Current.Get<HttpClient>();

            var subjectId = ScenarioContext.Current.Get<Guid>(ScenarioContextKeys.CompositeSubjectId);

            var pluralizedCompositeName = CompositeTermInflector.MakePlural(compositeName);

            ScenarioContext.Current.Set(pluralizedCompositeName, ScenarioContextKeys.PluralizedCompositeName);

            bool includeCorrelation = string.IsNullOrEmpty(excludeCorrelationText);

            string requestUrl = null;

            if (requestPattern.EqualsIgnoreCase("id"))
            {
                var dictionary = new Dictionary<string, object>();
                ScenarioContext.Current.Set(dictionary, ScenarioContextKeys.RequestParameters);

                requestUrl = OwinUriHelper.BuildCompositeUri(
                    string.Format(
                        "{0}/{1}/{2}{3}",
                        compositeCategoryName,
                        pluralizedCompositeName,
                        subjectId.ToString("n"),
                        GetQueryString(parametersTable, includeCorrelation)));
            }
            else if (requestPattern.EqualsIgnoreCase("key"))
            {
                var valueByName = parametersTable == null
                    ? ScenarioContext.Current.Get<Dictionary<string, object>>(ScenarioContextKeys.CompositeSubjectKey)
                    : parametersTable.Rows.ToDictionary(
                        r => r["Name"],
                        r => (object) r["Value"],
                        StringComparer.InvariantCultureIgnoreCase);

                ScenarioContext.Current.Set(valueByName, ScenarioContextKeys.RequestParameters);

                requestUrl = OwinUriHelper.BuildCompositeUri(
                    string.Format(
                        "{0}/{1}?{2}",
                        compositeCategoryName,
                        pluralizedCompositeName,
                        string.Join("&", valueByName.Select(kvp => kvp.Key + "=" + Uri.EscapeDataString(kvp.Value.ToString())))));
            }
            else
            {
                throw new NotSupportedException(
                    string.Format("Request pattern '{0}' is not yet explicity supported by the test step definition.", requestPattern));
            }

            if (!includeCorrelation)
            {
                ScenarioContext.Current.Remove(ScenarioContextKeys.RequestCorrelationId);
            }

            var getResponseMessage = httpClient.GetAsync(requestUrl)
                                               .GetResultSafely();

            // Save the response, and the resource collection name for the scenario
            ScenarioContext.Current.Set(getResponseMessage);
        }
Ejemplo n.º 5
0
        public void When_the_request_is_submitted(string requestName)
        {
            var httpClient = FeatureContext.Current.Get <HttpClient>();

            string requestUrl = null;
            Guid   resourceId;

            switch (requestName)
            {
            case "School by Id":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901001
                });

                requestUrl = $"enrollment/schools/{resourceId}";
                break;

            case "Schools by Local Education Agency (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901
                });

                requestUrl = $"enrollment/localEducationAgencies/{resourceId}/schools";
                break;

            case "Schools by Section (Id)":

                resourceId = GetResourceId(
                    "Section",
                    new
                {
                    SectionIdentifier = "25590100101Trad120ENG112011"
                });

                requestUrl = $"enrollment/sections/{resourceId}/schools";
                break;

            case "Schools by Staff (Id)":

                resourceId = GetResourceId(
                    "Staff",
                    new
                {
                    StaffUniqueId = "207268"
                });

                requestUrl = $"enrollment/staffs/{resourceId}/schools";
                break;

            case "Section by Id":

                resourceId = GetResourceId(
                    "Section",
                    new
                {
                    SectionIdentifier = "25590100101Trad120ENG112011"
                });

                requestUrl = $"enrollment/sections/{resourceId}";
                break;

            case "Sections by Local Education Agency (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901
                });

                requestUrl = $"enrollment/localEducationAgencies/{resourceId}/sections";
                break;

            case "Sections by School (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901001
                });

                requestUrl = $"enrollment/schools/{resourceId}/sections";
                break;

            case "Sections by Staff (Id)":

                resourceId = GetResourceId(
                    "Staff",
                    new
                {
                    StaffUniqueId = 207268
                });

                requestUrl = $"enrollment/staffs/{resourceId}/sections";
                break;

            case "Staff by Id":

                resourceId = GetResourceId(
                    "Staff",
                    new
                {
                    StaffUniqueId = "207268"
                });

                requestUrl = $"enrollment/staffs/{resourceId}";
                break;

            case "Staffs by Local Education Agency (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901
                });

                requestUrl = $"enrollment/localEducationAgencies/{resourceId}/staffs";
                break;

            case "Staffs by School (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901001
                });

                requestUrl = $"enrollment/schools/{resourceId}/staffs";
                break;

            case "Staffs by Section (Id)":

                resourceId = GetResourceId(
                    "Section",
                    new
                {
                    SectionIdentifier = "25590100101Trad120ENG112011"
                });

                requestUrl = $"enrollment/sections/{resourceId}/staffs";
                break;

            case "Student by Id":

                resourceId = GetResourceId(
                    "Student",
                    new
                {
                    StudentUniqueId = 605042
                });

                requestUrl = $"enrollment/students/{resourceId}";
                break;

            case "Students by Local Education Agency (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901
                });

                requestUrl = $"enrollment/localEducationAgencies/{resourceId}/students";
                break;

            case "Students by School (Id)":

                resourceId = GetResourceId(
                    "EducationOrganization",
                    new
                {
                    EducationOrganizationId = 255901001
                });

                requestUrl = $"enrollment/schools/{resourceId}/students";
                break;

            case "Students by Section (Id)":

                resourceId = GetResourceId(
                    "Section",
                    new
                {
                    SectionIdentifier = "25590100101Trad120ENG112011"
                });

                requestUrl = $"enrollment/sections/{resourceId}/students";
                break;

            case "Students by Staff (Id)":

                resourceId = GetResourceId(
                    "Staff",
                    new
                {
                    StaffUniqueId = 207268
                });

                requestUrl = $"enrollment/staffs/{resourceId}/students";
                break;

            default:

                throw new NotSupportedException(
                          string.Format("No request definition matched '{0}'.", requestName));
            }

            requestUrl += string.Format(
                "?{0}={1}",
                SpecialQueryStringParameters.CorrelationId,
                CompositeSteps.EstablishRequestCorrelationIdForScenario());

            var uri = OwinUriHelper.BuildCompositeUri(requestUrl);

            var getResponseMessage = httpClient.GetAsync(uri)
                                     .Sync();

            // Save the response, and the resource collection name for the scenario
            ScenarioContext.Current.Set(getResponseMessage);

            string json   = GetContentFromResponse();
            var    logger = LogManager.GetLogger(GetType());

            logger.DebugFormat("JSON response:\r\n{0}", json);
        }