Beispiel #1
0
        private string MapWage(ApprenticeshipVacancy src)
        {
            switch (src.WageType)
            {
            case (int)LegacyWageType.LegacyText:
                return(UnknownText);

            case (int)LegacyWageType.LegacyWeekly:
            case (int)LegacyWageType.Custom:
                return(GetFormattedCurrencyString(src.WeeklyWage) ?? UnknownText);

            case (int)LegacyWageType.ApprenticeshipMinimum:
                return(GetMinimumApprenticeWage(src));

            case (int)LegacyWageType.NationalMinimum:
                return(GetNationalMinimumWageRangeText(src));

            case (int)LegacyWageType.CustomRange:
                return(GetWageRangeText(src));

            case (int)LegacyWageType.CompetitiveSalary:
                return("Competitive salary");

            case (int)LegacyWageType.ToBeAgreedUponAppointment:
                return("To be agreed upon appointment");

            case (int)LegacyWageType.Unwaged:
                return("Unwaged");

            default:
                return(UnknownText);
            }
        }
        public async Task ThenIfVacancyHasStandardCodeGetStandardTitle()
        {
            var vacancy = new ApprenticeshipVacancy()
            {
                StandardCode = 123
            };

            _mockValidator
            .Setup(v => v.Validate(It.IsAny <ValidationContext <GetApprenticeshipVacancyRequest> >()))
            .Returns(new ValidationResult());
            _mockTrainingDetailService
            .Setup(s => s.GetStandardDetailsAsync(It.IsAny <int>()))
            .ReturnsAsync(new Standard {
                Title = "standard", Code = vacancy.StandardCode.GetValueOrDefault()
            });

            _mockGetApprenticeshipService.Setup(r => r.GetApprenticeshipVacancyByReferenceNumberAsync(It.IsAny <int>())).ReturnsAsync(vacancy);

            var response = await _queryHandler.Handle(new GetApprenticeshipVacancyRequest());

            _mockTrainingDetailService.Verify(s => s.GetFrameworkDetailsAsync(It.IsAny <int>()), Times.Never);
            _mockTrainingDetailService.Verify(s => s.GetStandardDetailsAsync(It.IsAny <int>()));

            Assert.AreEqual(vacancy, response.ApprenticeshipVacancy);
            Assert.IsNotNull(vacancy.Standard);
        }
        public void MapApprenticeshipTypeValid(int apprenticeshipTypeId, string educationLevel)
        {
            var vacancy = new ApprenticeshipVacancy
            {
                ApprenticeshipTypeId = apprenticeshipTypeId,
                Location             = new Address()
            };

            var result = _sut.MapToApprenticeshipVacancy(vacancy);

            result.ApprenticeshipLevel.Should().Be(educationLevel);
        }
        public void ShouldMapUsingLocationTypeId(int vacancyLocationTypeid, bool expectedResult)
        {
            var vacancy = new ApprenticeshipVacancy()
            {
                VacancyLocationTypeId = vacancyLocationTypeid,
                Location             = new Address(),
                ApprenticeshipTypeId = 1
            };

            var result = _sut.MapToApprenticeshipVacancy(vacancy);

            result.IsNationwide.Should().Be(expectedResult);
        }
Beispiel #5
0
        public void ThenSetApplicationUrl()
        {
            string expectedUrl = "https://" + Guid.NewGuid();
            var    vacancy     = new ApprenticeshipVacancy
            {
                EmployersRecruitmentWebsite = expectedUrl,
                Location             = new Address(),
                ApprenticeshipTypeId = 1
            };

            ApprenticeshipVacancyDto result = _sut.MapToApprenticeshipVacancy(vacancy);

            result.ApplicationUrl.Should().Be(expectedUrl);
        }
