Ejemplo n.º 1
0
        public override void SetUp()
        {
            base.SetUp();

            // Client-supplied resource id using PUT (legacy 2.x behavior that should now fail)
            using (var startup = new UniqueIdIntegrationOwinTestStartup(
                       DatabaseName, DefaultLocalEducationAgencyIds,
                       // Configure WITHOUT UniqueId integration
                       useUniqueIdIntegration: false))
            {
                using (var server = TestServer.Create(startup.Configuration))
                {
                    using (var client = new HttpClient(server.Handler))
                    {
                        client.Timeout = new TimeSpan(0, 0, 15, 0);

                        client.DefaultRequestHeaders.Authorization
                            = new AuthenticationHeaderValue("Bearer", Guid.NewGuid().ToString());

                        // Attempt to PUT (create) the Student resource using client-supplied resourceId in URL
                        // (legacy 2.x behavior that should now fail)
                        var student = CreateStudentJson();

                        string url = OwinUriHelper.BuildOdsUri("students");
                        string clientAssignedId = Guid.NewGuid().ToString("n");

                        _actualResponseForCreateUsingPutWithoutUniqueIdIntegration = Put(client, student, url, clientAssignedId);
                    }
                }
            }

            // Server-supplied resource id using UniqueId integration
            using (var startup = new UniqueIdIntegrationOwinTestStartup(
                       DatabaseName, DefaultLocalEducationAgencyIds,
                       // Configure WITH UniqueId integration
                       useUniqueIdIntegration: true))
            {
                using (var server = TestServer.Create(startup.Configuration))
                {
                    using (var client = new HttpClient(server.Handler))
                    {
                        client.Timeout = new TimeSpan(0, 0, 15, 0);

                        client.DefaultRequestHeaders.Authorization
                            = new AuthenticationHeaderValue("Bearer", Guid.NewGuid().ToString());

                        var    student = CreateStudentJson();
                        string url     = OwinUriHelper.BuildOdsUri("students");

                        // Attempt to PUT (create) the Student resource using client-supplied resourceId in URL
                        // (legacy 2.x behavior that should now fail)
                        string clientAssignedId = Guid.NewGuid().ToString("n");
                        _actualResponseForCreateUsingPutWithUniqueIdIntegration = Put(client, student, url, clientAssignedId);

                        // Attempt to POST the student (with server-supplied resourceId from UniqueId integration)
                        _actualResponseForCreateUsingPostWithUniqueIdIntegration = Post(client, student, url);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Should_Get_Dependencies()
        {
            string dependenciesResult;

            using (var startup = new OwinStartup(DatabaseName, DefaultLocalEducationAgencyIds))
            {
                using (var server = TestServer.Create(startup.Configuration))
                {
                    using (var client = new HttpClient(server.Handler))
                    {
                        client.Timeout = new TimeSpan(0, 0, 15, 0);

                        client.DefaultRequestHeaders.Authorization =
                            new AuthenticationHeaderValue("Bearer", Guid.NewGuid().ToString());

                        var dependencies = client.GetAsync(OwinUriHelper.BuildOdsUri("dependencies", null, null, true))
                                           .GetResultSafely();

                        dependencies.EnsureSuccessStatusCode();

                        dependenciesResult = dependencies.Content.ReadAsStringAsync().GetResultSafely();
                    }
                }
            }

            dependenciesResult.ShouldNotBeNullOrEmpty();
            Approvals.Verify(dependenciesResult);
        }
Ejemplo n.º 3
0
        WhenAPUTRequestWithACollectionContainingOnlyConformingIncludedOrExcludedTypeValuesIsSubmittedToSchoolsWithARequestBodyContentTypeOfTheAppropriateValueForTheProfileInUse(
            ConformanceType conformanceType,
            IncludedOrExcluded includedOrExcluded,
            string typeOrDescriptor,
            string resourceCollectionName,
            string contentType)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                contentType = ProfilesContentTypeHelper.CreateContentType(
                    resourceCollectionName,
                    ScenarioContext.Current.Get <string>(ScenarioContextKeys.ProfileName),
                    ContentTypeUsage.Writable);
            }

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

            httpClient.DefaultRequestHeaders.Clear();
            var container = FeatureContext.Current.Get <IWindsorContainer>();

            HttpContent putRequestContent = null;
            Guid        id = Guid.NewGuid();

            switch (resourceCollectionName)
            {
            case "schools":
                putRequestContent = GetSchoolPutRequestContent(id, contentType, conformanceType, includedOrExcluded, container, httpClient);
                break;

            case "studentAssessments":

                putRequestContent = GetStudentAssessmentPutRequestContent(
                    id,
                    contentType,
                    conformanceType,
                    includedOrExcluded,
                    container,
                    httpClient);

                break;

            default:
                throw new NotSupportedException();
            }

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                "Bearer",
                Guid.NewGuid()
                .ToString());

            // Post resource, using the Profile's content type
            var putResponseMessage = httpClient.PutAsync(OwinUriHelper.BuildOdsUri(resourceCollectionName + "/" + id), putRequestContent)
                                     .Sync();

            ScenarioContext.Current.Set(putResponseMessage);
        }
Ejemplo n.º 4
0
        internal static HttpResponseMessage CreateProgram(HttpClient client, int leaId, string name = null)
        {
            name = name ?? DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);

            var postBody = new StringContent(ResourceHelper.CreateProgram(leaId, name), Encoding.UTF8, "application/json");

            var createResponse = client.PostAsync(OwinUriHelper.BuildOdsUri("programs"), postBody).GetResultSafely();

            return(createResponse);
        }
