public async Task TestResourceIsUpdatedShouldReturnAskedVersionOnVRead() { var resourceTracker = new InMemoryResourceTracker(); var repository = new IotaFhirRepository( IotaResourceProvider.Repository, new FhirJsonTryteSerializer(), resourceTracker, new RandomSeedManager()); var createdResource = await repository.CreateResourceAsync(FhirResourceProvider.Patient); var initialVersion = createdResource.VersionId; var updatedResource = await repository.UpdateResourceAsync(createdResource); var updatedVersionId = updatedResource.VersionId; await repository.UpdateResourceAsync(updatedResource); var readResource = await repository.ReadResourceVersionAsync(updatedVersionId); Assert.AreNotEqual(initialVersion, readResource.Meta.VersionId); Assert.AreEqual(updatedVersionId, readResource.Meta.VersionId); Assert.AreEqual(3, resourceTracker.Entries.First().ResourceRoots.Count); }
public async Task TestResourceCanBeReadFromTangle() { var resourceTracker = new InMemoryResourceTracker(); var iotaRepository = IotaResourceProvider.Repository; var repository = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, new RandomSeedManager(resourceTracker)); var createdResource = await repository.CreateResourceAsync(FhirResourceProvider.Patient); var readResource = await repository.ReadResourceAsync(createdResource.Id); Assert.IsTrue(createdResource.IsExactly(readResource)); }
public async Task TestUpdatedResourceShouldReturnAllEntriesInHistory() { var resourceTracker = new InMemoryResourceTracker(); var iotaRepository = IotaResourceProvider.Repository; var repository = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, new RandomSeedManager(resourceTracker)); var createdResource = await repository.CreateResourceAsync(FhirResourceProvider.Patient); var updatedResource = await repository.UpdateResourceAsync(createdResource); var resources = await repository.ReadResourceHistoryAsync(updatedResource.Id); Assert.AreEqual(2, resources.Count); }
public async Task TestResourceHasValidReferenceShouldUseExistingSeed() { var seedManager = new RandomSeedManager(); var repository = new IotaFhirRepository( IotaResourceProvider.Repository, new FhirJsonTryteSerializer(), new InMemoryResourceTracker(), seedManager); var reference = $"did:iota:JHAGDJAHDJAHGDAJHGD"; await seedManager.AddReferenceAsync(reference, Seed.Random()); var observation = new Observation { Subject = new ResourceReference(reference) }; var resource = await repository.CreateResourceAsync(observation); Assert.AreEqual(1, seedManager.References.Count); }
public async Task TestResourceCreationOnTangleShouldAssignHashesAsIds() { var resourceTracker = new InMemoryResourceTracker(); var seedManager = new RandomSeedManager(); var repository = new IotaFhirRepository( IotaResourceProvider.Repository, new FhirJsonTryteSerializer(), resourceTracker, seedManager); var resource = await repository.CreateResourceAsync(FhirResourceProvider.Patient); Assert.AreEqual(1, Regex.Matches(resource.Id, Id.PATTERN).Count); Assert.AreEqual(resource.Id, resource.VersionId); Assert.AreEqual(resource.VersionId, resource.Meta.VersionId); Assert.AreEqual(DateTime.UtcNow.Day, resource.Meta.LastUpdated?.DateTime.Day); Assert.AreEqual(DateTime.UtcNow.Month, resource.Meta.LastUpdated?.DateTime.Month); Assert.AreEqual(DateTime.UtcNow.Year, resource.Meta.LastUpdated?.DateTime.Year); Assert.IsTrue(InputValidator.IsTrytes(resource.Id)); Assert.AreEqual(1, resourceTracker.Entries.Count); Assert.IsTrue(seedManager.References.Any(e => e.Key == $"did:iota:{resource.Id}")); }