Ejemplo n.º 1
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();
            }
        }