Ejemplo n.º 5
0
        internal static PersonHelperResponse CreateStudentAndAssociateToSchool(HttpClient client, string lastName, string firstName, int schoolId)
        {
            var studentResponse = CreateStudent(client, lastName, firstName);

            if (studentResponse.ResponseMessage.IsSuccessStatusCode)
            {
                client.PostAsync(
                    OwinUriHelper.BuildOdsUri("StudentSchoolAssociations"),
                    new StringContent(
                        ResourceHelper.CreateStudentSchoolAssociation(studentResponse.UniqueId, schoolId),
                        Encoding.UTF8,
                        "application/json"), CancellationToken.None).WaitSafely();
            }

            return(studentResponse);
        }
Ejemplo n.º 6
0
        internal static PersonHelperResponse CreatePerson(HttpClient client, string resource, string lastName, string firstName)
        {
            var uniqueId = Guid.NewGuid()
                           .ToString("N");

            var createResponse = client.PostAsync(
                OwinUriHelper.BuildOdsUri(resource),
                new StringContent(
                    CreateResource(resource, uniqueId, lastName, firstName),
                    Encoding.UTF8,
                    "application/json"), CancellationToken.None).GetResultSafely();

            return(new PersonHelperResponse
            {
                ResponseMessage = createResponse, UniqueId = uniqueId
            });
        }
Ejemplo n.º 7
0
        internal static HttpResponseMessage CreateStudentParentAssociation(HttpClient client, string studentUniqueId, string parentUniqueId)
        {
            var association = new StudentParentAssociation
            {
                StudentReference = new StudentReference
                {
                    StudentUniqueId = studentUniqueId
                },
                ParentReference = new ParentReference
                {
                    ParentUniqueId = parentUniqueId
                }
            };

            return(client.PostAsync(
                       OwinUriHelper.BuildOdsUri("StudentParentAssociations"),
                       new StringContent(JsonConvert.SerializeObject(association), Encoding.UTF8, "application/json"), CancellationToken.None)
                   .GetResultSafely());
        }
Ejemplo n.º 8
0
        public void When_getting_student_by_example_should_not_leave_any_tracked_components()
        {
            var authorizedFirstName = "John";
            var authorizedLastName  = string.Format("A{0}", DataSeedHelper.RandomName);

            var unauthorizedFirstName = "Other";
            var unauthorizedLastName  = string.Format("U{0}", DataSeedHelper.RandomName);

            var localEducationAgencyIds = new List <int>
            {
                Lea1Id, Lea2Id
            };

            using (var startup = new OwinStartup(DatabaseName, localEducationAgencyIds))
            {
                using (var server = TestServer.Create(startup.Configuration))
                {
                    using (var client = new HttpClient(server.Handler))
                    {
                        client.Timeout = DefaultHttpClientTimeout;

                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                            "Bearer",
                            Guid.NewGuid()
                            .ToString());

                        //1st Student
                        var studentCreateResponse = StudentHelper.CreateStudentAndAssociateToSchool(
                            client,
                            authorizedLastName,
                            authorizedFirstName,
                            School1Id);

                        studentCreateResponse.ResponseMessage.EnsureSuccessStatusCode();

                        //2nd Student
                        studentCreateResponse = StudentHelper.CreateStudentAndAssociateToSchool(
                            client,
                            unauthorizedLastName,
                            unauthorizedFirstName,
                            School2Id);

                        studentCreateResponse.ResponseMessage.EnsureSuccessStatusCode();
                    }
                }
            }

            localEducationAgencyIds = new List <int>
            {
                Lea1Id
            };

            using (var startup = new OwinStartup(DatabaseName, localEducationAgencyIds))
            {
                var trackedComponents     = startup.GetTrackedComponents();
                int trackedComponentCount = trackedComponents.Count();
                trackedComponentCount.ShouldBe(0);

                using (var server = TestServer.Create(startup.Configuration))
                {
                    using (var client = new HttpClient(server.Handler))
                    {
                        client.Timeout = DefaultHttpClientTimeout;

                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                            "Bearer",
                            Guid.NewGuid()
                            .ToString());

                        var authorizedResult = client
                                               .GetAsync(OwinUriHelper.BuildOdsUri("students", queryString: $"LastSurname={authorizedLastName}"))
                                               .Result;

                        authorizedResult.EnsureSuccessStatusCode();
                        authorizedResult.StatusCode.ShouldBe(HttpStatusCode.OK);

                        var students = DefaultTestJsonSerializer.DeserializeObject <Student[]>(
                            authorizedResult.Content.ReadAsStringAsync()
                            .Result);

                        students.Length.ShouldBe(1);

                        students[0]
                        .FirstName.ShouldBe(authorizedFirstName);

                        var unauthorizedResult = client
                                                 .GetAsync(OwinUriHelper.BuildOdsUri("students", queryString: $"LastSurname={unauthorizedLastName}"))
                                                 .Result;

                        unauthorizedResult.StatusCode.ShouldBe(HttpStatusCode.OK);

                        students = DefaultTestJsonSerializer.DeserializeObject <Student[]>(
                            unauthorizedResult.Content.ReadAsStringAsync()
                            .Result);

                        students.Length.ShouldBe(0);
                    }

                    trackedComponents     = startup.GetTrackedComponents();
                    trackedComponentCount = trackedComponents.Count();

                    trackedComponentCount.ShouldBe(
                        0,
                        "Tracked Components: " + string.Join(", ", trackedComponents.Select(tc => tc.Key.ToString())));
                }
            }
        }
