コード例 #1
0
        public async Task GivenAnUpsertResourceRequest_WhenHandled_ThenTheResourceShouldBeUpsertedIntoTheRepository()
        {
            var repository = Substitute.For <IFhirRepository>();
            var handler    = new UpsertResourceHandler(repository);

            repository.UpsertAsync(Arg.Any <Resource>(), Arg.Any <WeakETag>()).Returns(new SaveOutcome(Samples.GetDefaultObservation(), SaveOutcomeType.Created));
            var observation = Samples.GetDefaultObservation();

            repository.UpsertAsync(Arg.Any <Resource>()).Returns(new SaveOutcome(observation, SaveOutcomeType.Created));

            await handler.Handle(
                new UpsertResourceRequest(observation),
                CancellationToken.None);

            await repository.Received().UpsertAsync(Arg.Any <Observation>());
        }
コード例 #2
0
        public async Task GivenAnUpsertResourceRequestWithMatchingId_WhenHandled_ThenTheResourceShouldBeUpsertedIntoTheRepository()
        {
            var repository = Substitute.For <IFhirRepository>();
            var handler    = new UpsertResourceHandler(repository);

            repository.UpsertAsync(Arg.Any <Resource>(), Arg.Any <WeakETag>()).Returns(new SaveOutcome(Samples.GetDefaultObservation(), SaveOutcomeType.Created));

            var weakETag    = WeakETag.FromVersionId(Guid.NewGuid().ToString());
            var observation = Samples.GetDefaultObservation();

            observation.VersionId = weakETag.VersionId;
            observation.Id        = Guid.NewGuid().ToString();

            await handler.Handle(
                new UpsertResourceRequest(observation, weakETag),
                CancellationToken.None);

            await repository.Received().UpsertAsync(observation, weakETag);
        }