Beispiel #1
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());
        }
Beispiel #2
0
        public void ExternalSourceForServiceNotExists()
        {
            // Arrange
            var sourceId = "sourceId";
            var userName = "******";

            ExternalSourceRepoMock.Setup(s => s.All())
            .Returns(new List <ExternalSource>()
            {
                new ExternalSource {
                    SourceId = "someOtherSourceId", RelationId = userName, ObjectType = typeof(Model.Models.Service).Name
                }
            }.AsQueryable());

            var unitOfWork = unitOfWorkMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns(userName);
            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);
            var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object,
                                                       Logger, serviceUtilities, DataUtils, ServiceService, ChannelService, PublishingStatusCache, VersioningManager, UserOrganizationChecker,
                                                       CacheManager, UserOrganizationService);

            // Act
            Action act = () => service.SaveServiceConnectionsBySource(sourceId, new V7VmOpenApiServiceAndChannelRelationBySourceAsti(), DefaultVersion);

            // Assert
            act.ShouldThrowExactly <Exception>(CoreMessages.OpenApi.RelationIdNotFound);
        }
Beispiel #3
0
        public void Add_ExternalSourceExists()
        {
            // Arrange
            var sourceId       = "sourceId";
            var userName       = "******";
            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 = typeof(Model.Models.Service).Name
                }
            }.AsQueryable());
            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.AddService(new VmOpenApiServiceInVersionBase()
            {
                SourceId = sourceId
            }, false, DefaultVersion, false);

            // Assert
            act.ShouldThrowExactly <ExternalSourceExistsException>(string.Format(CoreMessages.OpenApi.ExternalSourceExists, sourceId));
        }
Beispiel #4
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());
        }
Beispiel #5
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());
        }
Beispiel #6
0
        public void Add_PublishedEntity()
        {
            // Arrange
            var sourceId        = "sourceId";
            var userName        = "******";
            var gdId            = Guid.NewGuid();
            var list            = EntityGenerator.GetServiceEntityList(1, PublishingStatusCache);
            var publishedEntity = list.Where(i => i.PublishingStatusId == PublishedId).FirstOrDefault();
            var vm = new VmOpenApiServiceInVersionBase()
            {
                SourceId         = sourceId,
                PublishingStatus = PublishingStatus.Published.ToString()
            };

            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 + "2", RelationId = userName, ObjectType = typeof(Model.Models.Service).Name
                }
            }.AsQueryable());     // does not return same source id
            gdServiceMock.Setup(s => s.GetGeneralDescriptionVersionBase(gdId, 0, true)).Returns(new VmOpenApiGeneralDescriptionVersionBase());

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

            CommonServiceMock.Setup(s => s.PublishAllAvailableLanguageVersions <ServiceVersioned, ServiceLanguageAvailability>(_serviceVersionedId, It.IsAny <Expression <Func <ServiceLanguageAvailability, bool> > >()))
            .Returns(new PublishingResult());

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

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

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

            vmResult.PublishingStatus.Should().Be(PublishingStatus.Published.ToString());
            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());
            CommonServiceMock.Verify(x => x.PublishAllAvailableLanguageVersions <ServiceVersioned, ServiceLanguageAvailability>(_serviceVersionedId, It.IsAny <Expression <Func <ServiceLanguageAvailability, bool> > >()), Times.Once());
        }
        private ChannelService Arrange(IVmOpenApiServiceChannelIn vm, ServiceChannelTypeEnum channelType)
        {
            var userName = "******";

            publishedEntity.TypeId = TypeCache.Get <ServiceChannelType>(channelType.ToString());

            unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes(
                                          It.IsAny <IQueryable <ServiceChannelVersioned> >(),
                                          It.IsAny <Func <IQueryable <ServiceChannelVersioned>, IQueryable <ServiceChannelVersioned> > >(),
                                          It.IsAny <bool>()
                                          )).Returns(new List <ServiceChannelVersioned> {
                publishedEntity
            }.AsQueryable());
            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 + "2", RelationId = userName, ObjectType = typeof(Model.Models.ServiceChannel).Name
                }
            }.AsQueryable());     // does not return same source id

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

            translationManagerVModelMockSetup.Setup(t => t.Translate <IVmOpenApiServiceChannelIn, ServiceChannelVersioned>(vm, unitOfWork))
            .Returns(publishedEntity);
            translationManagerVModelMockSetup.Setup(t => t.TranslateAll <VmOpenApiConnection, ServiceServiceChannel>(It.IsAny <List <VmOpenApiConnection> >(), unitOfWork))
            .Returns(new List <ServiceServiceChannel>());

            ArrangeTranslationManager(channelType);

            CommonServiceMock.Setup(s => s.PublishAllAvailableLanguageVersions <ServiceChannelVersioned, ServiceChannelLanguageAvailability>(publishedEntity.Id, It.IsAny <Expression <Func <ServiceChannelLanguageAvailability, bool> > >()))
            .Returns(new PublishingResult());

            return(new ChannelService(contextManager, UserIdentification, translationManagerMockSetup.Object, TranslationManagerVModel,
                                      Logger, ServiceChannelLogic, serviceUtilities, CommonService, new VmListItemLogic(), DataUtils, new VmOwnerReferenceLogic(),
                                      AddressService, CacheManager, PublishingStatusCache, VersioningManager, UserOrganizationChecker, UrlService));
        }
