public PrintableFormChannelMainStep1TranslatorTest()
        {
            unitOfWorkMock = unitOfWorkMockSetup.Object;
            var typesCacheMock = SetupTypesCacheMock <ServiceChannelType>(typeof(ServiceChannelTypeEnum));
            var serviceChannel = new ServiceChannelVersioned();

            translators = new List <object>()
            {
                new PrintableFormChannelMainStep1Translator(ResolveManager, TranslationPrimitives, new ServiceChannelTranslationDefinitionHelper(CacheManager), typesCacheMock.Object),

                RegisterTranslatorMock(new Mock <ITranslator <PrintableFormChannel, VmPrintableFormChannelStep1> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelVersioned, IVmChannelDescription> >(), unitOfWorkMock,
                                       desc =>
                {
                    serviceChannel.OrganizationId = desc.OrganizationId ?? Guid.Empty;
                    serviceChannel.ServiceChannelDescriptions.Add(new ServiceChannelDescription());
                    serviceChannel.ServiceChannelNames.Add(new ServiceChannelName());
                    return(serviceChannel);
                },
                                       setTargetAction: sc => serviceChannel = sc),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelAttachment, VmChannelAttachment> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelEmail, VmEmailData> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelPhone, VmPhone> >(), unitOfWorkMock)
            };

            RegisterDbSet(CreateCodeData <ServiceChannelType>(typeof(ServiceChannelTypeEnum)), unitOfWorkMockSetup);
            RegisterDbSet(CreateCodeData <PublishingStatusType>(typeof(PublishingStatus)), unitOfWorkMockSetup);
        }
        public override V7VmOpenApiServiceServiceChannel 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)
                             .AddSimple(i => i.IsASTIConnection, O => O.IsASTIConnection);

            if (entity.ServiceChannel != null)
            {
                var publishedId = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString());
                definition.AddNavigation(i => i.ServiceChannel.Versions.Where(x => x.PublishingStatusId == publishedId).FirstOrDefault(), o => o.ServiceChannel);
            }
            else
            {
                var channel = new ServiceChannelVersioned()
                {
                    UnificRootId = entity.ServiceChannelId
                };
                definition.AddNavigation(i => channel, o => o.ServiceChannel);
            }

            return(definition.GetFinal());
        }
        public void TranslatePrintableFormChannelStep1ToEntityUpdate(bool isSet, string guid)
        {
            var parsedGuid     = guid.ParseToGuid();
            var serviceChannel = new ServiceChannelVersioned()
            {
                Id = parsedGuid.Value
            };

            RegisterDbSet(isSet ? new List <ServiceChannelVersioned>()
            {
                serviceChannel
            } : new List <ServiceChannelVersioned>(), unitOfWorkMockSetup);
            var model       = TestHelper.CreateVmPrintableFormChannelModel().Step1Form;
            var toTranslate = new List <VmPrintableFormChannelStep1>()
            {
                model
            };

            model.Id = parsedGuid;

            if (isSet)
            {
                var translations = RunTranslationModelToEntityTest <VmPrintableFormChannelStep1, ServiceChannelVersioned>(translators, toTranslate, unitOfWorkMock);
                var translation  = translations.First();
                translation.OrganizationId.Should().Be(model.OrganizationId ?? Guid.Empty);
                translation.ServiceChannelDescriptions.Count.Should().Be(1);
                translation.ServiceChannelNames.Count.Should().Be(1);
                translation.TypeId.Should().Be(ServiceChannelTypeEnum.PrintableForm.ToString().GetGuid());
            }
            else
            {
                Assert.Throws(typeof(DbEntityNotFoundException), () => RunTranslationModelToEntityTest <VmPrintableFormChannelStep1, ServiceChannelVersioned>(translators, toTranslate, unitOfWorkMock));
            }
        }
        public override VmOpenApiServiceChannel TranslateEntityToVm(ServiceChannelVersioned entity)
        {
            var definition = base.CreateChannelDefinitions(entity);

            var type = typesCache.GetByValue <ServiceChannelType>(entity.TypeId);

            if (type == ServiceChannelTypeEnum.EChannel.ToString())
            {
                return(definition.AddSimple(i => i.ElectronicChannels.FirstOrDefault()?.Id, o => o.ChannelId)
                       .GetFinal());
            }
            if (type == ServiceChannelTypeEnum.WebPage.ToString())
            {
                return(definition.AddSimple(i => i.WebpageChannels.FirstOrDefault()?.Id, o => o.ChannelId)
                       .GetFinal());
            }
            if (type == ServiceChannelTypeEnum.PrintableForm.ToString())
            {
                return(definition.AddSimple(i => i.PrintableFormChannels.FirstOrDefault()?.Id, o => o.ChannelId)
                       .GetFinal());
            }
            if (type == ServiceChannelTypeEnum.ServiceLocation.ToString())
            {
                return(definition.AddSimple(i => i.ServiceLocationChannels.FirstOrDefault()?.Id, o => o.ChannelId)
                       .GetFinal());
            }

            return(definition.GetFinal());
        }
        public GetServiceChannelByIdTests()
        {
            SetupTypesCacheMock <ServiceChannelType>();

            _channelList            = EntityGenerator.GetServiceChannelEntityList(1, PublishingStatusCache);
            _publishedChannel       = _channelList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault();
            _publishedChannelRootId = _publishedChannel.UnificRootId;
        }
