Ejemplo n.º 1
0
        private ServiceService Arrange(List <ServiceVersioned> list = null)
        {
            var serviceList   = list ?? _list;
            var publishedItem = serviceList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault();
            var id            = publishedItem.Id;
            var rootId        = publishedItem.UnificRootId;

            unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes(
                                          It.IsAny <IQueryable <ServiceVersioned> >(),
                                          It.IsAny <Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > >(),
                                          It.IsAny <bool>()
                                          )).Returns((IQueryable <ServiceVersioned> services, Func <IQueryable <ServiceVersioned>, IQueryable <ServiceVersioned> > func, bool applyFilters) =>
            {
                return(services);
            });

            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            translationManagerMockSetup.Setup(t => t.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>()))
            .Returns((ServiceVersioned entity) =>
            {
                if (entity == null)
                {
                    return(null);
                }

                return(new VmOpenApiServiceVersionBase()
                {
                    Id = entity.UnificRootId, PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId)
                });
            });

            var translationManagerMock = translationManagerMockSetup.Object;

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, rootId, PublishingStatus.Published, true)).Returns(id);

            // repositories
            ServiceRepoMock.Setup(g => g.All()).Returns(serviceList.AsQueryable());
            ServiceNameRepoMock.Setup(m => m.All()).Returns(Enumerable.Empty <ServiceName>().AsQueryable());
            var serviceNameRepoMock = new Mock <IServiceNameRepository>();

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceNameRepository>()).Returns(serviceNameRepoMock.Object);

            return(new ServiceService(contextManager, translationManagerMock, TranslationManagerVModel, Logger, serviceUtilities,
                                      DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                      VersioningManager, gdService, UserOrganizationChecker));
        }
Ejemplo n.º 2
0
        internal void ArrangeTranslationManager(ServiceChannelTypeEnum channelType)
        {
            translationManagerMockSetup.Setup(t => t.Translate <ServiceChannelVersioned, VmOpenApiElectronicChannelVersionBase>(It.IsAny <ServiceChannelVersioned>()))
            .Returns((ServiceChannelVersioned entity) =>
            {
                if (channelType != ServiceChannelTypeEnum.EChannel)
                {
                    return(new VmOpenApiElectronicChannelVersionBase());
                }
                return(new VmOpenApiElectronicChannelVersionBase()
                {
                    Id = entity.UnificRootId,
                    PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId)
                });
            });

            translationManagerMockSetup.Setup(t => t.Translate <ServiceChannelVersioned, VmOpenApiPhoneChannelVersionBase>(It.IsAny <ServiceChannelVersioned>()))
            .Returns((ServiceChannelVersioned entity) =>
            {
                if (channelType != ServiceChannelTypeEnum.Phone)
                {
                    return(new VmOpenApiPhoneChannelVersionBase());
                }
                return(new VmOpenApiPhoneChannelVersionBase()
                {
                    Id = entity.UnificRootId,
                    PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId)
                });
            });

            translationManagerMockSetup.Setup(t => t.Translate <ServiceChannelVersioned, VmOpenApiServiceLocationChannelVersionBase>(It.IsAny <ServiceChannelVersioned>()))
            .Returns((ServiceChannelVersioned entity) =>
            {
                if (channelType != ServiceChannelTypeEnum.ServiceLocation)
                {
                    return(new VmOpenApiServiceLocationChannelVersionBase());
                }
                return(new VmOpenApiServiceLocationChannelVersionBase()
                {
                    Id = entity.UnificRootId,
                    PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId)
                });
            });

            translationManagerMockSetup.Setup(t => t.Translate <ServiceChannelVersioned, VmOpenApiPrintableFormChannelVersionBase>(It.IsAny <ServiceChannelVersioned>()))
            .Returns((ServiceChannelVersioned entity) =>
            {
                if (channelType != ServiceChannelTypeEnum.PrintableForm)
                {
                    return(new VmOpenApiPrintableFormChannelVersionBase());
                }
                return(new VmOpenApiPrintableFormChannelVersionBase()
                {
                    Id = entity.UnificRootId,
                    PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId)
                });
            });

            translationManagerMockSetup.Setup(t => t.Translate <ServiceChannelVersioned, VmOpenApiWebPageChannelVersionBase>(It.IsAny <ServiceChannelVersioned>()))
            .Returns((ServiceChannelVersioned entity) =>
            {
                if (channelType != ServiceChannelTypeEnum.WebPage)
                {
                    return(new VmOpenApiWebPageChannelVersionBase());
                }
                return(new VmOpenApiWebPageChannelVersionBase()
                {
                    Id = entity.UnificRootId,
                    PublishingStatus = PublishingStatusCache.GetByValue(entity.PublishingStatusId)
                });
            });
        }
Ejemplo n.º 3
0
        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);
            });
        }