Ejemplo n.º 9
0
        public void Should_update_specified_instance_db()
        {
            Trace.Listeners.Clear();

            // with the change in school year we need to send each year as a separate request so the context will change correctly.
            // should the context provider be set when the request comes into the controller? Currently it appears it is not being set.
            using (var server = TestServer.Create <OwinStartup>())
            {
                string uniqueId2014;
                string uniqueId2015;

                using (var client = new HttpClient(server.Handler))
                {
                    client.Timeout = new TimeSpan(0, 0, 15, 0);

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                        "Bearer",
                        Guid.NewGuid()
                        .ToString());

                    // create 2014
                    var uniqueId2014Response = client.PostAsync(
                        OwinUriHelper.BuildIdentityUri("identities", 2014),
                        new StringContent(
                            JsonConvert.SerializeObject(
                                UniqueIdCreator
                                .InitializeAPersonWithUniqueData()),
                            Encoding.UTF8,
                            "application/json"))
                                               .GetResultSafely();

                    uniqueId2014 = UniqueIdCreator.ExtractIdFromHttpResponse(uniqueId2014Response);

                    var create2014Response = client.PostAsync(
                        OwinUriHelper.BuildOdsUri("students", 2014),
                        new StringContent(
                            ResourceHelper.CreateStudent(
                                uniqueId2014,
                                DateTime.Now.Ticks.ToString(
                                    CultureInfo.InvariantCulture),
                                DateTime.Now.Ticks.ToString(
                                    CultureInfo.InvariantCulture)),
                            Encoding.UTF8,
                            "application/json"))
                                             .GetResultSafely();

                    create2014Response.EnsureSuccessStatusCode();

                    // create 2015
                    var uniqueId2015Response = client.PostAsync(
                        OwinUriHelper.BuildIdentityUri("identities", 2015),
                        new StringContent(
                            JsonConvert.SerializeObject(
                                UniqueIdCreator
                                .InitializeAPersonWithUniqueData()),
                            Encoding.UTF8,
                            "application/json"))
                                               .GetResultSafely();

                    uniqueId2015 = UniqueIdCreator.ExtractIdFromHttpResponse(uniqueId2015Response);

                    var create2015Response = client.PostAsync(
                        OwinUriHelper.BuildOdsUri("students", 2015),
                        new StringContent(
                            ResourceHelper.CreateStudent(
                                uniqueId2015,
                                DateTime.Now.Ticks.ToString(
                                    CultureInfo.InvariantCulture),
                                DateTime.Now.Ticks.ToString(
                                    CultureInfo.InvariantCulture)),
                            Encoding.UTF8,
                            "application/json"))
                                             .GetResultSafely();

                    create2015Response.EnsureSuccessStatusCode();
                }

                StudentExists(2014, uniqueId2014)
                .ShouldBeTrue();

                StudentExists(2015, uniqueId2014)
                .ShouldBeFalse();

                StudentExists(2014, uniqueId2015)
                .ShouldBeFalse();

                StudentExists(2015, uniqueId2015)
                .ShouldBeTrue();
            }
        }