Exemplo n.º 6
0
        public AddServiceChannelTests()
        {
            SetupTypesCacheMock <ServiceChannelType>();

            list            = EntityGenerator.GetServiceChannelEntityList(1, PublishingStatusCache);
            publishedEntity = list.Where(i => i.PublishingStatusId == PublishedId).FirstOrDefault();
            vm = new VmOpenApiServiceLocationChannelInVersionBase()
            {
                SourceId         = sourceId,
                PublishingStatus = PublishingStatus.Published.ToString()
            };
        }
        private void CheckTranslation(VmLocationChannelStep1 step1, ServiceChannelVersioned target)
        {
            if (step1.OrganizationId.HasValue)
            {
                target.OrganizationId.Should().NotBeEmpty();
                target.OrganizationId.Should().Be(step1.OrganizationId.Value);
            }
//            var names = conversion.GetValidTexts(step1.Name);
            target.ServiceChannelNames.Count.Should().Be(1, "ServiceNames");
//            var descriptions = conversion.GetValidTexts(step1.ShortDescription, step1.Description);
//            target.ServiceChannelDescriptions.Count.Should().Be(descriptions.Count, "ServiceDescriptions");
        }
        public override VmOpenApiWebPageChannelVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
        {
            var webPageChannel = entity.WebpageChannels?.FirstOrDefault();

            if (webPageChannel == null)
            {
                base.TranslateEntityToVm(entity);
            }

            var definition = CreateChannelDefinitions(entity)
                             .AddCollection(i => i.WebpageChannels.SafePropertyFromFirst(j => j.LocalizedUrls), o => o.Urls)
                             .AddSimple(i => webPageChannel.Id, o => o.ChannelId);

            return(definition.GetFinal());
        }
        public override VmOpenApiPhoneChannelVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
        {
            var phone = entity.Phones?.FirstOrDefault()?.Phone;

            if (phone == null)
            {
                return(base.TranslateEntityToVm(entity));
            }

            var typeCode          = typesCache.GetByValue <PhoneNumberType>(phone.TypeId);
            var serviceChargeType = typesCache.GetByValue <ServiceChargeType>(phone.ChargeTypeId);

            return(CreateChannelDefinitions(entity)
                   .AddCollection(i => i.Phones.Select(p => p.Phone).OrderBy(p => p.OrderNumber), o => o.PhoneNumbers)
                   .GetFinal());
        }
