Ejemplo n.º 1
0
        public void CanModify()
        {
            // Arrange
            var serviceId      = Guid.NewGuid();
            var channelId      = Guid.NewGuid();
            var organizationId = Guid.NewGuid();
            var relation       = new V7VmOpenApiServiceServiceChannelAstiInBase
            {
                ServiceId        = serviceId.ToString(),
                ServiceChannelId = channelId.ToString()
            };
            var unitOfWork = unitOfWorkMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

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

            ServiceServiceMock.Setup(s => s.GetServiceByIdSimple(serviceId, true))
            .Returns(new VmOpenApiServiceVersionBase()
            {
                PublishingStatus = PublishingStatus.Published.ToString()
            });

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

            //UserOrganizationServiceMock.Setup(s => s.GetAllUserOrganizations(unitOfWork)).Returns(new List<Guid>() { organizationId });

            translationManagerVModelMockSetup.Setup(s => s.Translate <IVmOpenApiServiceServiceChannelInVersionBase, ServiceServiceChannel>(relation, unitOfWork))
            .Returns(new ServiceServiceChannel());

            var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object,
                                                       Logger, serviceUtilities, DataUtils, ServiceServiceMock.Object, ChannelService, PublishingStatusCache, VersioningManager,
                                                       UserOrganizationChecker, CacheManager, UserOrganizationServiceMock.Object);

            // Act
            var result = service.SaveServicesAndChannels(new List <V7VmOpenApiServiceServiceChannelAstiInBase> {
                relation
            });

            // Assert
            result.Should().NotBeNull();
            var list = Assert.IsType <List <string> >(result);

            list.Count.Should().Be(1);
            list.FirstOrDefault().Should().EndWith("added or updated.");
            translationManagerVModelMockSetup.Verify(x => x.Translate <IVmOpenApiServiceServiceChannelInVersionBase, ServiceServiceChannel>(It.IsAny <VmOpenApiServiceServiceChannelInVersionBase>(), unitOfWork), Times.Once());
        }
Ejemplo n.º 2
0
        public void ChannelNotVisibleForUser()
        {
            // Arrange
            var serviceId      = Guid.NewGuid();
            var channelId      = Guid.NewGuid();
            var organizationId = Guid.NewGuid();
            var unitOfWork     = unitOfWorkMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

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

            ServiceServiceMock.Setup(s => s.GetServiceByIdSimple(serviceId, true))
            .Returns(new VmOpenApiServiceVersionBase()
            {
                PublishingStatus = PublishingStatus.Published.ToString()
            });

            ChannelServiceMock.Setup(s => s.GetServiceChannelByIdSimple(channelId, true))
            .Returns(new VmOpenApiServiceChannel()
            {
                Id = channelId, IsVisibleForAll = false, OrganizationId = organizationId
            });

            UserOrganizationServiceMock.Setup(s => s.GetAllUserOrganizations(unitOfWork)).Returns(new List <Guid>());

            var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object,
                                                       Logger, serviceUtilities, DataUtils, ServiceServiceMock.Object, ChannelService, PublishingStatusCache, VersioningManager,
                                                       UserOrganizationChecker, CacheManager, UserOrganizationServiceMock.Object);

            // Act
            var result = service.SaveServicesAndChannels(new List <V7VmOpenApiServiceServiceChannelAstiInBase> {
                new V7VmOpenApiServiceServiceChannelAstiInBase
                {
                    ServiceId        = serviceId.ToString(),
                    ServiceChannelId = channelId.ToString()
                }
            });

            // Assert
            result.Should().NotBeNull();
            var list = Assert.IsType <List <string> >(result);

            list.Count.Should().Be(1);
            list.FirstOrDefault().Should().EndWith("You do not have permission to update data!");
        }
Ejemplo n.º 3
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());
        }