public void RightVersionNotFound(bool getOnlyPublished)
        {
            // Arrange
            var id               = Guid.NewGuid();
            var unitOfWork       = unitOfWorkMockSetup.Object;
            var contextManager   = new TestContextManager(unitOfWork, unitOfWork);
            var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var translationManagerMock = translationManagerMockSetup.Object;

            VersioningManagerMock.Setup(s => s.GetVersionId <OrganizationVersioned>(unitOfWork, id, PublishingStatus.Published, true)).Returns((Guid?)null);
            VersioningManagerMock.Setup(s => s.GetVersionId <OrganizationVersioned>(unitOfWork, id, null, false)).Returns((Guid?)null);

            var service = new DataAccess.Services.OrganizationService(contextManager, translationManagerMock, TranslationManagerVModel, Logger, OrganizationLogic,
                                                                      serviceUtilities, DataUtils, CommonService, AddressService, PublishingStatusCache, LanguageCache,
                                                                      VersioningManager, UserOrganizationChecker, CacheManager.TypesCache);

            // Act
            var result = service.GetOrganizationById(id, DefaultVersion, getOnlyPublished);

            // Assert
            result.Should().BeNull();
            if (getOnlyPublished)
            {
                VersioningManagerMock.Verify(x => x.GetVersionId <OrganizationVersioned>(unitOfWork, id, PublishingStatus.Published, true), Times.Once());
            }
            else
            {
                VersioningManagerMock.Verify(x => x.GetVersionId <OrganizationVersioned>(unitOfWork, id, null, false), Times.Once());
            }
        }
        private ChannelService Arrange(ServiceChannelTypeEnum channelType, List <ServiceChannelVersioned> list = null)
        {
            var channelList      = list ?? _channelList;
            var publishedChannel = channelList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault();

            publishedChannel.TypeId = TypeCache.Get <ServiceChannelType>(channelType.ToString());
            var id = publishedChannel.Id;

            unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes(
                                          It.IsAny <IQueryable <ServiceChannelVersioned> >(),
                                          It.IsAny <Func <IQueryable <ServiceChannelVersioned>, IQueryable <ServiceChannelVersioned> > >(),
                                          It.IsAny <bool>()
                                          )).Returns((IQueryable <ServiceChannelVersioned> channelServices, Func <IQueryable <ServiceChannelVersioned>, IQueryable <ServiceChannelVersioned> > func, bool applyFilters) =>
            {
                return(channelServices);
            }
                                                     );
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

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

            ArrangeTranslationManager(channelType);

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

            // repositories
            ChannelRepoMock.Setup(g => g.All()).Returns(channelList.AsQueryable());

            return(new ChannelService(contextManager, UserIdentification, translationManagerMockSetup.Object, TranslationManagerVModel,
                                      Logger, ServiceChannelLogic, serviceUtilities, CommonService, new VmListItemLogic(), DataUtils, new VmOwnerReferenceLogic(),
                                      AddressService, CacheManager, PublishingStatusCache, VersioningManager, UserOrganizationChecker, UrlService));
        }
        public void ApplyIncludesReturnsNull()
        {
            // Arrange
            var organizationList    = EntityGenerator.GetOrganizationEntityList(1, PublishingStatusCache);
            var deletedOrganization = organizationList.Where(o => o.PublishingStatusId == DeletedId).FirstOrDefault();
            var id = deletedOrganization.Id;

            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 <OrganizationVersioned, VmOpenApiOrganizationSaha>(deletedOrganization))
            .Returns(new VmOpenApiOrganizationSaha());
            var translationManagerMock = translationManagerMockSetup.Object;

            VersioningManagerMock.Setup(s => s.GetVersionId <OrganizationVersioned>(unitOfWork, id, PublishingStatus.Published, true)).Returns(Guid.NewGuid());

            OrganizationRepoMock.Setup(g => g.All()).Returns(organizationList.AsQueryable());

            var service = new DataAccess.Services.OrganizationService(contextManager, translationManagerMock, TranslationManagerVModel, Logger, OrganizationLogic,
                                                                      serviceUtilities, DataUtils, CommonService, AddressService, PublishingStatusCache, LanguageCache,
                                                                      VersioningManager, UserOrganizationChecker, CacheManager.TypesCache);

            // Act
            Action act = () => service.GetOrganizationSahaById(id);

            // Assert
            act.ShouldThrow <Exception>();
        }
