Пример #1
0
        public async Task WhenFoundAndUpdateWithoutPredecessor_ClearsPredecessor()
        {
            var sut = CreateSut(out var repository, out var sensitivityTestRepository, out var mapper, "12");
            var updateSentinelEntry = new SentinelEntryRequest {
                Id = 567
            };
            var sensitivityTest1 = new AntimicrobialSensitivityTest();
            var sentinelEntry    = new SentinelEntry
            {
                ProtectKey = "12",
                AntimicrobialSensitivityTests = new List <AntimicrobialSensitivityTest>
                {
                    sensitivityTest1
                },
                PredecessorEntry   = new SentinelEntry(),
                PredecessorEntryId = 123
            };

            repository.FirstOrDefaultAsync(Arg.Is <SentinelEntryIncludingTestsSpecification>(specification => specification.Id == 567))
            .Returns(Task.FromResult(sentinelEntry));

            var action = await sut.HandleAsync(updateSentinelEntry).ConfigureAwait(true);

            await sensitivityTestRepository.Received(1).DeleteAsync(sensitivityTest1).ConfigureAwait(true);

            mapper.Received(1).Map(updateSentinelEntry, sentinelEntry);
            var okResult             = action.Result.Should().BeOfType <OkObjectResult>().Subject;
            var updatedSentinelEntry = okResult.Value.As <SentinelEntry>();

            updatedSentinelEntry.PredecessorEntry.Should().BeNull();
            updatedSentinelEntry.PredecessorEntryId.Should().BeNull();
        }
Пример #2
0
        public async Task WhenFound_DeletesCorrespondingObjects()
        {
            var sut = CreateSut(out var repository, out var sensitivityTestRepository, "12");
            var sensitivityTest1 = new AntimicrobialSensitivityTest();
            var sensitivityTest2 = new AntimicrobialSensitivityTest();
            var sentinelEntry    = new SentinelEntry
            {
                Id         = 567,
                ProtectKey = "12",
                AntimicrobialSensitivityTests = new List <AntimicrobialSensitivityTest>
                {
                    sensitivityTest1, sensitivityTest2
                }
            };

            repository.FirstOrDefaultAsync(Arg.Is <SentinelEntryIncludingTestsSpecification>(specification => specification.Id == 567))
            .Returns(Task.FromResult(sentinelEntry));

            var action = await sut.HandleAsync(567).ConfigureAwait(true);

            await sensitivityTestRepository.Received(1).DeleteAsync(sensitivityTest1).ConfigureAwait(true);

            await sensitivityTestRepository.Received(1).DeleteAsync(sensitivityTest2).ConfigureAwait(true);

            await repository.Received(1).DeleteAsync(sentinelEntry).ConfigureAwait(true);

            var okResult = action.Result.Should().BeOfType <OkObjectResult>().Subject;

            okResult.Value.Should().Be(567);
        }
Пример #3
0
        public async Task WhenFound_ReturnsCorrespondingObject()
        {
            var sut = CreateSut(out var repository, out var sensitivityTestRepository, out var mapper, "12");
            var updateSentinelEntry = new SentinelEntryRequest {
                Id = 567, PredecessorLaboratoryNumber = "SN-3030-0303"
            };
            var sensitivityTest1 = new AntimicrobialSensitivityTest();
            var sensitivityTest2 = new AntimicrobialSensitivityTest();
            var sentinelEntry    = new SentinelEntry
            {
                ProtectKey = "12",
                AntimicrobialSensitivityTests = new List <AntimicrobialSensitivityTest>
                {
                    sensitivityTest1, sensitivityTest2
                }
            };
            var predecessorSentinelEntry = new SentinelEntry {
                Id = 303
            };

            repository.FirstOrDefaultAsync(Arg.Is <SentinelEntryByLaboratoryNumberSpecification>(s => s.Year == 3030 && s.SequentialNumber == 303)).Returns(predecessorSentinelEntry);
            repository.FirstOrDefaultAsync(Arg.Is <SentinelEntryIncludingTestsSpecification>(specification => specification.Id == 567))
            .Returns(Task.FromResult(sentinelEntry));

            var action = await sut.HandleAsync(updateSentinelEntry).ConfigureAwait(true);

            await sensitivityTestRepository.Received(1).DeleteAsync(sensitivityTest1).ConfigureAwait(true);

            await sensitivityTestRepository.Received(1).DeleteAsync(sensitivityTest2).ConfigureAwait(true);

            mapper.Received(1).Map(updateSentinelEntry, sentinelEntry);
            var okResult = action.Result.Should().BeOfType <OkObjectResult>().Subject;

            okResult.Value.Should().Be(sentinelEntry);
            okResult.Value.As <SentinelEntry>().PredecessorEntryId.Should().Be(303);
        }