Beispiel #8
0
        public void CannotGetUser()
        {
            // Arrange
            var unitOfWork = unitOfWorkMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns((string)null);
            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);
            var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object,
                                                       Logger, serviceUtilities, DataUtils, ServiceService, ChannelService, PublishingStatusCache, VersioningManager, UserOrganizationChecker,
                                                       CacheManager, UserOrganizationService);

            // Act
            Action act = () => service.SaveServiceConnectionsBySource(null, new V7VmOpenApiServiceAndChannelRelationBySourceAsti(), DefaultVersion);

            // Assert
            act.ShouldThrowExactly <Exception>(CoreMessages.OpenApi.RelationIdNotFound);
        }
Beispiel #9
0
        public void Add_CannotGetUser()
        {
            // Arrange
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns((string)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.AddService(new VmOpenApiServiceInVersionBase(), false, DefaultVersion, false);

            // Assert
            act.ShouldThrowExactly <Exception>(CoreMessages.OpenApi.RelationIdNotFound);
        }
Beispiel #10
0
        public void Add_DraftEntity()
        {
            // Arrange
            var userName    = "******";
            var list        = EntityGenerator.GetServiceEntityList(1, PublishingStatusCache);
            var draftEntity = list.Where(i => i.PublishingStatusId == PublishingStatusCache.Get(PublishingStatus.Draft)).FirstOrDefault();
            var vm          = new VmOpenApiServiceInVersionBase()
            {
                PublishingStatus = PublishingStatus.Draft.ToString()
            };

            var unitOfWork = unitOfWorkMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

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

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

            CommonServiceMock.Setup(s => s.PublishAllAvailableLanguageVersions <ServiceVersioned, ServiceLanguageAvailability>(draftEntity.Id, It.IsAny <Expression <Func <ServiceLanguageAvailability, bool> > >()))
            .Returns(new PublishingResult());

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

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

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

            vmResult.PublishingStatus.Should().Be(PublishingStatus.Draft.ToString());
            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());
            CommonServiceMock.Verify(x => x.PublishAllAvailableLanguageVersions <ServiceVersioned, ServiceLanguageAvailability>(_serviceId, It.IsAny <Expression <Func <ServiceLanguageAvailability, bool> > >()), Times.Never());
        }
Beispiel #11
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());
        }
