예제 #1
0
        public void Validate_GivenProviderTypeIsEmpty_ShouldReturnValidationError()
        {
            // Arrange
            MasterProviderModelValidator validatorUnderTest      = new MasterProviderModelValidator();
            MasterProviderModel          providerModelToValidate = GetMasterProviderModel(m => m.MasterProviderTypeGroupName = string.Empty);

            // Act
            ValidationResult validationResult = validatorUnderTest.Validate(providerModelToValidate);

            // Assert
            validationResult
            .Errors
            .Should().NotBeNullOrEmpty();

            validationResult
            .Errors
            .Count.Should().Be(1);

            validationResult
            .Errors[0]
            .ErrorMessage
            .Should().Be("Urn: 123432 - Provider Type Group Name column was empty");

            validationResult
            .IsValid
            .Should().BeFalse();
        }
예제 #2
0
        private MasterProviderModel GetMasterProviderModel(Action <MasterProviderModel> changeMasterProvider = null)
        {
            MasterProviderModel masterProviderModel = new MasterProviderModel()
            {
                MasterReasonEstablishmentClosed = EstablishmentClosedReason.AcademyConverter,
                MasterProviderName              = "Provider Name",
                MasterCRMAccountId              = "Crm account id",
                MasterDateClosed                = new DateTime(2019, 1, 1),
                MasterDateOpened                = new DateTime(2018, 1, 1),
                MasterDfEEstabNo                = "Establish No",
                MasterDfELAEstabNo              = "LaEstablish No",
                MasterLocalAuthorityCode        = "La Code",
                MasterLocalAuthorityName        = "La Name",
                MasterNavendorNo                = "Nav vendor no",
                MasterPhaseOfEducation          = "Phase of education",
                MasterProviderLegalName         = "Legal Name",
                MasterProviderStatusName        = "Status Name",
                MasterProviderTypeGroupName     = "Type group name",
                MasterProviderTypeName          = "Provider type name",
                MasterReasonEstablishmentOpened = EstablishmentOpenedReason.AcademyConverter,
                MasterSuccessor = "12345678",
                MasterUKPRN     = "123321",
                MasterUPIN      = "123312",
                MasterURN       = "123432"
            };

            changeMasterProvider?.Invoke(masterProviderModel);

            return(masterProviderModel);
        }
예제 #3
0
        public async Task <IActionResult> ImportProviders(HttpRequest request)
        {
            MasterProviderModel[] providers = new MasterProviderModel[0];

            try
            {
                providers = await request.ReadBodyJson <MasterProviderModel[]>();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Invalid providers were provided");

                return(new BadRequestObjectResult($"Invalid providers were provided: {ex.Message}"));
            }

            if (providers.IsNullOrEmpty())
            {
                _logger.Error("No providers were provided");

                return(new BadRequestObjectResult("No providers were provided"));
            }

            IEnumerable <ValidationFailure> validationFailures = providers.SelectMany(p => _masterProviderModelValidator.Validate(p).Errors);

            if (validationFailures.Any())
            {
                return(new BadRequestObjectResult(string.Join(",", validationFailures.Select(vf => vf.ErrorMessage))));
            }

            IList <ProviderIndex> providersToIndex = new List <ProviderIndex>();

            foreach (MasterProviderModel provider in providers)
            {
                ProviderIndex providerIndex = _providerImportMappingService.Map(provider);

                if (providerIndex != null)
                {
                    providersToIndex.Add(providerIndex);
                }
            }

            IEnumerable <IndexError> errors = await _resultsSearchRepositoryPolicy.ExecuteAsync(() => _searchRepository.Index(providersToIndex));

            if (errors.Any())
            {
                string errorMessage = $"Failed to index providers result documents with errors: { string.Join(";", errors.Select(m => m.ErrorMessage)) }";
                _logger.Error(errorMessage);

                return(new InternalServerErrorResult(errorMessage));
            }

            return(new NoContentResult());
        }
