public void ASTIUpdate_RegularConnectionsNotDeleted() { // Arrange var serviceId = Guid.NewGuid(); var channelId = Guid.NewGuid(); var request = new V7VmOpenApiServiceAndChannelRelationAstiInBase { IsASTI = true, ServiceId = serviceId, ChannelRelations = new List <V7VmOpenApiServiceServiceChannelAstiInBase> { new V7VmOpenApiServiceServiceChannelAstiInBase { ServiceGuid = serviceId, ChannelGuid = channelId, } } }; var unitOfWork = unitOfWorkMockSetup.Object; var contextManager = new TestContextManager(unitOfWork, unitOfWork); var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService, VersioningManager, UserInfoService, UserOrganizationChecker); translationManagerVModelMockSetup.Setup(s => s.Translate <V7VmOpenApiServiceAndChannelRelationAstiInBase, Model.Models.Service>(request, unitOfWork)) .Returns(new Model.Models.Service() { Id = serviceId, ServiceServiceChannels = new List <ServiceServiceChannel> { new ServiceServiceChannel { IsASTIConnection = true, ServiceChannelId = channelId }, new ServiceServiceChannel { IsASTIConnection = false, ServiceChannelId = Guid.NewGuid() } } }); // repositories ConnectionRepoMock.Setup(c => c.All()).Returns(new List <ServiceServiceChannel>().AsQueryable()); DescriptionRepoMock.Setup(c => c.All()).Returns(new List <ServiceServiceChannelDescription>().AsQueryable()); var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object, Logger, serviceUtilities, DataUtils, ServiceService, ChannelService, PublishingStatusCache, VersioningManager, UserOrganizationChecker, CacheManager, UserOrganizationService); // Act var result = service.SaveServiceConnections(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()); ConnectionRepoMock.Verify(x => x.Remove(It.IsAny <ServiceServiceChannel>()), Times.Never()); DescriptionRepoMock.Verify(x => x.Remove(It.IsAny <ServiceServiceChannelDescription>()), Times.Never()); }
public void DeleteAllASTIConnections() { // Arrange var channelId = Guid.NewGuid(); var serviceId = Guid.NewGuid(); var serviceId2 = Guid.NewGuid(); var request = new V7VmOpenApiChannelServicesIn { ChannelId = channelId, DeleteAllServiceRelations = true }; // repositories var connectionList = new List <ServiceServiceChannel>() { new ServiceServiceChannel { ServiceId = serviceId, ServiceChannelId = channelId }, new ServiceServiceChannel { ServiceId = serviceId2, ServiceChannelId = channelId } }; ConnectionRepoMock.Setup(c => c.All()).Returns(connectionList.AsQueryable()); DescriptionRepoMock.Setup(c => c.All()).Returns(new List <ServiceServiceChannelDescription> { new ServiceServiceChannelDescription { ServiceId = serviceId, ServiceChannelId = channelId }, new ServiceServiceChannelDescription { ServiceId = serviceId2, ServiceChannelId = channelId }, }.AsQueryable()); var unitOfWork = unitOfWorkMockSetup.Object; var contextManager = new TestContextManager(unitOfWork, unitOfWork); var serviceUtilities = new ServiceUtilities(UserIdentificationMock.Object, LockingManager, contextManager, UserOrganizationService, VersioningManager, UserInfoService, UserOrganizationChecker); translationManagerVModelMockSetup.Setup(s => s.Translate <V7VmOpenApiChannelServicesIn, ServiceChannel>(request, unitOfWork)) .Returns(new ServiceChannel() { Id = serviceId, ServiceServiceChannels = new List <ServiceServiceChannel> { new ServiceServiceChannel { IsASTIConnection = true, ServiceChannelId = channelId, ServiceId = serviceId }, new ServiceServiceChannel { IsASTIConnection = true, ServiceChannelId = channelId, ServiceId = serviceId2 }, new ServiceServiceChannel { IsASTIConnection = false, ServiceChannelId = channelId, ServiceId = Guid.NewGuid() } // regular connection that should not be removed } }); var service = new ServiceAndChannelService(contextManager, translationManagerMockSetup.Object, translationManagerVModelMockSetup.Object, Logger, serviceUtilities, DataUtils, ServiceService, ChannelService, PublishingStatusCache, VersioningManager, UserOrganizationChecker, CacheManager, UserOrganizationService); // Act var result = service.SaveServiceChannelConnections(request, DefaultVersion); // Assert // We are not testing method GetServiceChannelById so we expect result to be null. result.Should().BeNull(); translationManagerVModelMockSetup.Verify(t => t.Translate <V7VmOpenApiChannelServicesIn, ServiceChannel>(It.IsAny <V7VmOpenApiChannelServicesIn>(), unitOfWork), Times.Once()); ConnectionRepoMock.Verify(x => x.Remove(It.IsAny <ServiceServiceChannel>()), Times.Exactly(2)); DescriptionRepoMock.Verify(x => x.Remove(It.IsAny <ServiceServiceChannelDescription>()), Times.Exactly(2)); }