예제 #1
0
        public void When_creating_a_student_should_not_leave_any_tracked_components()
        {
            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 createResponse = StudentHelper.CreateStudent(client, DataSeedHelper.RandomName, DataSeedHelper.RandomName);
                        createResponse.ResponseMessage.EnsureSuccessStatusCode();
                        createResponse.ResponseMessage.StatusCode.ShouldBe(HttpStatusCode.Created);
                    }

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

                    trackedComponentCount.ShouldBe(
                        0,
                        "Tracked Components: " + string.Join(", ", trackedComponents.Select(tc => tc.Key.ToString())));
                }
            }
        }
예제 #2
0
        public void When_getting_student_by_id_should_not_leave_any_tracked_components()
        {
            string authorizedStudentUri;

            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,
                            DataSeedHelper.RandomName,
                            DataSeedHelper.RandomName,
                            School1Id);

                        studentCreateResponse.ResponseMessage.EnsureSuccessStatusCode();
                        authorizedStudentUri = studentCreateResponse.ResponseMessage.Headers.Location.AbsoluteUri;
                    }
                }
            }

            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(authorizedStudentUri)
                                               .Result;

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

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

                    trackedComponentCount.ShouldBe(
                        0,
                        "Tracked Components: " + string.Join(", ", trackedComponents.Select(tc => tc.Key.ToString())));
                }
            }
        }
예제 #3
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())));
                }
            }
        }