예제 #4
0
        public void Map_GivenMasterProviderModelWithNoUKPRNorURN_ReturnsNull()
        {
            //Arrange
            MasterProviderModel model = new MasterProviderModel();

            ProviderImportMappingService mappingService = new ProviderImportMappingService();

            //Act
            ProviderIndex providerIndex = mappingService.Map(model);

            //Assert
            providerIndex
            .Should()
            .BeNull();
        }
        public ProviderIndex Map(MasterProviderModel masterProviderModel)
        {
            ProviderIndex providerIndex = new ProviderIndex();

            if (string.IsNullOrWhiteSpace(masterProviderModel.MasterUKPRN) && string.IsNullOrWhiteSpace(masterProviderModel.MasterURN))
            {
                return(null);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(masterProviderModel.MasterUKPRN))
                {
                    providerIndex.ProviderId     = masterProviderModel.MasterUKPRN;
                    providerIndex.ProviderIdType = IdentifierFieldType.UKPRN.ToString();
                }
                else
                {
                    providerIndex.ProviderId     = masterProviderModel.MasterURN;
                    providerIndex.ProviderIdType = IdentifierFieldType.URN.ToString();
                }

                providerIndex.Authority = masterProviderModel.MasterLocalAuthorityName;
                providerIndex.CloseDate = masterProviderModel.MasterDateClosed;
                providerIndex.DfeEstablishmentNumber = masterProviderModel.MasterDfEEstabNo;
                providerIndex.EstablishmentNumber    = masterProviderModel.MasterDfELAEstabNo;
                providerIndex.LACode                    = masterProviderModel.MasterLocalAuthorityCode;
                providerIndex.LegalName                 = masterProviderModel.MasterProviderLegalName;
                providerIndex.Name                      = masterProviderModel.MasterProviderName;
                providerIndex.OpenDate                  = masterProviderModel.MasterDateOpened;
                providerIndex.ProviderSubType           = masterProviderModel.MasterProviderTypeName;
                providerIndex.ProviderType              = masterProviderModel.MasterProviderTypeGroupName;
                providerIndex.UKPRN                     = masterProviderModel.MasterUKPRN;
                providerIndex.UPIN                      = masterProviderModel.MasterUPIN;
                providerIndex.URN                       = masterProviderModel.MasterURN;
                providerIndex.CrmAccountId              = masterProviderModel.MasterCRMAccountId;
                providerIndex.Status                    = masterProviderModel.MasterProviderStatusName;
                providerIndex.NavVendorNo               = masterProviderModel.MasterNavendorNo;
                providerIndex.PhaseOfEducation          = masterProviderModel.MasterPhaseOfEducation;
                providerIndex.ReasonEstablishmentOpened = masterProviderModel.MasterReasonEstablishmentOpened?.GetAttributeOfType <EnumMemberAttribute>().Value;
                providerIndex.ReasonEstablishmentClosed = masterProviderModel.MasterReasonEstablishmentClosed?.GetAttributeOfType <EnumMemberAttribute>().Value;
                providerIndex.Successor                 = masterProviderModel.MasterSuccessor;
                providerIndex.TrustStatus               = masterProviderModel.MasterTrustStatus?.GetAttributeOfType <EnumMemberAttribute>().Value;
                providerIndex.TrustCode                 = masterProviderModel.MasterTrustCode;
                providerIndex.TrustName                 = masterProviderModel.MasterTrustName;

                return(providerIndex);
            }
        }
예제 #6
0
        public void Validate_GivenModelIsValid_ShouldReturnEmptyValidationResult()
        {
            // Arrange
            MasterProviderModelValidator validatorUnderTest      = new MasterProviderModelValidator();
            MasterProviderModel          providerModelToValidate = GetMasterProviderModel();

            // Act
            ValidationResult validationResult = validatorUnderTest.Validate(providerModelToValidate);

            // Assert
            validationResult
            .Errors
            .Should().BeEmpty();

            validationResult
            .IsValid
            .Should().BeTrue();
        }