Beispiel #6
0
        public ApiTypes.ApprenticeshipVacancy MapToApprenticeshipVacancy(ApprenticeshipVacancy apprenticeshipVacancy)
        {
            var liveVacancyBaseUrl = _provideSettings.GetSetting(ApplicationSettingKeys.LiveApprenticeshipVacancyBaseUrlKey);

            var apprenticeship = new ApiTypes.ApprenticeshipVacancy
            {
                VacancyReference              = apprenticeshipVacancy.VacancyReferenceNumber,
                Title                         = apprenticeshipVacancy.Title,
                ShortDescription              = apprenticeshipVacancy.ShortDescription,
                Description                   = apprenticeshipVacancy.Description,
                WageUnit                      = MapWageUnit(apprenticeshipVacancy.WageUnitId),
                WorkingWeek                   = apprenticeshipVacancy.WorkingWeek,
                WageText                      = MapWage(apprenticeshipVacancy),
                WageAdditionalInformation     = null,
                HoursPerWeek                  = apprenticeshipVacancy.HoursPerWeek,
                ExpectedDuration              = apprenticeshipVacancy.ExpectedDuration,
                ExpectedStartDate             = apprenticeshipVacancy.ExpectedStartDate,
                PostedDate                    = apprenticeshipVacancy.PostedDate,
                ApplicationClosingDate        = apprenticeshipVacancy.ApplicationClosingDate,
                NumberOfPositions             = apprenticeshipVacancy.NumberOfPositions,
                EmployerName                  = apprenticeshipVacancy.IsAnonymousEmployer ? apprenticeshipVacancy.AnonymousEmployerName : apprenticeshipVacancy.EmployerName,
                EmployerDescription           = apprenticeshipVacancy.IsAnonymousEmployer ? apprenticeshipVacancy.AnonymousEmployerDescription : apprenticeshipVacancy.EmployerDescription,
                EmployerWebsite               = apprenticeshipVacancy.IsAnonymousEmployer ? null : apprenticeshipVacancy.EmployerWebsite,
                TrainingToBeProvided          = apprenticeshipVacancy.TrainingToBeProvided,
                QualificationsRequired        = apprenticeshipVacancy.QualificationsRequired,
                SkillsRequired                = apprenticeshipVacancy.SkillsRequired,
                PersonalQualities             = apprenticeshipVacancy.PersonalQualities,
                FutureProspects               = apprenticeshipVacancy.FutureProspects,
                ThingsToConsider              = apprenticeshipVacancy.ThingsToConsider,
                IsNationwide                  = apprenticeshipVacancy.VacancyLocationTypeId == Nationwide,
                SupplementaryQuestion1        = apprenticeshipVacancy.SupplementaryQuestion1,
                SupplementaryQuestion2        = apprenticeshipVacancy.SupplementaryQuestion2,
                VacancyUrl                    = $"{liveVacancyBaseUrl}/{apprenticeshipVacancy.VacancyReferenceNumber}",
                Location                      = _geoCodedAddressMapper.MapToLocation(apprenticeshipVacancy.Location, showAnonymousEmployerDetails: apprenticeshipVacancy.IsAnonymousEmployer),
                ContactName                   = apprenticeshipVacancy.ContactName,
                ContactEmail                  = apprenticeshipVacancy.ContactEmail,
                ContactNumber                 = apprenticeshipVacancy.ContactNumber,
                TrainingProviderName          = apprenticeshipVacancy.TrainingProvider,
                TrainingProviderUkprn         = apprenticeshipVacancy.TrainingProviderUkprn,
                TrainingProviderSite          = apprenticeshipVacancy.TrainingProviderSite, //This is mapped to provider's trading name
                IsEmployerDisabilityConfident = apprenticeshipVacancy.IsDisabilityConfident,
                ApprenticeshipLevel           = EducationLevelHelper.RemapFromInt(apprenticeshipVacancy.ApprenticeshipTypeId).ToString(),
                ApplicationUrl                = apprenticeshipVacancy.EmployersRecruitmentWebsite,
                ApplicationInstructions       = apprenticeshipVacancy.EmployersApplicationInstructions
            };

            MapTrainingDetails(apprenticeshipVacancy, apprenticeship);

            return(apprenticeship);
        }
Beispiel #7
0
        public void ThenSetApplicationInstructions()
        {
            string expectedInstructions = Guid.NewGuid().ToString();
            var    vacancy = new ApprenticeshipVacancy
            {
                EmployersApplicationInstructions = expectedInstructions,
                Location             = new Address(),
                ApprenticeshipTypeId = 1
            };

            ApprenticeshipVacancyDto result = _sut.MapToApprenticeshipVacancy(vacancy);

            result.ApplicationInstructions.Should().Be(expectedInstructions);
        }
 private void UpdateEntityTimestamps(ApprenticeshipVacancy entity)
 {
     /* TODO
      * // determine whether this is a "new" entity being saved for the first time
      * if (entity.DateTimeCreated == DateTime.MinValue)
      * {
      *  entity.DateTimeCreated = DateTime.UtcNow;
      *  entity.DateTimeUpdated = null;
      * }
      * else
      * {
      *  entity.DateTimeUpdated = DateTime.UtcNow;
      * }
      */
 }
Beispiel #9
0
 private void MapTrainingDetails(ApprenticeshipVacancy src, ApiTypes.ApprenticeshipVacancy dest)
 {
     if (src.Framework != null)
     {
         dest.TrainingType  = ApiTypes.TrainingType.Framework;
         dest.TrainingTitle = src.Framework.Title;
         dest.TrainingCode  = src.Framework.Code.ToString();
     }
     else if (src.Standard != null)
     {
         dest.TrainingType  = ApiTypes.TrainingType.Standard;
         dest.TrainingTitle = src.Standard.Title;
         dest.TrainingCode  = src.Standard.Code.ToString();
     }
     else
     {
         dest.TrainingType = ApiTypes.TrainingType.Unavailable;
     }
 }
