public void TestGetTemplates() { MockObjectRepository mockRepo = new MockObjectRepository(); mockRepo.InitializeFHIR2Repository(); mockRepo.InitializeLCGAndLogin(); var ig = mockRepo.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_FHIR_DSTU2_IG_TYPE_NAME, "Test IG"); var template = mockRepo.GenerateTemplate("http://test.com/profile1", "Composition", "Test Composition", ig); HttpRequestMessage request = new HttpRequestMessage() { RequestUri = new Uri("http://localhost:8080/api/FHIR2/StructureDefinition") }; HttpRequest contextRequest = new HttpRequest(null, "http://localhost:8080/api/FHIR2/StructureDefinition", null); HttpResponse contextResponse = new HttpResponse(new StringWriter()); HttpContext.Current = new HttpContext(contextRequest, contextResponse); FHIR2StructureDefinitionController controller = new FHIR2StructureDefinitionController(mockRepo, request); var response = controller.GetTemplates(); var result = AssertHelper.IsType <NegotiatedContentResult <Bundle> >(response); Assert.IsNotNull(result.Content); Assert.AreEqual(1, result.Content.Entry.Count); var firstEntry = result.Content.Entry.First(); Assert.AreEqual("http://localhost:8080/api/FHIR2/StructureDefinition/1", firstEntry.FullUrl); Assert.IsNotNull(firstEntry.Resource); var firstStrucDef = AssertHelper.IsType <StructureDefinition>(firstEntry.Resource); Assert.IsNull(firstStrucDef.Id); }
public void DSTU2_TestGetTemplates() { // Login for the user. This is important to do here (outside of setup) so that it associates the thread // running the GetTemplates() method with authentication, since login is session/thread-specific StructureDefinitionControllerTest.mockRepo2.Login(); var ig = StructureDefinitionControllerTest.mockRepo2.FindOrCreateImplementationGuide(Constants.IGTypeNames.FHIR_DSTU2, "Test IG"); HttpRequestMessage request = new HttpRequestMessage() { RequestUri = new Uri("http://localhost:8080/api/FHIR2/StructureDefinition") }; HttpRequest contextRequest = new HttpRequest(null, "http://localhost:8080/api/FHIR2/StructureDefinition", null); HttpResponse contextResponse = new HttpResponse(new StringWriter()); HttpContext.Current = new HttpContext(contextRequest, contextResponse); FHIR2StructureDefinitionController controller = new FHIR2StructureDefinitionController(StructureDefinitionControllerTest.mockRepo2, request); // Do the work: GetTemplates() // This responds with an HTTP response, which needs to be converted into the actual Bundle result var response = controller.GetTemplates(); var result = AssertHelper.IsType <NegotiatedContentResult <Bundle> >(response); Assert.IsNotNull(result.Content); Assert.AreEqual(1, result.Content.Entry.Count); var firstEntry = result.Content.Entry.First(); Assert.AreEqual("http://localhost:8080/api/FHIR2/StructureDefinition/1", firstEntry.FullUrl); Assert.IsNotNull(firstEntry.Resource); var firstStrucDef = AssertHelper.IsType <StructureDefinition>(firstEntry.Resource); Assert.IsNull(firstStrucDef.Id); }