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 TestResourceIsReadOnlyShouldThrowException() { var resourceTracker = new InMemoryResourceTracker(); await resourceTracker.AddEntryAsync(new ResourceEntry { ResourceRoots = new List <string> { "SOMEID" } }); var repository = new IotaFhirRepository( IotaResourceProvider.Repository, new FhirJsonTryteSerializer(), resourceTracker, new RandomSeedManager()); var resource = FhirResourceProvider.Patient; resource.Id = "SOMEID"; await repository.UpdateResourceAsync(resource); }
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}")); }
public async Task TestNoMessagesAreOnMamStreamShouldThrowException() { var iotaRepository = IotaResourceProvider.Repository; var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var resourceTracker = new InMemoryResourceTracker(); await resourceTracker.AddEntryAsync( new ResourceEntry { Channel = channelFactory.Create(Mode.Restricted, Seed.Random(), SecurityLevel.Medium, Seed.Random().Value, true), Subscription = subscriptionFactory.Create(new Hash(Seed.Random().Value), Mode.Restricted, Seed.Random().Value, true), ResourceRoots = new List <string> { "SOMEID" } }); var repository = new IotaFhirRepository( iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, new RandomSeedManager()); await repository.ReadResourceAsync("SOMEID"); }