Beispiel #10
0
        private string GetNationalMinimumWageRangeText(ApprenticeshipVacancy src)
        {
            if (!src.HoursPerWeek.HasValue || src.HoursPerWeek <= 0)
            {
                return(UnknownText);
            }

            if (!src.MinimumWageLowerBound.HasValue && !src.MinimumWageUpperBound.HasValue)
            {
                return(UnknownText);
            }

            var lowerMinimumLimit = src.MinimumWageLowerBound * src.HoursPerWeek;
            var upperMinimumLimit = src.MinimumWageUpperBound * src.HoursPerWeek;

            var minLowerBoundSection = GetFormattedCurrencyString(lowerMinimumLimit) ?? UnknownText;
            var minUpperBoundSection = GetFormattedCurrencyString(upperMinimumLimit) ?? UnknownText;

            return($"{minLowerBoundSection} - {minUpperBoundSection}");
        }
 public ApprenticeshipVacancy ShallowSave(ApprenticeshipVacancy entity)
 {
     throw new NotImplementedException();
 }
        public ApprenticeshipVacancy Save(ApprenticeshipVacancy entity)
        {
            _logger.Debug("Calling database to save apprenticeship vacancy with id={0}", entity.EntityId);

            UpdateEntityTimestamps(entity);

            // TODO: Map from ApprenticeshipVacancy to Apprenticeship ??

            var dbVacancy = _mapper.Map <ApprenticeshipVacancy, Vacancy.Vacancy>(entity);

            dbVacancy.VacancyLocationTypeCode = "S"; // TODO: Can't get this right unless / until added to ApprenticeshipVacancy or exclude from updates

            // TODO: This should be the other way around (to avoid a race condition)
            // and be in a single call to the database (to avoid a double latency hit)
            // This should be done as a single method in _getOpenConnection

            try
            {
                _getOpenConnection.Insert(dbVacancy);
            }
            catch (Exception ex)
            {
                // TODO: Detect key violation

                if (!_getOpenConnection.UpdateSingle(dbVacancy))
                {
                    throw new Exception("Failed to update record after failed insert", ex);
                }

                if (entity.LocationAddresses != null)
                {
                    _getOpenConnection.MutatingQuery <int>(@"
-- TODO: Could be optimised. Locking may possibly be an issue
-- TODO: Should possibly split address into separate repo method
    DELETE Address.PostalAddress
    WHERE  PostalAddressId IN (
        SELECT PostalAddressId
        FROM   Vacancy.VacancyLocation
        WHERE  VacancyId = @VacancyId
    )

    DELETE Vacancy.VacancyLocation
    FROM   Vacancy.VacancyLocation
    WHERE  VacancyId = @VacancyId
");
                }
            }

            if (entity.LocationAddresses != null) // TODO: Split into separate repository method
            {
                // TODO: Optimisation - insert several in one SQL round-trip
                foreach (var location in entity.LocationAddresses)
                {
                    var dbLocation = new Vacancy.VacancyLocation()
                    {
                        VacancyId            = dbVacancy.VacancyId,
                        DirectApplicationUrl = "TODO",
                        NumberOfPositions    = location.NumberOfPositions
                    };

                    var dbAddress = _mapper.Map <Domain.Entities.Locations.Address, Address.PostalAddress>(location.Address);

                    dbLocation.PostalAddressId = (int)_getOpenConnection.Insert(dbAddress);

                    _getOpenConnection.Insert(dbLocation);
                }
            }


            _logger.Debug("Saved apprenticeship vacancy with to database with id={0}", entity.EntityId);

            // TODO: Mongo used to map dbVacancy back to entity, not sure what the point in that is.

            return(entity);
        }
Beispiel #13
0
 private string GetWageRangeText(ApprenticeshipVacancy src)
 {
     return($"{GetFormattedCurrencyString(src.WageLowerBound) ?? UnknownText} - {GetFormattedCurrencyString(src.WageUpperBound) ?? UnknownText}");
 }
Beispiel #14
0
 private string GetMinimumApprenticeWage(ApprenticeshipVacancy src)
 {
     return(src.MinimumWageRate.HasValue && src.HoursPerWeek.HasValue
         ? GetFormattedCurrencyString(src.MinimumWageRate.Value * src.HoursPerWeek.Value)
         : UnknownText);
 }