public async Task WhenApprenticeshipsApiReturnsDuplicateFrameworksAndStandards_ThenOnlyDistinctFrameworksAndStandardsAreUpsertedIntoReferenceData()
        {
            // Arrange
            _mockOuterApiClient
            .Setup(x => x.Get <GetTrainingProgrammesResponse>(It.IsAny <GetTrainingProgrammesRequest>()))
            .ReturnsAsync(new GetTrainingProgrammesResponse
            {
                TrainingProgrammes = new List <GetTrainingProgrammesResponseItem> {
                    _standardOne, _standardTwo, _standardTwo, _standardTwo, _frameworkOne, _frameworkTwo, _frameworkTwo, _frameworkTwo, _frameworkTwo
                }
            });

            ApprenticeshipProgrammesReferenceData apprenticeshipProgrammesReferenceData = null;

            _mockReferenceDataWriter.Setup(x => x.UpsertReferenceData(It.IsAny <ApprenticeshipProgrammesReferenceData>()))
            .Callback <ApprenticeshipProgrammesReferenceData>(arg => apprenticeshipProgrammesReferenceData = arg)
            .Returns(Task.CompletedTask);

            // Act
            await _sut.UpdateApprenticeshipProgrammesAsync();

            _mockReferenceDataWriter.Verify(x => x.UpsertReferenceData(apprenticeshipProgrammesReferenceData), Times.Once);
            apprenticeshipProgrammesReferenceData.Data.Count.Should().Be(4);
            apprenticeshipProgrammesReferenceData.Data.Count(ap => ap.ApprenticeshipType == TrainingType.Framework).Should().Be(2);
            apprenticeshipProgrammesReferenceData.Data.Count(ap => ap.ApprenticeshipType == TrainingType.Standard).Should().Be(2);
        }
        public async Task WhenApprenticeshipsApiReturnsDuplicateFrameworks_ThenOnlyDistinctFrameworksAreUpsertedIntoReferenceData()
        {
            // Arrange
            _mockOuterApiClient
            .Setup(x => x.Get <GetTrainingProgrammesResponse>(It.IsAny <GetTrainingProgrammesRequest>()))
            .ReturnsAsync(new GetTrainingProgrammesResponse
            {
                TrainingProgrammes = new List <GetTrainingProgrammesResponseItem> {
                    _standardOne, _frameworkOne, _frameworkOne, _frameworkTwo
                }
            });

            ApprenticeshipProgrammesReferenceData apprenticeshipProgrammesReferenceData = null;

            _mockReferenceDataWriter.Setup(x => x.UpsertReferenceData(It.IsAny <ApprenticeshipProgrammesReferenceData>()))
            .Callback <ApprenticeshipProgrammesReferenceData>(arg => apprenticeshipProgrammesReferenceData = arg)
            .Returns(Task.CompletedTask);

            // Act
            await _sut.UpdateApprenticeshipProgrammesAsync();

            // Assert
            var firstItem  = apprenticeshipProgrammesReferenceData.Data.First(ap => ap.ApprenticeshipType == TrainingType.Framework);
            var secondItem = apprenticeshipProgrammesReferenceData.Data.Where(ap => ap.ApprenticeshipType == TrainingType.Framework).Skip(1).First();

            _mockReferenceDataWriter.Verify(x => x.UpsertReferenceData(apprenticeshipProgrammesReferenceData), Times.Once);
            apprenticeshipProgrammesReferenceData.Data.Count().Should().Be(3);
            apprenticeshipProgrammesReferenceData.Data.Count(ap => ap.ApprenticeshipType == TrainingType.Framework).Should().Be(2);
            firstItem.Id.Equals(secondItem.Id).Should().BeFalse();
            firstItem.ApprenticeshipLevel.Equals(secondItem.ApprenticeshipLevel).Should().BeFalse();
            firstItem.Title.Equals(secondItem.Title).Should().BeFalse();
        }
        public async Task WhenApprenticeshipsApiReturnsDuplicateFrameworksAndStandards_ThenOnlyDistinctFrameworksAndStandardsAreUpsertedIntoReferenceData()
        {
            // Arrange
            _mockStandardsClient
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(
                Enumerable
                .Repeat(_standardOne, 2)
                .Union(Enumerable.Repeat(_standardTwo, 5))
                );

            _mockFrameworksClient
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(
                Enumerable
                .Repeat(_frameworkOne, 2)
                .Union(Enumerable.Repeat(_frameworkTwo, 11))
                );

            ApprenticeshipProgrammesReferenceData apprenticeshipProgrammesReferenceData = null;

            _mockReferenceDataWriter.Setup(x => x.UpsertReferenceData(It.IsAny <ApprenticeshipProgrammesReferenceData>()))
            .Callback <ApprenticeshipProgrammesReferenceData>(arg => apprenticeshipProgrammesReferenceData = arg)
            .Returns(Task.CompletedTask);

            // Act
            await _sut.UpdateApprenticeshipProgrammesAsync();

            _mockReferenceDataWriter.Verify(x => x.UpsertReferenceData(apprenticeshipProgrammesReferenceData), Times.Once);
            apprenticeshipProgrammesReferenceData.Data.Count.Should().Be(4);
            apprenticeshipProgrammesReferenceData.Data.Count(ap => ap.ApprenticeshipType == TrainingType.Framework).Should().Be(2);
            apprenticeshipProgrammesReferenceData.Data.Count(ap => ap.ApprenticeshipType == TrainingType.Standard).Should().Be(2);
        }
