Beispiel #1
0
        private IVmOpenApiServiceBase GetAndUpdateService(IDataMapper mapper, int serviceId)
        {
            IVmOpenApiServiceBase vmResult = new VmOpenApiServiceVersionBase();

            if (alreadyUpdatedServices.Contains(serviceId))
            {
                return(vmResult);
            }

            try
            {
                var vmService = mapper.MapService(serviceId);
                if (!Settings.DebugData)
                {
                    try
                    {
                        vmResult = serviceService.AddService(vmService, false, 0, UserName);
                    }
                    catch (ExternalSourceExistsException ex)
                    {
                        // The external source for service is already in use so the item was already created into PTV. Let's update the data.
                        vmResult = serviceService.SaveService(vmService, false, 0, vmService.SourceId, UserName);
                    }
                }
                else
                {
                    vmResult = serviceService.GetServiceBySource(vmService.SourceId, 0, userName: UserName);
                }
                serviceUpdateSuccessCount++;
                alreadyUpdatedServices.Add(serviceId);
            }
            catch (Exception ex)
            {
                logger.LogError($"Error occured while updating a service: { serviceId }. { ex.Message }");
                serviceUpdateFailedCount++;
                if (!failedServices.Contains(serviceId))
                {
                    failedServices.Add(serviceId);
                }
                if (ex is EndPointNotFoundException)
                {
                    serviceEndpointNotFoundCount++;
                }
            }
            return(vmResult);
        }
Beispiel #2
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);
            });
        }