public async Task Should_get_education_organization_identifiers_for_a_user_lea_context() { // Arrange var sessionFactory = A.Fake <ISessionFactory>(); var session = A.Fake <IStatelessSession>(); A.CallTo(() => sessionFactory.OpenStatelessSession()) .Returns(session); // info schema validation to get all the columns var schemaSqlQuery = A.Fake <ISQLQuery>(); A.CallTo(() => session.CreateSQLQuery(A <string> .That.Contains("information_schema.columns"))) .Returns(schemaSqlQuery); A.CallTo(() => schemaSqlQuery.ListAsync <string>(CancellationToken.None)) .Returns(new List <string>()); // setting up education organization identifier calls, need to guarantee we are using the same object for each call. var edOrgIdentifierSqlQuery = A.Fake <ISQLQuery>(); A.CallTo(() => session.CreateSQLQuery(A <string> .That.Contains("auth.educationorganizationidentifiers"))) .Returns(edOrgIdentifierSqlQuery); A.CallTo( () => edOrgIdentifierSqlQuery.SetResultTransformer( Transformers.AliasToBean <EducationOrganizationIdentifiers>())) .Returns(edOrgIdentifierSqlQuery); A.CallTo(() => edOrgIdentifierSqlQuery.ListAsync <EducationOrganizationIdentifiers>(CancellationToken.None)) .Returns(CreateEducationOrganizationIdentifiers()); // Act var tokenInfoProvider = new TokenInfoProvider(sessionFactory); var results = await tokenInfoProvider.GetTokenInfoAsync(CreateApiContext()); // Assert // validate we went down the path A.CallTo(() => sessionFactory.OpenStatelessSession()) .MustHaveHappenedOnceExactly(); A.CallTo(() => session.CreateSQLQuery(A <string> .That.Contains("information_schema.columns"))) .MustHaveHappenedOnceExactly(); A.CallTo(() => schemaSqlQuery.ListAsync <string>(CancellationToken.None)) .MustHaveHappenedOnceExactly(); A.CallTo(() => session.CreateSQLQuery(A <string> .That.Contains("auth.educationorganizationidentifiers"))) .MustHaveHappenedOnceExactly(); A.CallTo(() => edOrgIdentifierSqlQuery.ListAsync <EducationOrganizationIdentifiers>(CancellationToken.None)) .MustHaveHappenedOnceExactly(); // validate we have a valid object results.ShouldNotBeNull(); results.NamespacePrefixes.Count().ShouldBe(1); results.AssignedProfiles.ShouldBeEmpty(); results.EducationOrganizations.Count().ShouldBe(2); }
public async Task Should_get_education_organization_identifiers_for_a_user_lea_context() { // Arrange var sessionFactory = A.Fake <ISessionFactory>(); var session = A.Fake <IStatelessSession>(); A.CallTo(() => sessionFactory.OpenStatelessSession()) .Returns(session); // setting up education organization identifier calls, need to guarantee we are using the same object for each call. var edOrgIdentifierSqlQuery = A.Fake <ISQLQuery>(); A.CallTo(() => session.CreateSQLQuery(A <string> .That.Contains("auth.EducationOrganizationIdToEducationOrganizationId"))) .Returns(edOrgIdentifierSqlQuery); A.CallTo( () => edOrgIdentifierSqlQuery.SetResultTransformer( Transformers.AliasToBean <TokenInfoEducationOrganizationData>())) .Returns(edOrgIdentifierSqlQuery); A.CallTo(() => edOrgIdentifierSqlQuery.ListAsync <TokenInfoEducationOrganizationData>(CancellationToken.None)) .Returns(CreateEducationOrganizationIdentifiers()); // Act var tokenInfoProvider = new TokenInfoProvider(sessionFactory); var results = await tokenInfoProvider.GetTokenInfoAsync(CreateApiContext()); // Assert // validate we went down the path A.CallTo(() => sessionFactory.OpenStatelessSession()) .MustHaveHappenedOnceExactly(); A.CallTo(() => session.CreateSQLQuery(A <string> .That.Contains("auth.EducationOrganizationIdToEducationOrganizationId"))) .MustHaveHappenedOnceExactly(); A.CallTo(() => edOrgIdentifierSqlQuery.ListAsync <TokenInfoEducationOrganizationData>(CancellationToken.None)) .MustHaveHappenedOnceExactly(); var postSecondaryEntry = results.EducationOrganizations.SingleOrDefault(d => d["education_organization_id"].Equals(6000203)); var communityProviderEntry = results.EducationOrganizations.SingleOrDefault(d => d["education_organization_id"].Equals(19255901)); var schoolEntry = results.EducationOrganizations.SingleOrDefault(d => d["education_organization_id"].Equals(255901107)); results.EducationOrganizations.ShouldSatisfyAllConditions( // validate we have a valid object () => results.ShouldNotBeNull(), () => results.NamespacePrefixes.Count().ShouldBe(1), () => results.AssignedProfiles.ShouldBeEmpty(), // Verify correct preparation of the Education Organization data () => results.EducationOrganizations.Count().ShouldBe(3), // Verify the entries () => postSecondaryEntry.ShouldNotBeNull(), () => communityProviderEntry.ShouldNotBeNull(), () => schoolEntry.ShouldNotBeNull(), // --------------------------- // Verify post-secondary entry // --------------------------- () => postSecondaryEntry.Count.ShouldBe(4), () => postSecondaryEntry["name_of_institution"].ShouldBe("The University of Texas at Austin"), () => postSecondaryEntry["type"].ShouldBe("edfi.PostSecondaryInstitution"), () => postSecondaryEntry["education_organization_id"].ShouldBe(6000203), // Verify post-secondary entry's concrete education organization identifiers () => postSecondaryEntry["post_secondary_institution_id"].ShouldBe(6000203), // -------------------------------- // Verify community provider entry // -------------------------------- () => communityProviderEntry.Count.ShouldBe(5), () => communityProviderEntry["name_of_institution"].ShouldBe("Communities in Schools of Grand Bend"), () => communityProviderEntry["type"].ShouldBe("edfi.CommunityProvider"), () => communityProviderEntry["education_organization_id"].ShouldBe(19255901), // Verify community provider entry's concrete education organization identifiers () => communityProviderEntry["community_provider_id"].ShouldBe(19255901), () => communityProviderEntry["community_organization_id"].ShouldBe(19), // -------------------------------- // Verify school entry // -------------------------------- () => schoolEntry.Count.ShouldBe(6), () => schoolEntry["name_of_institution"].ShouldBe("Grand Bend Elementary School"), () => schoolEntry["type"].ShouldBe("edfi.School"), () => schoolEntry["education_organization_id"].ShouldBe(255901107), // Verify school entry's concrete education organization identifiers () => schoolEntry["school_id"].ShouldBe(255901107), () => schoolEntry["local_education_agency_id"].ShouldBe(255901), () => schoolEntry["education_service_center_id"].ShouldBe(255950) ); /* For reference: Expected JSON output * "education_organizations": [ * { * "education_organization_id": 19255901, * "name_of_institution": "Communities in Schools of Grand Bend", * "type": "edfi.CommunityProvider", * "community_organization_id": 19, * "community_provider_id": 19255901 * }, * { * "education_organization_id": 255901107, * "name_of_institution": "Grand Bend Elementary School", * "type": "edfi.School", * "local_education_agency_id": 255901, * "education_service_center_id": 255950, * "school_id": 255901107 * }, * { * "education_organization_id": 6000203, * "name_of_institution": "The University of Texas at Austin", * "type": "edfi.PostSecondaryInstitution", * "post_secondary_institution_id": 6000203 * } * ], */ }