Beispiel #12
0
        public void CanModifyConnections()
        {
            // Arrange
            var serviceSourceId = "sourceId";
            var channelSourceId = "sourceId2";
            var serviceId       = Guid.NewGuid();
            var channelId       = Guid.NewGuid();
            var userName        = "******";
            var request         = new V7VmOpenApiServiceAndChannelRelationBySourceAsti()
            {
                ChannelRelations = new List <V7VmOpenApiServiceServiceChannelBySourceAsti>
                {
                    new V7VmOpenApiServiceServiceChannelBySourceAsti
                    {
                        ServiceChannelSourceId = channelSourceId,
                    }
                }
            };

            ExternalSourceRepoMock.Setup(s => s.All())
            .Returns(new List <ExternalSource>()
            {
                new ExternalSource {
                    PTVId = serviceId, SourceId = serviceSourceId, RelationId = userName, ObjectType = typeof(Model.Models.Service).Name
                },
                new ExternalSource {
                    PTVId = channelId, SourceId = channelSourceId, RelationId = userName, ObjectType = typeof(ServiceChannel).Name
                }
            }.AsQueryable());

            var unitOfWork = unitOfWorkMockSetup.Object;

            translationManagerVModelMockSetup.Setup(s => s.Translate <V7VmOpenApiServiceAndChannelRelationAstiInBase, Model.Models.Service>(It.IsAny <V7VmOpenApiServiceAndChannelRelationAstiInBase>(), unitOfWork))
            .Returns(new Model.Models.Service()
            {
                Id = serviceId,
            });

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            UserIdentificationMock.Setup(s => s.UserName).Returns(userName);
            var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            ChannelServiceMock.Setup(s => s.GetServiceChannelByIdSimple(channelId, true))
            .Returns(new VmOpenApiServiceChannel
            {
                ServiceChannelType = ServiceChannelTypeEnum.ServiceLocation.ToString(),
                Security           = new VmSecurityOwnOrganization {
                    IsOwnOrganization = true
                }
            });

            var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object,
                                                       Logger, serviceUtilities, DataUtils, ServiceService, ChannelServiceMock.Object, PublishingStatusCache, VersioningManager, UserOrganizationChecker,
                                                       CacheManager, UserOrganizationService);

            // Act
            var result = service.SaveServiceConnectionsBySource(serviceSourceId, request, DefaultVersion);

            // Assert
            // We are not testing method GetServiceById so we expect result to be null.
            result.Should().BeNull();
            translationManagerVModelMockSetup.Verify(t => t.Translate <V7VmOpenApiServiceAndChannelRelationAstiInBase, Model.Models.Service>(It.IsAny <V7VmOpenApiServiceAndChannelRelationAstiInBase>(), unitOfWork), Times.Once());
        }
Beispiel #13
0
        public void Add_GDAttached_AttachProposedChannels()
        {
            // Arrange
            var userName        = "******";
            var gdId            = Guid.NewGuid();
            var descriptions    = TestDataFactory.CreateLocalizedList("Description");
            var list            = EntityGenerator.GetServiceEntityList(1, PublishingStatusCache);
            var publishedEntity = list.Where(i => i.PublishingStatusId == PublishedId).FirstOrDefault();

            publishedEntity.StatutoryServiceGeneralDescriptionId = gdId;
            var vm = new VmOpenApiServiceInVersionBase()
            {
                PublishingStatus = PublishingStatus.Published.ToString(),
                StatutoryServiceGeneralDescriptionId = gdId.ToString(),
            };

            var unitOfWork = unitOfWorkMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

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

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

            CommonServiceMock.Setup(s => s.PublishAllAvailableLanguageVersions <ServiceVersioned, ServiceLanguageAvailability>(publishedEntity.Id, It.IsAny <Expression <Func <ServiceLanguageAvailability, bool> > >()))
            .Returns(new PublishingResult());

            gdServiceMock.Setup(g => g.GetGeneralDescriptionSimple(unitOfWork, It.IsAny <Guid>()))
            .Returns(new VmOpenApiGeneralDescriptionVersionBase()
            {
                ServiceChannels = new List <V6VmOpenApiServiceServiceChannel>
                {
                    new V6VmOpenApiServiceServiceChannel {
                        ServiceChannel = new VmOpenApiItem {
                            Id = _channelId
                        }, Description = descriptions
                    }
                }
            });
            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 service = new ServiceService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object, Logger, serviceUtilities,
                                             DataUtils, CommonService, new VmOwnerReferenceLogic(), CacheManager.TypesCache, LanguageCache, PublishingStatusCache,
                                             VersioningManager, gdService, UserOrganizationChecker);

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

            // 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());
            CommonServiceMock.Verify(x => x.PublishAllAvailableLanguageVersions <ServiceVersioned, ServiceLanguageAvailability>(publishedEntity.Id, It.IsAny <Expression <Func <ServiceLanguageAvailability, bool> > >()), Times.Never());
            gdServiceMock.Verify(x => x.GetGeneralDescriptionVersionBase(It.IsAny <Guid>(), 0, true), Times.Exactly(1)); // Saving
            gdServiceMock.Verify(x => x.GetGeneralDescriptionVersionBase(It.IsAny <Guid>(), 0, true), Times.Exactly(1)); // Geting
            vmResult.StatutoryServiceGeneralDescriptionId.Should().Be(gdId);
            vmResult.ServiceChannels.Should().NotBeNull();
            vmResult.ServiceChannels.Count.Should().Be(1);
        }