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); }
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); }
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); } } } }
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); }
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); }
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); }
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 }); }
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()); }
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); }
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 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); }
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); }
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(); } }
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); }