public async Task GivenMultipleMatchingResources_WhenDeletingConditionallyWithMultipleFlag_TheServerShouldDeleteSuccessfully()
        {
            var mockResultEntry1 = new SearchResultEntry(CreateMockResourceWrapper(Samples.GetDefaultObservation().UpdateId(Guid.NewGuid().ToString()), false));
            var mockResultEntry2 = new SearchResultEntry(CreateMockResourceWrapper(Samples.GetDefaultObservation().UpdateId(Guid.NewGuid().ToString()), false));

            ConditionalDeleteResourceRequest message = SetupConditionalDelete(
                KnownResourceTypes.Observation,
                DefaultSearchParams,
                hardDelete: false,
                count: 100,
                mockResultEntry1,
                mockResultEntry2);

            DeleteResourceResponse result = await _mediator.Send(message);

            Assert.NotNull(result);
            Assert.Equal(2, result.ResourcesDeleted);

            await _fhirDataStore.Received(2).UpsertAsync(
                Arg.Is <ResourceWrapper>(x => x.IsDeleted),
                Arg.Any <WeakETag>(),
                true,
                true,
                Arg.Any <CancellationToken>());
        }
        public async Task GivenNoExistingResources_WhenDeletingConditionally_TheServerShouldReturn()
        {
            ConditionalDeleteResourceRequest message = SetupConditionalDelete(KnownResourceTypes.Observation, DefaultSearchParams);

            DeleteResourceResponse result = await _mediator.Send(message);

            Assert.Equal(0, result.ResourcesDeleted);
        }
        public async Task GivenMultipleMatchingResources_WhenDeletingConditionally_TheServerShouldReturnError()
        {
            var mockResultEntry1 = new SearchResultEntry(CreateMockResourceWrapper(Samples.GetDefaultObservation().UpdateId(Guid.NewGuid().ToString()), false));
            var mockResultEntry2 = new SearchResultEntry(CreateMockResourceWrapper(Samples.GetDefaultObservation().UpdateId(Guid.NewGuid().ToString()), false));

            ConditionalDeleteResourceRequest message = SetupConditionalDelete(
                KnownResourceTypes.Observation,
                DefaultSearchParams,
                hardDelete: false,
                count: 1,
                mockResultEntry1,
                mockResultEntry2);

            await Assert.ThrowsAsync <PreconditionFailedException>(() => _mediator.Send <DeleteResourceResponse>(message));
        }
Exemple #4
0
        public async Task GivenOneMatchingResource_WhenDeletingConditionallyWithHardDeleteFlag_TheServerShouldDeleteSuccessfully()
        {
            var mockResultEntry = new SearchResultEntry(CreateMockResourceWrapper(Samples.GetDefaultObservation().UpdateId(Guid.NewGuid().ToString()), false));

            ConditionalDeleteResourceRequest message = SetupConditionalDelete(KnownResourceTypes.Observation, DefaultSearchParams, true, 1, mockResultEntry);

            DeleteResourceResponse result = await _mediator.Send(message);

            Assert.NotNull(result);
            Assert.Equal(1, result.ResourcesDeleted);

            await _fhirDataStore.DidNotReceive().UpsertAsync(
                Arg.Any <ResourceWrapper>(),
                Arg.Any <WeakETag>(),
                true,
                true,
                Arg.Any <CancellationToken>());

            await _fhirDataStore.Received().HardDeleteAsync(Arg.Any <ResourceKey>(), Arg.Any <bool>(), Arg.Any <CancellationToken>());
        }
        private ConditionalDeleteResourceRequest SetupConditionalDelete(
            string resourceType,
            IReadOnlyList <Tuple <string, string> > list = null,
            bool hardDelete = false,
            int count       = 1,
            params SearchResultEntry[] searchResults)
        {
            _searchService.SearchAsync(Arg.Any <string>(), Arg.Any <IReadOnlyList <Tuple <string, string> > >(), Arg.Any <CancellationToken>())
            .Returns(new SearchResult(searchResults, null, null, Enumerable.Empty <Tuple <string, string> >().ToArray()));

            if (hardDelete)
            {
                _fhirDataStore.HardDeleteAsync(Arg.Any <ResourceKey>(), Arg.Any <CancellationToken>()).Returns(Task.CompletedTask);
            }
            else
            {
                _fhirDataStore.UpsertAsync(Arg.Any <ResourceWrapper>(), Arg.Any <WeakETag>(), true, true, Arg.Any <CancellationToken>())
                .Returns(x => new UpsertOutcome(x.ArgAt <ResourceWrapper>(0), SaveOutcomeType.Updated));
            }

            var message = new ConditionalDeleteResourceRequest(resourceType, list, hardDelete, count);

            return(message);
        }