Пример #1
0
        public async Task SaveTestProviderResults_WhenNoItemsPasssed_ThenNothingSaved()
        {
            // Arrange
            ITestResultsRepository testResultsRepository = CreateTestResultsRepository();
            ISearchRepository <TestScenarioResultIndex> searchRepository = CreateSearchRespository();

            TestResultsService service = CreateTestResultsService(testResultsRepository, searchRepository);

            IEnumerable <TestScenarioResult> updateItems = Enumerable.Empty <TestScenarioResult>();

            IEnumerable <ProviderResult> providerResults = Enumerable.Empty <ProviderResult>();

            // Act
            HttpStatusCode result = await service.SaveTestProviderResults(updateItems, providerResults);

            // Assert
            result.Should().Be(HttpStatusCode.NotModified);

            await testResultsRepository
            .Received(0)
            .SaveTestProviderResults(Arg.Any <IEnumerable <TestScenarioResult> >());

            await searchRepository
            .Received(0)
            .Index(Arg.Any <IEnumerable <TestScenarioResultIndex> >());
        }
Пример #2
0
        public async Task SaveTestProviderResults_WhenItemsPasssed_ThenItemsSaved()
        {
            // Arrange
            ITestResultsRepository testResultsRepository = CreateTestResultsRepository();
            ISearchRepository <TestScenarioResultIndex> searchRepository = CreateSearchRespository();

            TestResultsService service = CreateTestResultsService(testResultsRepository, searchRepository);

            List <TestScenarioResult> itemsToUpdate = new List <TestScenarioResult>
            {
                CreateTestScenarioResult()
            };

            testResultsRepository
            .SaveTestProviderResults(Arg.Any <IEnumerable <TestScenarioResult> >())
            .Returns(HttpStatusCode.Created);

            IEnumerable <ProviderResult> providerResults = Enumerable.Empty <ProviderResult>();

            // Act
            HttpStatusCode result = await service.SaveTestProviderResults(itemsToUpdate, providerResults);

            // Assert
            result.Should().Be(HttpStatusCode.Created);

            await testResultsRepository
            .Received(1)
            .SaveTestProviderResults(itemsToUpdate);

            await searchRepository
            .Received(1)
            .Index(Arg.Any <IEnumerable <TestScenarioResultIndex> >());
        }
Пример #3
0
        public async Task SaveTestProviderResults_WhenItemsPasssedAndRepositoryFailed_ThenItemsNotSaved()
        {
            // Arrange
            ITestResultsRepository testResultsRepository = CreateTestResultsRepository();

            testResultsRepository
            .SaveTestProviderResults(Arg.Any <IEnumerable <TestScenarioResult> >())
            .Returns(HttpStatusCode.BadRequest);

            TestResultsService service = CreateTestResultsService(testResultsRepository);

            IEnumerable <ProviderResult> providerResults = Enumerable.Empty <ProviderResult>();

            List <TestScenarioResult> itemsToUpdate = new List <TestScenarioResult>
            {
                CreateTestScenarioResult()
            };

            // Act
            HttpStatusCode result = await service.SaveTestProviderResults(itemsToUpdate, providerResults);

            // Assert
            result.Should().Be(HttpStatusCode.InternalServerError);

            await testResultsRepository
            .Received(1)
            .SaveTestProviderResults(itemsToUpdate);
        }
Пример #4
0
        public async Task SaveTestProviderResults_WhenItemsPasssed_ThenSearchResultsMapped()
        {
            // Arrange
            ITestResultsRepository testResultsRepository = CreateTestResultsRepository();
            ISearchRepository <TestScenarioResultIndex> searchRepository = CreateSearchRespository();

            TestResultsService service = CreateTestResultsService(testResultsRepository, searchRepository);

            IEnumerable <ProviderResult> providerResults = new[]
            {
                new ProviderResult
                {
                    Provider = new ProviderSummary
                    {
                        UKPRN = "111",
                        UPIN  = "222",
                        URN   = "333",
                        EstablishmentNumber = "123",
                        DateOpened          = DateTimeOffset.Now,
                        Authority           = "authority",
                        ProviderSubType     = "provider sub type",
                        ProviderType        = "provider type",
                        Id = "ProviderId"
                    }
                }
            };

            List <TestScenarioResult> itemsToUpdate      = new List <TestScenarioResult>();
            TestScenarioResult        testScenarioResult = CreateTestScenarioResult();

            itemsToUpdate.Add(testScenarioResult);

            testResultsRepository
            .SaveTestProviderResults(Arg.Any <IEnumerable <TestScenarioResult> >())
            .Returns(HttpStatusCode.Created);

            // Act
            HttpStatusCode result = await service.SaveTestProviderResults(itemsToUpdate, providerResults);

            // Assert
            result.Should().Be(HttpStatusCode.Created);

            await testResultsRepository
            .Received(1)
            .SaveTestProviderResults(itemsToUpdate);

            await searchRepository
            .Received(1)
            .Index(Arg.Is <IEnumerable <TestScenarioResultIndex> >(c =>
                                                                   c.First().Id == testScenarioResult.Id &&
                                                                   c.First().ProviderId == testScenarioResult.Provider.Id &&
                                                                   c.First().ProviderName == testScenarioResult.Provider.Name &&
                                                                   c.First().SpecificationId == testScenarioResult.Specification.Id &&
                                                                   c.First().SpecificationName == testScenarioResult.Specification.Name &&
                                                                   c.First().TestResult == Enum.GetName(typeof(Models.Results.TestResult), testScenarioResult.TestResult) &&
                                                                   c.First().TestScenarioId == testScenarioResult.TestScenario.Id &&
                                                                   c.First().TestScenarioName == testScenarioResult.TestScenario.Name &&
                                                                   c.First().LastUpdatedDate > DateTimeOffset.Now.AddDays(-1) &&
                                                                   c.First().EstablishmentNumber == "123" &&
                                                                   c.First().UKPRN == "111" &&
                                                                   c.First().UPIN == "222" &&
                                                                   c.First().URN == "333" &&
                                                                   c.First().LocalAuthority == "authority" &&
                                                                   c.First().ProviderType == "provider type" &&
                                                                   c.First().ProviderSubType == "provider sub type" &&
                                                                   c.First().OpenDate.HasValue
                                                                   ));
        }