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>()); }
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); }