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); }
public void ModelIsNull() { // Arrange var unitOfWork = unitOfWorkMockSetup.Object; var contextManager = new TestContextManager(unitOfWork, unitOfWork); 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 var result = service.SaveServiceConnectionsBySource(null, null, DefaultVersion); // Assert result.Should().BeNull(); }
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); }
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()); }