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()); }
public void Add_WebPageChannel() { // Arrange var service = Arrange(vm, ServiceChannelTypeEnum.WebPage); // Act var result = service.AddServiceChannel(vm, false, DefaultVersion, null); // Assert result.Should().NotBeNull(); result.Should().BeOfType <V7VmOpenApiWebPageChannel>(); translationManagerVModelMockSetup.Verify(x => x.Translate <IVmOpenApiServiceChannelIn, ServiceChannelVersioned>(It.IsAny <VmOpenApiServiceChannelIn>(), unitOfWorkMockSetup.Object), Times.Once()); translationManagerMockSetup.Verify(x => x.Translate <ServiceChannelVersioned, VmOpenApiWebPageChannelVersionBase>(It.IsAny <ServiceChannelVersioned>()), Times.Once()); CommonServiceMock.Verify(x => x.PublishAllAvailableLanguageVersions <ServiceChannelVersioned, ServiceChannelLanguageAvailability>(publishedEntity.Id, It.IsAny <Expression <Func <ServiceChannelLanguageAvailability, 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)); }
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()); }
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); }