public override VmOpenApiServiceChannelService TranslateEntityToVm(ServiceServiceChannel entity) { var definition = CreateEntityViewModelDefinition(entity) .AddCollection(i => i.ServiceServiceChannelDescriptions, o => o.Description) .AddNavigation(i => i.ChargeTypeId.HasValue ? typesCache.GetByValue <ServiceChargeType>(i.ChargeTypeId.Value) : null, o => o.ServiceChargeType) .AddCollection(i => i.ServiceServiceChannelDigitalAuthorizations?.Select(d => d.DigitalAuthorization).ToList(), o => o.DigitalAuthorizations) .AddCollection(i => i.ServiceServiceChannelExtraTypes, o => o.ExtraTypes) .AddCollection(i => i.ServiceServiceChannelServiceHours, o => o.ServiceHours) .AddNavigation(i => i, o => o.ContactDetails); if (entity.Service != null) { var publishedId = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString()); definition.AddNavigation(i => i.Service.Versions.Where(x => x.PublishingStatusId == publishedId).FirstOrDefault(), o => o.Service); } else { var service = new ServiceVersioned() { UnificRootId = entity.ServiceId }; definition.AddNavigation(i => service, o => o.Service); } return(definition.GetFinal()); }
public GetServiceByIdTests() { _list = EntityGenerator.GetServiceEntityList(1, PublishingStatusCache); _publishedItem = _list.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault(); _publishedItemId = _publishedItem.Id; _publishedRootItemId = _publishedItem.UnificRootId; }
private void CheckTranslation(VmService source, VmServiceStep2 step, ServiceVersioned target) { //target.Id.Should().NotBe(Guid.Empty); target.ServiceTargetGroups.Count.Should().Be(step.TargetGroups.Count); target.ServiceServiceClasses.Count.Should().Be(step.ServiceClasses.Count); target.ServiceOntologyTerms.Count.Should().Be(step.OntologyTerms.Count); target.ServiceLifeEvents.Count.Should().Be(step.LifeEvents.Count); target.ServiceKeywords.Count.Should().Be(step.KeyWords.Count); }
public void TranslateServiceToVm() { var service = new ServiceVersioned(); var toTranslate = new List <ServiceVersioned>() { service }; var translations = RunTranslationEntityToModelTest <ServiceVersioned, VmOpenApiServiceVersionBase>(translators, toTranslate); var translation = translations.First(); Assert.Equal(toTranslate.Count, translations.Count); }
private List <Guid?> GetSavedServiceOrganizationIds(ServiceVersioned service, IUnitOfWorkWritable unitOfWork) { var rep = unitOfWork.CreateRepository <IOrganizationServiceRepository>(); var id = unitOfWork.TranslationCloneCache.GetFromCachedSet <ServiceVersioned>() .Where(x => x.ClonedEntity.Id == service.Id).Select(x => x.OriginalEntity.Id).SingleOrDefault(); id = id.IsAssigned() ? id : service.Id; var ids = rep.All() .Where(x => x.ServiceVersionedId == id) .Select(x => (Guid?)x.OrganizationId) .Distinct() .ToList(); return(ids ?? new List <Guid?>()); }
private void CheckTranslation(VmService source, VmServiceStep1 step1, ServiceVersioned target) { //target.Id.Should().NotBe(Guid.Empty); var names = conversion.GetValidTextsSkipEmptyKeepMandatory(step1.ServiceName, step1.AlternateServiceName); target.ServiceNames.Count.Should().Be(names.Count, "ServiceNames"); target.ServiceNames.All(n => names.Contains(n.Name)).Should().BeTrue("Not all names are translated correctly"); var descriptions = conversion.GetValidTexts(step1.ShortDescriptions, step1.Description, step1.UserInstruction, step1.AdditionalInformation, step1.AdditionalInformationDeadLine, step1.AdditionalInformationProcessingTime, step1.AdditionalInformationValidityTime); target.ServiceDescriptions.Count.Should().Be(descriptions.Count, "ServiceDescriptions"); target.ServiceDescriptions.All(n => descriptions.Contains(n.Description)).Should().BeTrue("Not all description are translated correctly"); target.ServiceRequirements.Count.Should().Be(1, "ServiceRequirements"); target.ServiceLanguages.Count.Should().Be(step1.Languages.Count, "ServiceLanguages"); // target.ServiceCoverageTypeId.Should().Be(step1.ServiceCoverageTypeId); target.FundingTypeId.Should().Be(step1.FundingTypeId); }
private void CheckTranslations(ServiceVersioned source, IVmOpenApiServiceBase target) { target.ServiceDescriptions.Count.Should().Be(2); // additionalInfo var additionalInfoTarget = target.ServiceDescriptions.Where(d => d.Type == DescriptionTypeEnum.ServiceTypeAdditionalInfo.ToString()).First(); var additionalInfoSource = source.ServiceDescriptions.First(d => d.TypeId == CacheManager.TypesCache.Get <DescriptionType>(DescriptionTypeEnum.ServiceTypeAdditionalInfo.ToString())); additionalInfoTarget.Language.Should().Be(CacheManager.LanguageCache.GetByValue(additionalInfoSource.LocalizationId)); additionalInfoTarget.Value.Should().Be(additionalInfoSource.Description); // serviceDescription var serviceDescriptionTarget = target.ServiceDescriptions.First(); var serviceDescriptionSource = source.ServiceDescriptions.First(d => d.TypeId == CacheManager.TypesCache.Get <DescriptionType>(serviceDescriptionTarget.Type)); serviceDescriptionTarget.Language.Should().Be(CacheManager.LanguageCache.GetByValue(serviceDescriptionSource.LocalizationId)); serviceDescriptionTarget.Value.Should().NotBeNull(); }
public override VmOpenApiServiceCollectionService TranslateEntityToVm(ServiceCollectionService entity) { var definition = CreateEntityViewModelDefinition(entity); if (entity.Service != null) { var publishedId = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString()); definition.AddPartial(i => i.Service.Versions.Where(x => x.PublishingStatusId == publishedId).FirstOrDefault(), o => o); } else { var service = new ServiceVersioned() { UnificRootId = entity.ServiceId }; definition.AddCollection(i => service.ServiceNames.ToList(), o => o.Name); } return(definition.GetFinal()); }
private static void CheckTranslation(VmService source, VmServiceStep3 step, ServiceVersioned target) { target.ServiceProducers.Count.Should().Be(step.ServiceProducers.Count); // selfProduced var sourceSelfProduced = source.Step3Form.ServiceProducers.First(p => p.ProvisionType == ProvisionTypeEnum.SelfProduced.ToString().GetGuid()); var targetSelfProduced = target.ServiceProducers.First(p => p.ProvisionTypeId == ProvisionTypeEnum.SelfProduced.ToString().GetGuid()); targetSelfProduced.Organizations.Count.Should().Be(sourceSelfProduced.SelfProducers.Count); if (sourceSelfProduced.SelfProducers.Count > 0) { targetSelfProduced.Organizations.First().OrganizationId.Should().Be(sourceSelfProduced.SelfProducers.First()); } targetSelfProduced.AdditionalInformations.Should().BeEmpty(); // purchased var sourcePurchased = source.Step3Form.ServiceProducers.First(p => p.ProvisionType == ProvisionTypeEnum.PurchaseServices.ToString().GetGuid()); var targetPurchased = target.ServiceProducers.First(p => p.ProvisionTypeId == ProvisionTypeEnum.PurchaseServices.ToString().GetGuid()); if (sourcePurchased.Organization.HasValue) { targetPurchased.Organizations.First().OrganizationId.Should().Be(sourcePurchased.Organization.Value); } if (!string.IsNullOrEmpty(sourcePurchased.AdditionalInformation["fi"])) { targetPurchased.AdditionalInformations.First().Text.Should().Be(sourcePurchased.AdditionalInformation["fi"]); } // other var sourceOther = source.Step3Form.ServiceProducers.First(p => p.ProvisionType == ProvisionTypeEnum.Other.ToString().GetGuid()); var targetOther = target.ServiceProducers.First(p => p.ProvisionTypeId == ProvisionTypeEnum.Other.ToString().GetGuid()); if (sourceOther.Organization.HasValue) { targetOther.Organizations.First().OrganizationId.Should().Be(sourceOther.Organization.Value); } if (!string.IsNullOrEmpty(sourceOther.AdditionalInformation["fi"])) { targetOther.AdditionalInformations.First().Text.Should().Be(sourceOther.AdditionalInformation["fi"]); } }
public PrefilteringManagerTests() { var service = new ServiceVersioned() { Id = Guid.NewGuid() }; servicesDbSet = new List <ServiceVersioned>() { service }; lockingDbSet = new List <Locking>(); unitOfWorkMockSetup = new Mock <IUnitOfWorkWritable>(); publishingStatusCache = new Mock <IPublishingStatusCache>(); publishingStatusCache.Setup(i => i.Get(It.IsAny <PublishingStatus>())).Returns <PublishingStatus>(j => j.ToString().GetGuid()); publishingStatusCache.Setup(i => i.Get(It.IsAny <string>())).Returns <string>(j => j.GetGuid()); CacheManagerMock.Setup(i => i.PublishingStatusCache).Returns(publishingStatusCache.Object); serviceRepositoryMockSetup = new Mock <IServiceVersionedRepository>(); serviceRepositoryMockSetup.Setup(i => i.All()).Returns(servicesDbSet.AsQueryable()); serviceRepositoryMockSetup.Setup(i => i.Add(It.IsAny <ServiceVersioned>())).Returns <ServiceVersioned>(i => { servicesDbSet.Add(i); return(i); }); lockingRepositoryMockSetup = new Mock <ILockingRepository>(); lockingRepositoryMockSetup.Setup(i => i.All()).Returns(lockingDbSet.AsQueryable()); lockingRepositoryMockSetup.Setup(i => i.Add(It.IsAny <Locking>())).Returns <Locking>(i => { lockingDbSet.Add(i); return(i); }); lockingRepositoryMockSetup.Setup(i => i.Remove(It.IsAny <Locking>())).Callback <Locking>(i => { lockingDbSet.Remove(i); }); userIdentificationMockSetup = new Mock <IUserIdentification>(); unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceVersionedRepository>()).Returns(serviceRepositoryMockSetup.Object); unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <ILockingRepository>()).Returns(lockingRepositoryMockSetup.Object); userIdentificationMockSetup.Setup(ui => ui.UserName).Returns("TestUser"); RegisterDbSet(servicesDbSet, unitOfWorkMockSetup); RegisterDbSet(lockingDbSet, unitOfWorkMockSetup); }
private void CheckTranslation(VmService source, List <Guid> step, ServiceVersioned target) { // target.Id.Should().NotBe(Guid.Empty); // target.ServiceServiceChannels.Count.Should().Be(step.Count); }
public void ImportDataFromJSON() { // var importedGeneralDescriptions = JsonConvert.DeserializeObject<List<ImportStatutoryServiceGeneralDescription>>(File.ReadAllText(CreateGeneralDescriptionsJsonTask.GeneralDescriptionsGeneratedFile), new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); string langCode = LanguageCode.fi.ToString(); // //List<Guid> municipalityOrganizationIds = new List<Guid>(); List <StatutoryServiceGeneralDescriptionVersioned> statutoryServiceGeneralDescriptions = new List <StatutoryServiceGeneralDescriptionVersioned>(); // Language defaultLanguage = null; // string draftCode = PublishingStatus.Draft.ToString(); // //PublishingStatusType defaultPublishingType = null; // var nameTypeName = NameTypeEnum.Name.ToString(); // //NameType defaultNameType = null; // // var serviceTypeService = ServiceTypeEnum.Service.ToString(); // // using (var serviceScope = _serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope()) // { // var service = serviceScope.ServiceProvider.GetService<IGeneralDescriptionUpdateService>(); // service?.CreateOrUpdateGeneralDescriptions(importedGeneralDescriptions); // } // for performance/speed reason read these into memory (there are only ~130 entries on each table currently) Console.WriteLine(); using (var serviceScope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var scopedCtxMgr = serviceScope.ServiceProvider.GetService <IContextManager>(); scopedCtxMgr.ExecuteWriter(unitOfWork => { var municipalityRepository = unitOfWork.CreateRepository <IMunicipalityRepository>(); var organizationRepository = unitOfWork.CreateRepository <IOrganizationVersionedRepository>(); var organizationTypeRepository = unitOfWork.CreateRepository <IOrganizationTypeRepository>(); var statutoryServiceGeneralDescriptionRepository = unitOfWork.CreateRepository <IStatutoryServiceGeneralDescriptionVersionedRepository>(); // Exclude Helsinki and Mikkeli var excludedMunicipalityIds = municipalityRepository.All().Where(x => x.MunicipalityNames.Any(y => y.Name.Equals("Helsinki") || y.Name.Equals("Mikkeli"))).Select(m => m.Id).ToList(); // Get all organizations that are municipalities (exclude Mikkeli and Helsinki) var organizationMunicipalityTypeCode = OrganizationTypeEnum.Municipality.ToString(); var organizationMunicipalityTypeId = organizationTypeRepository.All().Where(x => x.Code == organizationMunicipalityTypeCode).First().Id; var municipalityOrganizationsUnificRoots = organizationRepository.All() .Where(x => x.TypeId == organizationMunicipalityTypeId && ((x.MunicipalityId == null) || ((x.MunicipalityId != null) && !excludedMunicipalityIds.Contains(x.MunicipalityId.Value)))) .Select(m => m.UnificRootId) .ToList(); statutoryServiceGeneralDescriptions = statutoryServiceGeneralDescriptionRepository.All().ToList(); var existingStatutoryServiceNames = unitOfWork.CreateRepository <IStatutoryServiceNameRepository>().All().ToList(); var existingStatutoryServiceClasses = unitOfWork.CreateRepository <IStatutoryServiceServiceClassRepository>().All().ToList(); var serviceRepository = unitOfWork.CreateRepository <IServiceVersionedRepository>(); var serviceNameRepository = unitOfWork.CreateRepository <IServiceNameRepository>(); var organizationServiceRepository = unitOfWork.CreateRepository <IOrganizationServiceRepository>(); var serviceServiceClassRepository = unitOfWork.CreateRepository <IServiceServiceClassRepository>(); var defaultPublishingType = unitOfWork .CreateRepository <IPublishingStatusTypeRepository>() .All() .FirstOrDefault(m => m.Code == draftCode); var defaultLanguage = unitOfWork.CreateRepository <ILanguageRepository>().All().First(x => x.Code == langCode); var defaultNameType = unitOfWork .CreateRepository <INameTypeRepository>() .All() .FirstOrDefault(x => x.Code == nameTypeName); var defaultAreaInformationType = unitOfWork .CreateRepository <IAreaInformationTypeRepository>() .All() .FirstOrDefault(x => x.Code == AreaInformationTypeEnum.WholeCountry.ToString()); var defaultFundingType = unitOfWork.CreateRepository <IServiceFundingTypeRepository>() .All() .FirstOrDefault(x => x.Code == ServiceFundingTypeEnum.PubliclyFunded.ToString()); foreach (var statutoryServiceGeneralDescription in statutoryServiceGeneralDescriptions) { Console.Write("#"); // Link the created general description to each municipality by creating a new service foreach (var municipalityOrganizationRootId in municipalityOrganizationsUnificRoots) { // Create service for each municipality organization var service = new ServiceVersioned() { Created = DateTime.UtcNow, CreatedBy = CreateServiceDataForGeneralDescriptionsJsonTask.DefaultCreatedBy, Id = Guid.NewGuid(), StatutoryServiceGeneralDescriptionId = statutoryServiceGeneralDescription.UnificRootId, //ServiceCoverageTypeId = null, Type = null, FundingType = defaultFundingType, AreaInformationType = defaultAreaInformationType, PublishingStatus = defaultPublishingType, UnificRoot = new Service() { Id = Guid.NewGuid() }, OrganizationId = municipalityOrganizationRootId }; var serviceName = new ServiceName() { Created = DateTime.UtcNow, CreatedBy = CreateServiceDataForGeneralDescriptionsJsonTask.DefaultCreatedBy, ServiceVersionedId = service.Id, Name = existingStatutoryServiceNames.FirstOrDefault( x => x.StatutoryServiceGeneralDescriptionVersionedId == statutoryServiceGeneralDescription.Id).Name, Localization = defaultLanguage, Type = defaultNameType }; // Create OrganizationService linking the service to organization (municipality) var organizationService = new OrganizationService() { Created = DateTime.UtcNow, CreatedBy = CreateServiceDataForGeneralDescriptionsJsonTask.DefaultCreatedBy, ServiceVersionedId = service.Id, OrganizationId = municipalityOrganizationRootId, }; var statutoryServiceClass = existingStatutoryServiceClasses.FirstOrDefault(x => x.StatutoryServiceGeneralDescriptionVersionedId == statutoryServiceGeneralDescription.Id); // Create ServiceServiceClass if (statutoryServiceClass != null) { var serviceServiceClass = new ServiceServiceClass() { Created = DateTime.UtcNow, CreatedBy = CreateServiceDataForGeneralDescriptionsJsonTask.DefaultCreatedBy, ServiceVersionedId = service.Id, ServiceClassId = statutoryServiceClass.ServiceClassId }; serviceServiceClassRepository.Add(serviceServiceClass); } serviceRepository.Add(service); serviceNameRepository.Add(serviceName); organizationServiceRepository.Add(organizationService); } unitOfWork.Save(SaveMode.NonTrackedDataMigration); } }); } }
public AddServiceTests() { _serviceId = Guid.NewGuid(); _serviceVersionedId = Guid.NewGuid(); _channelId = Guid.NewGuid(); _channelVersionedId = Guid.NewGuid(); SetupTypesCacheMock <ServiceType>(); SetupTypesCacheMock <ServiceChargeType>(); var serviceVersioned = new ServiceVersioned { Id = _serviceVersionedId, UnificRootId = _serviceId, UnificRoot = new Model.Models.Service() { Id = _serviceId, ServiceServiceChannels = new List <ServiceServiceChannel>() }, Organization = new Model.Models.Organization() }; var channelVersioned = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishedId, _channelId, _channelVersionedId); channelVersioned.UnificRoot = new ServiceChannel { Id = _channelId, Versions = new List <ServiceChannelVersioned> { channelVersioned } }; var connectionList = new List <ServiceServiceChannel> { new ServiceServiceChannel { Service = serviceVersioned.UnificRoot, ServiceId = serviceVersioned.UnificRootId, ServiceChannel = channelVersioned.UnificRoot, ServiceChannelId = channelVersioned.UnificRootId } }; translationManagerVModelMockSetup.Setup(t => t.Translate <IVmOpenApiServiceInVersionBase, ServiceVersioned>(It.IsAny <IVmOpenApiServiceInVersionBase>(), It.IsAny <IUnitOfWorkWritable>())) .Returns((IVmOpenApiServiceInVersionBase x, IUnitOfWorkWritable y) => { if (!string.IsNullOrEmpty(x.StatutoryServiceGeneralDescriptionId)) { serviceVersioned.StatutoryServiceGeneralDescriptionId = x.StatutoryServiceGeneralDescriptionId.ParseToGuid(); } serviceVersioned.PublishingStatusId = PublishingStatusCache.Get(x.PublishingStatus); if (x.ServiceNames?.Count > 0) { serviceVersioned.ServiceNames = new List <ServiceName>(); x.ServiceNames.ForEach(n => serviceVersioned.ServiceNames.Add(new ServiceName { Name = n.Value })); } if (!string.IsNullOrEmpty(x.Type)) { serviceVersioned.TypeId = TypeCache.Get <ServiceType>(x.Type); } if (!string.IsNullOrEmpty(x.ServiceChargeType)) { serviceVersioned.ChargeTypeId = TypeCache.Get <ServiceChargeType>(x.ServiceChargeType); } return(serviceVersioned); }); translationManagerVModelMockSetup.Setup(t => t.TranslateAll <VmOpenApiServiceServiceChannelInVersionBase, ServiceServiceChannel>(It.IsAny <List <V7VmOpenApiServiceServiceChannelAstiInBase> >(), It.IsAny <IUnitOfWorkWritable>())) .Returns((List <V7VmOpenApiServiceServiceChannelAstiInBase> x, IUnitOfWorkWritable y) => { var connections = new List <ServiceServiceChannel>(); x.ForEach(c => { var cv = EntityGenerator.CreateEntity <ServiceChannelVersioned, ServiceChannel, ServiceChannelLanguageAvailability>(PublishedId, c.ChannelGuid, _channelVersionedId); cv.UnificRoot = new ServiceChannel { Id = c.ChannelGuid, Versions = new List <ServiceChannelVersioned> { cv } }; var connection = new ServiceServiceChannel { ServiceChannelId = c.ChannelGuid, ServiceChannel = cv.UnificRoot }; if (c.Description?.Count > 0) { connection.ServiceServiceChannelDescriptions = new List <ServiceServiceChannelDescription>(); c.Description.ForEach(d => { var description = new ServiceServiceChannelDescription { Description = d.Value }; connection.ServiceServiceChannelDescriptions.Add(description); }); connections.Add(connection); } }); return(connections); }); ServiceRepoMock.Setup(g => g.All()).Returns((new List <ServiceVersioned> { serviceVersioned }).AsQueryable()); ConnectionRepoMock.Setup(g => g.All()).Returns(connectionList.AsQueryable()); //ServiceChannelRepoMock.Setup(g => g.All()).Returns((new List<ServiceChannelVersioned> { channelVersioned }).AsQueryable()); unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes( It.IsAny <IQueryable <ServiceVersioned> >(), It.IsAny <Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > >(), It.IsAny <bool>() )).Returns(new List <ServiceVersioned> { serviceVersioned }.AsQueryable()); unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes( It.IsAny <IQueryable <ServiceServiceChannel> >(), It.IsAny <Func <IQueryable <ServiceServiceChannel>, IQueryable <ServiceServiceChannel> > >(), It.IsAny <bool>() )).Returns(connectionList.AsQueryable()); VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWorkMockSetup.Object, _serviceId, PublishingStatus.Published, true)).Returns(_serviceVersionedId); translationManagerMockSetup.Setup(t => t.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>())) .Returns((ServiceVersioned sv) => { var vm = new VmOpenApiServiceVersionBase() { Id = sv.UnificRootId, StatutoryServiceGeneralDescriptionId = sv.StatutoryServiceGeneralDescriptionId, PublishingStatus = PublishingStatusCache.GetByValue(sv.PublishingStatusId) }; if (sv.ServiceNames?.Count > 0) { vm.ServiceNames = new List <VmOpenApiLocalizedListItem>(); sv.ServiceNames.ForEach(n => vm.ServiceNames.Add(new VmOpenApiLocalizedListItem { Value = n.Name })); } if (sv.UnificRoot?.ServiceServiceChannels?.Count > 0) { vm.ServiceChannels = new List <V7VmOpenApiServiceServiceChannel>(); sv.UnificRoot.ServiceServiceChannels.ForEach(c => { var channel = new V7VmOpenApiServiceServiceChannel { ServiceChannel = new VmOpenApiItem { Id = c.ServiceChannelId } }; vm.ServiceChannels.Add(channel); }); } return(vm); }); }