Exemplo n.º 10
0
        public override VmOpenApiElectronicChannelVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
        {
            var electronic = entity.ElectronicChannels?.FirstOrDefault();

            if (electronic == null)
            {
                return(base.TranslateEntityToVm(entity));
            }

            var definition = CreateChannelDefinitions(entity)
                             .AddSimple(i => electronic.SignatureQuantity ?? (0 as int?), o => o.SignatureQuantity)
                             .AddSimple(i => electronic.RequiresSignature, o => o.RequiresSignature)
                             .AddSimple(i => electronic.RequiresAuthentication, o => o.RequiresAuthentication)
                             .AddCollection(i => electronic.LocalizedUrls, o => o.Urls)
                             .AddCollection(i => i.Attachments.Select(j => j.Attachment).ToList(), o => o.Attachments)
                             .AddSimple(i => electronic.Id, o => o.ChannelId);

            return(definition.GetFinal());
        }
        public override VmOpenApiPrintableFormChannelVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
        {
            var printableForm = entity.PrintableFormChannels.FirstOrDefault();

            if (printableForm == null)
            {
                return(base.TranslateEntityToVm(entity));
            }

            var definition = base.CreateChannelDefinitions(entity)
                             .AddCollection(i => printableForm.FormIdentifiers, o => o.FormIdentifier)
                             .AddCollection(i => printableForm.FormReceivers, o => o.FormReceiver)
                             .AddCollection(i => printableForm.ChannelUrls, o => o.ChannelUrls)
                             .AddCollection(i => i.Attachments.Select(j => j.Attachment).ToList(), o => o.Attachments)
                             .AddSimple(i => printableForm.Id, o => o.ChannelId);

            if (printableForm.DeliveryAddress != null)
            {
                definition.AddNavigation(i => printableForm.DeliveryAddress, o => o.DeliveryAddress);
            }

            return(definition.GetFinal());
        }
 public override VmOpenApiServiceLocationChannelInVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
 {
     return(base.TranslateEntityToVm(entity));
 }