예제 #7
0
        public void Map_GivenMasterProviderModelWithNoUKPRNButURN_SetsURNAsIdentifier()
        {
            //Arrange
            MasterProviderModel model = new MasterProviderModel
            {
                MasterURN = "1234"
            };

            ProviderImportMappingService mappingService = new ProviderImportMappingService();

            //Act
            ProviderIndex providerIndex = mappingService.Map(model);

            //Assert
            providerIndex
            .ProviderId
            .Should()
            .Be("1234");

            providerIndex
            .ProviderIdType
            .Should()
            .Be("URN");
        }
예제 #8
0
        public void Map_GivenMasterProviderModel_MapsAllProperties()
        {
            //Arrange
            const EstablishmentClosedReason masterReasonEstablishmentClosed = EstablishmentClosedReason.ResultOfAmalgamation;
            const EstablishmentOpenedReason masterReasonEstablishmentOpened = EstablishmentOpenedReason.ResultOfClosure;
            const TrustStatus masterTrustStatus = TrustStatus.NotApplicable;
            const string      masterSuccessor   = "12345678";
            const string      masterTrustCode   = "12312";
            const String      masterTrustName   = "Parent Trust";

            MasterProviderModel model = new MasterProviderModel
            {
                MasterCRMAccountId          = "1",
                MasterDateClosed            = DateTimeOffset.Now,
                MasterDateOpened            = DateTimeOffset.Now,
                MasterDfEEstabNo            = "111",
                MasterDfELAEstabNo          = "222",
                MasterLocalAuthorityCode    = "111111",
                MasterLocalAuthorityName    = "Timbuktoo",
                MasterProviderLegalName     = "legal name",
                MasterProviderName          = "name",
                MasterProviderStatusName    = "Active",
                MasterProviderTypeGroupName = "type",
                MasterProviderTypeName      = "sub type",
                MasterUKPRN                     = "1234",
                MasterUPIN                      = "4321",
                MasterURN                       = "2413",
                MasterNavendorNo                = "12345",
                MasterPhaseOfEducation          = "0",
                MasterSuccessor                 = masterSuccessor,
                MasterReasonEstablishmentClosed = masterReasonEstablishmentClosed,
                MasterReasonEstablishmentOpened = masterReasonEstablishmentOpened,
                MasterTrustStatus               = masterTrustStatus,
                MasterTrustCode                 = masterTrustCode,
                MasterTrustName                 = masterTrustName
            };

            ProviderImportMappingService mappingService = new ProviderImportMappingService();

            //Act
            ProviderIndex providerIndex = mappingService.Map(model);

            //Assert
            providerIndex.CrmAccountId.Should().Be("1");
            providerIndex.CloseDate.Should().NotBeNull();
            providerIndex.OpenDate.Should().NotBeNull();
            providerIndex.DfeEstablishmentNumber.Should().Be("111");
            providerIndex.EstablishmentNumber.Should().Be("222");
            providerIndex.LACode.Should().Be("111111");
            providerIndex.Authority.Should().Be("Timbuktoo");
            providerIndex.LegalName.Should().Be("legal name");
            providerIndex.Name.Should().Be("name");
            providerIndex.Status.Should().Be("Active");
            providerIndex.ProviderType.Should().Be("type");
            providerIndex.ProviderSubType.Should().Be("sub type");
            providerIndex.UKPRN.Should().Be("1234");
            providerIndex.UPIN.Should().Be("4321");
            providerIndex.URN.Should().Be("2413");
            providerIndex.NavVendorNo.Should().Be("12345");
            providerIndex.PhaseOfEducation.Should().Be("0");
            providerIndex.ReasonEstablishmentClosed.Should().Be("Result of Amalgamation/Merger");
            providerIndex.ReasonEstablishmentOpened.Should().Be("Result of Closure");
            providerIndex.Successor.Should().Be(masterSuccessor);
            providerIndex.TrustStatus.Should().Be("Not applicable");
            providerIndex.TrustCode.Should().Be(masterTrustCode);
            providerIndex.TrustName.Should().Be(masterTrustName);
        }