Example #4
0
        public void ExternalSourceNotExists()
        {
            // Arrange
            var sourceId       = "sourceId";
            var userName       = "******";
            var entityName     = typeof(Model.Models.Service).Name;
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns(userName);

            ExternalSourceRepoMock.Setup(s => s.All())
            .Returns(new List <ExternalSource>()
            {
                new ExternalSource {
                    SourceId = sourceId, RelationId = userName, ObjectType = entityName
                }
            }.AsQueryable());

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, _serviceId, null, false))
            .Returns((Guid?)null);

            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var service = new ServiceService(contextManager, translationManagerMockSetup.Object, TranslationManagerVModel, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

            // Act
            Action act = () => service.SaveService(new VmOpenApiServiceInVersionBase(), false, DefaultVersion, false, sourceId);

            // Assert
            act.ShouldThrowExactly <Exception>(string.Format(CoreMessages.OpenApi.EntityNotFound, entityName, sourceId));
        }
Example #5
0
        public void RightVersionNotFound()
        {
            // Arrange
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns("user");

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, _serviceId, null, false))
            .Returns((Guid?)null);

            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var service = new ServiceService(contextManager, translationManagerMockSetup.Object, TranslationManagerVModel, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

            // Act
            var result = service.SaveService(new VmOpenApiServiceInVersionBase {
                Id = _serviceId
            }, false, DefaultVersion, false);

            // Assert
            result.Should().BeNull();
            translationManagerVModelMockSetup.Verify(x => x.Translate <IVmOpenApiServiceInVersionBase, ServiceVersioned>(It.IsAny <VmOpenApiServiceInVersionBase>(), unitOfWork), Times.Never());
        }
        private DataAccess.Services.OrganizationService Arrange(List <OrganizationVersioned> list = null)
        {
            var organizationList      = list ?? _organizationList;
            var publishedOrganization = organizationList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault();
            var id     = publishedOrganization.Id;
            var rootId = publishedOrganization.UnificRootId;

            unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes(
                                          It.IsAny <IQueryable <OrganizationVersioned> >(),
                                          It.IsAny <Func <IQueryable <OrganizationVersioned>, IQueryable <OrganizationVersioned> > >(),
                                          It.IsAny <bool>()
                                          )).Returns((IQueryable <OrganizationVersioned> orgList, Func <IQueryable <OrganizationVersioned>, IQueryable <OrganizationVersioned> > func, bool applyfilters) =>
            {
                return(orgList);
            });
            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 <OrganizationVersioned, VmOpenApiOrganizationVersionBase>(It.IsAny <OrganizationVersioned>()))
            .Returns((OrganizationVersioned org) =>
            {
                if (org == null)
                {
                    return(null);
                }
                return(new VmOpenApiOrganizationVersionBase {
                    Id = org.UnificRootId, Modified = org.Modified, PublishingStatus = TypeCache.GetByValue <PublishingStatusType>(org.PublishingStatusId)
                });
            });

            var translationManagerMock = translationManagerMockSetup.Object;

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

            // repositories
            OrganizationRepoMock.Setup(g => g.All()).Returns(organizationList.AsQueryable());
            OrganizationNameRepoMock.Setup(m => m.All()).Returns(Enumerable.Empty <OrganizationName>().AsQueryable());
            var serviceNameRepoMock = new Mock <IServiceNameRepository>();

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceNameRepository>()).Returns(serviceNameRepoMock.Object);
            var organizationServiceRepoMock = new Mock <IOrganizationServiceRepository>();

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IOrganizationServiceRepository>()).Returns(organizationServiceRepoMock.Object);
            var serviceRepoMock = new Mock <IServiceVersionedRepository>();

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceVersionedRepository>()).Returns(serviceRepoMock.Object);
            var serviceProducerRepoMock = new Mock <IServiceProducerOrganizationRepository>();

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceProducerOrganizationRepository>()).Returns(serviceProducerRepoMock.Object);

            return(new DataAccess.Services.OrganizationService(contextManager, translationManagerMock, TranslationManagerVModel, Logger, OrganizationLogic,
                                                               serviceUtilities, DataUtils, CommonService, AddressService, PublishingStatusCache, LanguageCache,
                                                               VersioningManager, UserOrganizationChecker, CacheManager.TypesCache));
        }
