public async Task TestResourceDoesNotExistShouldReturnErrorCode() { var interactor = new ReadResourceInteractor(new InMemoryFhirRepository(), new InMemorySearchRepository()); var response = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "kasfasagdssg", ResourceType = "Patient" }); Assert.AreEqual(ResponseCode.ResourceNotFound, response.Code); }
public async Task TestRepositoryThrowsExceptionShouldReturnErrorCode() { var repository = new Mock <IFhirRepository>(); repository.Setup(r => r.ReadResourceAsync(It.IsAny <string>())).ThrowsAsync(new Exception()); var interactor = new ReadResourceInteractor(repository.Object, new InMemorySearchRepository()); var response = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "kasfasagdssg", ResourceType = "Patient" }); Assert.AreEqual(ResponseCode.Failure, response.Code); }
public async Task TestResourceTypeMismatchShouldReturnErrorCode() { var resource = FhirResourceProvider.Patient; resource.Id = "SOMEFHIRCONFORMID"; var repository = new InMemoryFhirRepository(); repository.Resources.Add(resource); var interactor = new ReadResourceInteractor(repository, new InMemorySearchRepository()); var response = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "SOMEFHIRCONFORMID", ResourceType = "Observation" }); Assert.AreEqual(ResponseCode.ResourceNotFound, response.Code); }
public async Task TestResourceExistsShouldReturnResourceAndSuccess() { var resource = FhirResourceProvider.Patient; resource.Id = "SOMEFHIRCONFORMID"; var repository = new InMemoryFhirRepository(); repository.Resources.Add(resource); var interactor = new ReadResourceInteractor(repository, new InMemorySearchRepository()); var response = await interactor.ExecuteAsync(new ReadResourceRequest { ResourceId = "SOMEFHIRCONFORMID", ResourceType = "Patient" }); Assert.AreEqual(ResponseCode.Success, response.Code); Assert.IsTrue(response.Resource.IsExactly(resource)); }
public async Task RunAsync(int rounds) { var repository = new RestIotaRepository( new FallbackIotaClient( new List <string> { "https://nodes.thetangle.org:443", "http://node04.iotatoken.nl:14265", "http://node05.iotatoken.nl:16265", "https://nodes.thetangle.org:443", "http://iota1.heidger.eu:14265", "https://nodes.iota.cafe:443", "https://potato.iotasalad.org:14265", "https://durian.iotasalad.org:14265", "https://turnip.iotasalad.org:14265", "https://nodes.iota.fm:443", "https://tuna.iotasalad.org:14265", "https://iotanode2.jlld.at:443", "https://node.iota.moe:443", "https://wallet1.iota.town:443", "https://wallet2.iota.town:443", "http://node03.iotatoken.nl:15265", "https://node.iota-tangle.io:14265", "https://pow4.iota.community:443", "https://dyn.tangle-nodes.com:443", "https://pow5.iota.community:443", }, 5000), new PoWSrvService()); var fhirRepository = new IotaFhirRepository(repository, new FhirJsonTryteSerializer(), new InMemoryResourceTracker()); var resourceInteractor = new CreateResourceInteractor(fhirRepository); var readInteractor = new ReadResourceInteractor(fhirRepository); var measurement = new GlucoseMeasurementValue { GlucoseConcentrationMolL = 5.4f, BaseTime = DateTime.UtcNow }; var resourceId = string.Empty; var n = 0; while (n < rounds) { n++; this.Tracker.Update(n); // The example sends an observation. Nevertheless it does not make a difference from a technical perspective // what resource is sent, as long as its size fits one IOTA transaction var response = await resourceInteractor.ExecuteAsync(new CreateResourceRequest { Resource = ObservationFactory.FromMeasurement(measurement) }); if (string.IsNullOrEmpty(resourceId)) { resourceId = response.LogicalId; } } foreach (var trackingEntry in fhirRepository.ResultTimes) { this.Logger.Log($"Create: {trackingEntry.CreateTime:0000} | Attach: {trackingEntry.AttachTime:0000}"); } await readInteractor.ExecuteAsync(new ReadResourceRequest { ResourceId = resourceId }); foreach (var readEntry in fhirRepository.ReadTimes) { this.Logger.Log($"Read: {readEntry.ReadTime:0000}"); } }