protected override void Act()
            {
                var json = @"
                    {
                        ""id"" : ""00000000000000000000000000000000"",
                        ""schoolReference"" : null,
                        ""sessionReference"" : {
                            ""schoolId"" : 123,
                            ""sessionName"" : ""ABC"",
                            ""schoolYear"" : 2013,
                            ""link"" : {
                                ""rel"" : ""Session"",
                                ""href"" : ""/sessions?schoolId=123&schoolYear=2013""
                            }
                        },
                        ""studentReference"" : null,
                        ""eventDate"" : ""0001-01-01"",
                        ""attendanceEventCategoryDescriptor"" : null,
                        ""attendanceEventReason"" : null,
                        ""educationalEnvironmentType"" : null,
                        ""_etag"" : null
                    }
                ";

                _model = DefaultTestJsonSerializer.DeserializeObject <StudentSchoolAttendanceEvent>(json);
            }
            public void Should_throw_format_exception(string dateTimeValue)
            {
                Should.Throw <FormatException>(
                    () =>
                    DefaultTestJsonSerializer.DeserializeObject <DateTimes>(
                        @"
{
    ""DateTimeOnly"":""" + dateTimeValue + @"""
}"));
            }
Esempio n. 3
0
            public void Should_return_student()
            {
                _responseMessage.StatusCode.ShouldBe(HttpStatusCode.OK);

                var result = _responseMessage.Content.ReadAsStringAsync()
                             .GetResultSafely();

                var resource = DefaultTestJsonSerializer.DeserializeObject <Student>(result);

                resource.Id.ShouldBe(_id);
            }
            protected override void ExecuteBehavior()
            {
                nullableDateTimes = DefaultTestJsonSerializer.DeserializeObject <DateTimes>(
                    @"
{
    ""DateTimeOnly"":""2014-08-01"",
    ""NullableDateTimeOnly"":null
}");

                serializedJsonForNullableDateTimes = JsonConvert.SerializeObject(nullableDateTimes);
            }
Esempio n. 5
0
            public void Should_return_student()
            {
                _responseMessage.StatusCode.ShouldBe(HttpStatusCode.OK);

                var result = _responseMessage.Content.ReadAsStringAsync()
                             .Result;

                var students = DefaultTestJsonSerializer.DeserializeObject <Student[]>(result);

                students.Length.ShouldBe(10);
            }
            protected override void Arrange()
            {
                datetimes = DefaultTestJsonSerializer.DeserializeObject <DateTimes>(
                    @"
                     {
                         ""DateTimeOnly"":""2014-08-01"",
                         ""NullableDateTimeOnly"":""2014-08-01""
                     }");

                serializedJson = JsonConvert.SerializeObject(datetimes);
            }
            public void Should_deserialize_to_valid_value(string dateTimeValue, int?expectedYear, int?expectedMonth, int?expectedDay)
            {
                var dateTimesObject = DefaultTestJsonSerializer.DeserializeObject <DateTimes>(
                    @"
{
    ""DateTimeOnly"":""" + dateTimeValue + @"""
}");

                var now = DateTime.Now;

                Assert.That(dateTimesObject.DateTimeOnly, Is.EqualTo(new DateTime(expectedYear ?? now.Year, expectedMonth ?? now.Month, expectedDay ?? now.Day)));
            }
            [TestCase("2014/08", 2014, 08, 01)] // YYYY/MM
            public void Should_deserialize_to_valid_value(string dateTimeValue, int?expectedYear, int?expectedMonth, int?expectedDay)
            {
                // NOTE the spec revised 2019 states the format is year, month, day https://en.wikipedia.org/wiki/ISO_8601
                var dateTimesObject = DefaultTestJsonSerializer.DeserializeObject <DateTimes>(
                    @"
                     {
                         ""DateTimeOnly"":""" + dateTimeValue + @"""
                     }");

                var now = DateTime.Now;

                Assert.That(dateTimesObject.DateTimeOnly, Is.EqualTo(new DateTime(expectedYear ?? now.Year, expectedMonth ?? now.Month, expectedDay ?? now.Day)));
            }
            protected override void ExecuteBehavior()
            {
                try
                {
                    deserializedObject = DefaultTestJsonSerializer.DeserializeObject <DateTimes>(
                        @"
{
    ""DateTimeOnly"":""2014-08-01T07:57:32Z""
}");
                }
                catch (Exception e)
                {
                    expectedException = e;
                }
            }
Esempio n. 10
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())));
                }
            }
        }
            public void Should_not_introduce_a_partially_defined_reference_on_JSON_deserialization()
            {
                var deserializedModel = DefaultTestJsonSerializer.DeserializeObject <StaffEducationOrganizationAssignmentAssociation>(_actualSerializedJson);

                deserializedModel.EmploymentStaffEducationOrganizationEmploymentAssociationReference.ShouldBeNull();
            }