Example #7
0
        public void GdAttached_AttachProposedChannels()
        {
            // Arrange
            var userName     = "******";
            var gdId         = Guid.NewGuid();
            var descriptions = TestDataFactory.CreateLocalizedList("Description");
            var entityName   = typeof(Model.Models.Service).Name;
            var vm           = new VmOpenApiServiceInVersionBase
            {
                Id = _serviceId,
                StatutoryServiceGeneralDescriptionId = gdId.ToString()
            };
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns(userName);

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, _serviceId, null, false))
            .Returns(_serviceVersionedId);

            gdServiceMock.Setup(g => g.GetGeneralDescriptionVersionBase(It.IsAny <Guid>(), 0, true))
            .Returns(new VmOpenApiGeneralDescriptionVersionBase()
            {
                ServiceChannels = new List <V6VmOpenApiServiceServiceChannel>
                {
                    new V6VmOpenApiServiceServiceChannel {
                        ServiceChannel = new VmOpenApiItem {
                            Id = _channelId
                        }, Description = descriptions
                    }
                }
            });

            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var service = new ServiceService(contextManager, translationManagerMockSetup.Object, TranslationManagerVModel, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

            // Act
            var result = service.SaveService(vm, false, DefaultVersion, true);

            // Assert
            result.Should().NotBeNull();
            var vmResult = Assert.IsType <V7VmOpenApiService>(result);

            vmResult.StatutoryServiceGeneralDescriptionId.Should().Be(gdId);
            vmResult.ServiceChannels.Should().NotBeNull();
            vmResult.ServiceChannels.Count.Should().Be(1);
            translationManagerVModelMockSetup.Verify(x => x.Translate <IVmOpenApiServiceInVersionBase, ServiceVersioned>(It.IsAny <VmOpenApiServiceInVersionBase>(), unitOfWork), Times.Once());
            translationManagerMockSetup.Verify(x => x.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>()), Times.Once());
        }
Example #8
0
        public void GdAttached_MapDataFormGD()
        {
            // Arrange
            var userName     = "******";
            var gdId         = Guid.NewGuid();
            var gdType       = ServiceTypeEnum.PermissionAndObligation.ToString();
            var gdChargeType = ServiceChargeTypeEnum.Free.ToString();
            var vm           = new VmOpenApiServiceInVersionBase
            {
                Id = _serviceId,
                StatutoryServiceGeneralDescriptionId = gdId.ToString()
            };
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns(userName);

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, _serviceId, null, false))
            .Returns(_serviceVersionedId);

            gdServiceMock.Setup(g => g.GetGeneralDescriptionSimple(unitOfWork, It.IsAny <Guid>()))
            .Returns(new VmOpenApiGeneralDescriptionVersionBase()
            {
                Type = gdType,
                ServiceChargeType = gdChargeType
            });
            gdServiceMock.Setup(g => g.GetGeneralDescriptionVersionBase(It.IsAny <Guid>(), 0, true))
            .Returns(new VmOpenApiGeneralDescriptionVersionBase()
            {
                Type = gdType,
                ServiceChargeType = gdChargeType
            });

            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var service = new ServiceService(contextManager, translationManagerMockSetup.Object, TranslationManagerVModel, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

            // Act
            var result = service.SaveService(vm, false, DefaultVersion, true);

            // Assert
            result.Should().NotBeNull();
            var vmResult = Assert.IsType <V7VmOpenApiService>(result);

            vmResult.StatutoryServiceGeneralDescriptionId.Should().Be(gdId);
            vmResult.Type.Should().Be(gdType);
            vmResult.ServiceChargeType.Should().BeNull(); // service charge type is not gotten from GD (in GET) so should be null
            translationManagerVModelMockSetup.Verify(x => x.Translate <IVmOpenApiServiceInVersionBase, ServiceVersioned>(It.IsAny <VmOpenApiServiceInVersionBase>(), unitOfWork), Times.Once());
            translationManagerMockSetup.Verify(x => x.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>()), Times.Once());
        }