Exemplo n.º 13
0
 public ServiceChannelTranslationDefinitionHelper AddAttachmentsDefinition <TOut>(ITranslationDefinitions <ServiceChannelVersioned, TOut> definition, ServiceChannelVersioned entity) where TOut : IAttachments
 {
     definition.AddDictionaryList(i => i.Attachments.Select(x => x.Attachment).OrderBy(x => x.OrderNumber).ThenBy(x => x.Created), o => o.Attachments,
                                  x => languageCache.GetByValue(x.LocalizationId));
     return(this);
 }
        public override VmOpenApiServiceLocationChannelVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
        {
            var serviceLocation = entity.ServiceLocationChannels?.FirstOrDefault();

            if (serviceLocation == null)
            {
                return(base.TranslateEntityToVm(entity));
            }

            var definitions = CreateChannelDefinitions(entity)
                              .AddCollection(i => i.Phones.Select(p => p.Phone).OrderBy(p => p.OrderNumber), o => o.PhoneNumbers)
                              .AddCollection(i => serviceLocation.Addresses.OrderBy(x => x.CharacterId).ThenBy(x => x.Address.OrderNumber).ThenBy(x => x.Address.Modified), o => o.Addresses)
                              .AddSimple(i => serviceLocation.Id, o => o.ChannelId);

            var vm = definitions.GetFinal();

            // Organize moving addresses - we need to group moving addresses into one address (address.MovingAddresses includes all the moving addresses).
            if (vm.Addresses?.Count > 0)
            {
                V7VmOpenApiAddressWithMoving movingAddress = null;
                var addresses = new List <V7VmOpenApiAddressWithMoving>();
                vm.Addresses.ForEach(a =>
                {
                    if (a.SubType == AddressTypeEnum.Moving.ToString())
                    {
                        if (movingAddress != null)
                        {
                            a.MultipointLocation.ForEach(m => movingAddress.MultipointLocation.Add(m));
                        }
                        else
                        {
                            movingAddress = a;
                            addresses.Add(movingAddress);
                        }
                    }
                    else
                    {
                        addresses.Add(a);
                    }
                });
                vm.Addresses = addresses;
            }

            return(vm);
        }
        public LocationChannelMainTranslatorTest()
        {
            unitOfWorkMock = unitOfWorkMockSetup.Object;
            var duplicatedEntity = new ServiceChannelVersioned()
            {
                CreatedBy = "ITranslator<ServiceChannel, IVmChannelDescription>>"
            };

            translators = new List <object>()
            {
                new LocationChannelMainStep1Translator(ResolveManager, TranslationPrimitives, new ServiceChannelTranslationDefinitionHelper(CacheManager), CacheManager),

                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelVersioned, IVmChannelDescription> >(), unitOfWorkMock,
                                       desc =>
                {
//                        var x = TranslatedInstanceStorage.ProcessInstance(desc, duplicatedEntity);
                    duplicatedEntity.OrganizationId = desc.OrganizationId ?? Guid.Empty;
                    duplicatedEntity.ServiceChannelNames.Add(new ServiceChannelName {
                        Name = desc.Name
                    });
                    return(duplicatedEntity);
                },
                                       setTargetAction: sc => duplicatedEntity = sc
                                       ),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceLocationChannel, VmLocationChannelStep1> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelVersioned, VmOpeningHoursStep> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelVersioned, IPhoneNumberAndFax> >(), unitOfWorkMock,
                                       phones =>
                {
//                        var x = TranslatedInstanceStorage.ProcessInstance(phones, duplicatedEntity);
                    duplicatedEntity.Phones.Add(new ServiceChannelPhone {
                        CreatedBy = phones.PhoneNumber.Number
                    });
                    return(duplicatedEntity);
                },
                                       setTargetAction: sc => duplicatedEntity = sc
                                       ),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelVersioned, IEmail> >(), unitOfWorkMock,
                                       email =>
                {
//                        var x = TranslatedInstanceStorage.ProcessInstance(email, duplicatedEntity);
                    duplicatedEntity.Emails.Add(new ServiceChannelEmail {
                        Email = new Email {
                            Value = email.Email.Email
                        }
                    });
                    return(duplicatedEntity);
                },
                                       setTargetAction: sc => duplicatedEntity = sc
                                       ),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelLanguage, VmListItem> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelWebPage, VmWebPage> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelEmail, VmEmailData> >(), unitOfWorkMock),
                RegisterTranslatorMock(new Mock <ITranslator <ServiceChannelPhone, VmPhone> >(), unitOfWorkMock)
            };
            RegisterDbSet(CreateCodeData <ServiceChannelType>(typeof(ServiceChannelTypeEnum)), unitOfWorkMockSetup);
            RegisterDbSet(CreateCodeData <PublishingStatusType>(typeof(PublishingStatus)), unitOfWorkMockSetup);

            RegisterDbSet(new List <ServiceChannel>(), unitOfWorkMockSetup);
            RegisterDbSet(new List <ServiceChannelVersioned>(), unitOfWorkMockSetup);
            RegisterDbSet(new List <Versioning>(), unitOfWorkMockSetup);

            itemListGenerator = new ItemListModelGenerator();
            conversion        = new TestConversion();
            itemListGenerator = new ItemListModelGenerator();
        }
        //private void CheckTranslation(VmLocationChannelStep2 step2, ServiceChannel target)
        //{
        //    target.WebPages.Count.Should().Be(step2.WebPages.Count, "WebPages");
        //    target.Id.Should().NotBe(Guid.Empty);
        //    // checks that special translator was called
        //    target.Emails.Count.Should().Be(1);
        //    target.Emails.First().Email.Value.Should().Be(step2.Email.Email);
        //    target.Phones.Count.Should().Be(1);
        //    target.Phones.First().CreatedBy.Should().Be(step2.PhoneNumber.Number);
        //}

        private void CheckTranslation(VmLocationChannel source, ServiceChannelVersioned target)
        {
            //target.Id.Should().NotBe(Guid.Empty);
            target.TypeId.Should().Be(ServiceChannelTypeEnum.ServiceLocation.ToString().GetGuid());
            //target.PublishingStatusId.Should().Be(source.PublishingStatusId.Value);
        }
 public override VmOpenApiPrintableFormChannelInVersionBase TranslateEntityToVm(ServiceChannelVersioned entity)
 {
     return(base.TranslateEntityToVm(entity));
 }
        protected ITranslationDefinitions <ServiceChannelVersioned, TVmOpenApiServiceChannel> CreateChannelDefinitions(ServiceChannelVersioned entity)
        {
            var commonForAllId = typesCache.Get <ServiceChannelConnectionType>(ServiceChannelConnectionTypeEnum.CommonForAll.ToString());

            return(CreateEntityViewModelDefinition(entity)
                   // We have to use unique root id as id!
                   .AddSimple(i => i.UnificRootId, o => o.Id)
                   .AddCollection(i => i.ServiceChannelNames, o => o.ServiceChannelNames)
                   .AddNavigation(i => typesCache.GetByValue <ServiceChannelType>(i.TypeId), o => o.ServiceChannelType)
                   .AddCollection(i => i.ServiceChannelDescriptions, o => o.ServiceChannelDescriptions)
                   .AddCollection(i => i.Languages.OrderBy(j => j.Order).ToList().Select(j => j.Language.Code).ToList(), o => o.Languages)
                   .AddCollection(i => i.WebPages, o => o.WebPages)
                   .AddCollection(i => i.ServiceChannelServiceHours.Select(x => x.ServiceHours).ToList().OrderBy(x => x.OrderNumber), o => o.ServiceHours)
                   // For support phones we only match items with type Phone.
                   .AddCollection(i => i.Phones.Where(p => p.Phone.TypeId == typesCache.Get <PhoneNumberType>(PhoneNumberTypeEnum.Phone.ToString())).Select(p => p.Phone).OrderBy(p => p.OrderNumber).ToList(), o => o.SupportPhones)
                   .AddCollection(i => i.Emails.Select(e => e.Email).OrderBy(e => e.OrderNumber), o => o.SupportEmails)
                   .AddNavigation(i => typesCache.GetByValue <PublishingStatusType>(i.PublishingStatusId), o => o.PublishingStatus)
                   .AddSimple(i => i.ConnectionTypeId == commonForAllId ? true : false, o => o.IsVisibleForAll)
                   .AddCollection(i => i.LanguageAvailabilities.Select(l => languageCache.GetByValue(l.LanguageId)).ToList(), o => o.AvailableLanguages)
                   .AddNavigation(i => i.AreaInformationTypeId.IsAssigned() ? typesCache.GetByValue <AreaInformationType>(i.AreaInformationTypeId.Value) : null, o => o.AreaType)
                   .AddCollection(i => i.AreaMunicipalities.Select(m => m.Municipality), o => o.AreaMunicipalities)
                   .AddCollection(i => i.Areas.Select(a => a.Area), o => o.Areas)
                   .AddCollection(i => i.UnificRoot?.ServiceServiceChannels, o => o.Services)
                   .AddSimple(i => i.Modified, o => o.Modified));
        }
 public override TVmOpenApiServiceChannel TranslateEntityToVm(ServiceChannelVersioned entity)
 {
     return(CreateChannelDefinitions(entity)
            .GetFinal());
 }
Exemplo n.º 20
0
 public override TVmOpenApiServiceChannelIn TranslateEntityToVm(ServiceChannelVersioned entity)
 {
     throw new NotImplementedException("No translation implemented in OpenApiServiceChannelInTranslator!");
 }
Exemplo n.º 21
0
 private void CheckTranslation(VmOpeningHoursStep model, ServiceChannelVersioned target)
 {
     //target.Id.Should().NotBe(Guid.Empty);
     target.ServiceChannelServiceHours.Select(i => i.ServiceHours).ToList().Count.Should().Be(model.StandardHours.Count + model.ExceptionHours.Count + model.SpecialHours.Count, "Opening hours");
 }