Ejemplo n.º 4
0
        public async Task WhenApprenticeshipsApiReturnsDuplicateStandards_ThenOnlyDistinctStandardsAreUpsertedIntoReferenceData()
        {
            // Arrange
            _mockStandardsClient
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(
                Enumerable
                .Repeat(_standardOne, 2)
                .Append(_standardTwo)
                );

            _mockFrameworksClient
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(new [] { _frameworkOne });

            ApprenticeshipProgrammesReferenceData apprenticeshipProgrammesReferenceData = null;

            _mockReferenceDataWriter.Setup(x => x.UpsertReferenceData(It.IsAny <ApprenticeshipProgrammesReferenceData>()))
            .Callback <ApprenticeshipProgrammesReferenceData>(arg => apprenticeshipProgrammesReferenceData = arg)
            .Returns(Task.CompletedTask);

            // Act
            await _sut.UpdateApprenticeshipProgrammesAsync();

            // Assert
            var firstItem  = apprenticeshipProgrammesReferenceData.Data.Where(ap => ap.ApprenticeshipType == TrainingType.Standard).First();
            var secondItem = apprenticeshipProgrammesReferenceData.Data.Where(ap => ap.ApprenticeshipType == TrainingType.Standard).Skip(1).First();

            _mockReferenceDataWriter.Verify(x => x.UpsertReferenceData(apprenticeshipProgrammesReferenceData), Times.Once);
            apprenticeshipProgrammesReferenceData.Data.Count().Should().Be(3);
            apprenticeshipProgrammesReferenceData.Data.Where(ap => ap.ApprenticeshipType == TrainingType.Standard).Count().Should().Be(2);
            firstItem.Id.Equals(secondItem.Id).Should().BeFalse();
            firstItem.Level.Equals(secondItem.Level).Should().BeFalse();
            firstItem.Title.Equals(secondItem.Title).Should().BeFalse();
        }
        public async Task WhenRemappingFromStandards_ShouldSetEducationLevelNumber(int level)
        {
            _standardOne.Level  = level;
            _frameworkOne.Level = level;

            _mockStandardsClient
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(new[] { _standardOne });

            _mockFrameworksClient
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(new[] { _frameworkOne });

            ApprenticeshipProgrammesReferenceData updatedData = null;

            _mockReferenceDataWriter
            .Setup(x => x.UpsertReferenceData(It.IsAny <ApprenticeshipProgrammesReferenceData>()))
            .Callback <ApprenticeshipProgrammesReferenceData>(x => updatedData = x)
            .Returns(Task.CompletedTask);

            await _sut.UpdateApprenticeshipProgrammesAsync();

            Assert.True(updatedData.Data.All(x => x.EducationLevelNumber == level));
        }