Example #9
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));
        }
Example #10
0
        public void GetLatestService(PublishingStatus publishingStatus)
        {
            // Arrange
            var item   = _list.Where(i => i.PublishingStatusId == PublishingStatusCache.Get(publishingStatus)).FirstOrDefault();
            var rootId = item.UnificRootId;
            var id     = item.Id;

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWorkMockSetup.Object, rootId, null, false)).Returns(id);
            var service = Arrange();

            // Act
            var result = service.GetServiceById(rootId, 7, VersionStatusEnum.Latest);

            // Assert
            result.Should().NotBeNull();
            var vmResult = Assert.IsType <V7VmOpenApiService>(result);

            vmResult.PublishingStatus.Should().Be(publishingStatus.ToString());
            VersioningManagerMock.Verify(x => x.GetVersionId <ServiceVersioned>(unitOfWorkMockSetup.Object, rootId, null, false), Times.Once);
        }
        public void GetLatestActiveServiceChannel(PublishingStatus publishingStatus)
        {
            // Arrange
            var channelType = ServiceChannelTypeEnum.ServiceLocation;
            var item        = _channelList.Where(i => i.PublishingStatusId == PublishingStatusCache.Get(publishingStatus)).FirstOrDefault();

            item.TypeId = TypeCache.Get <ServiceChannelType>(channelType.ToString());
            var rootId = item.UnificRootId;
            var id     = item.Id;

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceChannelVersioned>(unitOfWorkMockSetup.Object, rootId, null, true))
            .Returns(() =>
            {
                if (publishingStatus == PublishingStatus.Deleted || publishingStatus == PublishingStatus.OldPublished)
                {
                    return(null);
                }

                return(id);
            });

            var service = Arrange(channelType);

            // Act
            var result = service.GetServiceChannelById(rootId, 7, VersionStatusEnum.LatestActive);

            // Assert
            // Method should only return draft, modified or published versions.
            VersioningManagerMock.Verify(x => x.GetVersionId <ServiceChannelVersioned>(unitOfWorkMockSetup.Object, rootId, null, true), Times.Once);
            if (publishingStatus == PublishingStatus.Draft || publishingStatus == PublishingStatus.Modified || publishingStatus == PublishingStatus.Published)
            {
                result.Should().NotBeNull();
                var vmResult = Assert.IsType <V7VmOpenApiServiceLocationChannel>(result);
                vmResult.PublishingStatus.Should().Be(publishingStatus.ToString());
            }
            else
            {
                result.Should().BeNull();
            }
        }
        public void RightVersionNotFound(VersionStatusEnum status)
        {
            // Arrange
            var id               = Guid.NewGuid();
            var unitOfWork       = unitOfWorkMockSetup.Object;
            var contextManager   = new TestContextManager(unitOfWork, unitOfWork);
            var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceChannelVersioned>(unitOfWork, id, PublishingStatus.Published, true)).Returns((Guid?)null);
            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceChannelVersioned>(unitOfWork, id, null, true)).Returns((Guid?)null);

            var service = new ChannelService(contextManager, UserIdentification, translationManagerMockSetup.Object, TranslationManagerVModel,
                                             Logger, ServiceChannelLogic, serviceUtilities, CommonService, new VmListItemLogic(), DataUtils, new VmOwnerReferenceLogic(),
                                             AddressService, CacheManager, PublishingStatusCache, VersioningManager, UserOrganizationChecker, UrlService);

            // Act
            var result = service.GetServiceChannelById(id, DefaultVersion, status);

            // Assert
            result.Should().BeNull();
        }
Example #13
0
        public void ExternalSourceExists()
        {
            // Arrange
            var sourceId       = "sourceId";
            var userName       = "******";
            var entityName     = typeof(Model.Models.Service).Name;
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns(userName);

            ExternalSourceRepoMock.Setup(s => s.All())
            .Returns(new List <ExternalSource>()
            {
                new ExternalSource {
                    SourceId = sourceId, RelationId = userName, ObjectType = entityName, PTVId = _serviceId
                }
            }.AsQueryable());

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, _serviceId, null, false))
            .Returns(_serviceVersionedId);

            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var service = new ServiceService(contextManager, translationManagerMockSetup.Object, TranslationManagerVModel, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

            // Act
            var result = service.SaveService(new VmOpenApiServiceInVersionBase(), false, DefaultVersion, false, sourceId);

            // Assert
            result.Should().NotBeNull();
            var vmResult = Assert.IsType <V7VmOpenApiService>(result);

            translationManagerVModelMockSetup.Verify(x => x.Translate <IVmOpenApiServiceInVersionBase, ServiceVersioned>(It.IsAny <VmOpenApiServiceInVersionBase>(), unitOfWork), Times.Once());
            translationManagerMockSetup.Verify(x => x.Translate <ServiceVersioned, VmOpenApiServiceVersionBase>(It.IsAny <ServiceVersioned>()), Times.Once());
        }
Example #14
0
        private GeneralDescriptionService Arrange()
        {
            var gdList      = _gdList;
            var publishedGd = gdList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault();
            var id          = publishedGd.Id;

            unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes(
                                          It.IsAny <IQueryable <StatutoryServiceGeneralDescriptionVersioned> >(),
                                          It.IsAny <Func <IQueryable <StatutoryServiceGeneralDescriptionVersioned>, IQueryable <StatutoryServiceGeneralDescriptionVersioned> > >(),
                                          It.IsAny <bool>()
                                          )).Returns(new List <StatutoryServiceGeneralDescriptionVersioned> {
                publishedGd
            }.AsQueryable());
            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 <StatutoryServiceGeneralDescriptionVersioned, VmOpenApiGeneralDescriptionVersionBase>(_publishedGd))
            .Returns(new VmOpenApiGeneralDescriptionVersionBase());

            var translationManagerMock = translationManagerMockSetup.Object;

            VersioningManagerMock.Setup(s => s.GetVersionId <StatutoryServiceGeneralDescriptionVersioned>(unitOfWork, id, PublishingStatus.Published, true)).Returns(Guid.NewGuid());

            // repositories
            GdRepoMock.Setup(g => g.All()).Returns(gdList.AsQueryable());
            var serviceChannelNameRepoMock = new Mock <IServiceChannelNameRepository>();

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IServiceChannelNameRepository>()).Returns(serviceChannelNameRepoMock.Object);

            return(new GeneralDescriptionService(contextManager, UserIdentification, translationManagerMockSetup.Object, TranslationManagerVModel,
                                                 Logger, serviceUtilities, CommonService, PublishingStatusCache, UserOrganizationChecker, LanguageCache, TypeCache,
                                                 VersioningManager, DataUtils, ValidationManagerMock));
        }
Example #15
0
        public void RightVersionNotFound(VersionStatusEnum status)
        {
            // Arrange
            var id               = Guid.NewGuid();
            var unitOfWork       = unitOfWorkMockSetup.Object;
            var contextManager   = new TestContextManager(unitOfWork, unitOfWork);
            var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var translationManagerMock = translationManagerMockSetup.Object;

            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, id, PublishingStatus.Published, true)).Returns((Guid?)null);
            VersioningManagerMock.Setup(s => s.GetVersionId <ServiceVersioned>(unitOfWork, id, null, It.IsAny <bool>())).Returns((Guid?)null);

            var service = new ServiceService(contextManager, translationManagerMock, TranslationManagerVModel, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

            // Act
            var result = service.GetServiceById(id, DefaultVersion, status);

            // Assert
            result.Should().BeNull();
        }
Example #16
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);
            });
        }