Ejemplo n.º 1
0
        public void GetUsageRelation_Returns(bool some)
        {
            //Arrange
            var id             = A <int>();
            var systemRelation = new SystemRelation(new ItSystemUsage())
            {
                Id = some ? id : A <int>()
            };
            var ignoredRelation = new SystemRelation(new ItSystemUsage())
            {
                Id = A <int>()
            };

            _sut.UsageRelations.Add(ignoredRelation);
            _sut.UsageRelations.Add(systemRelation);

            //Act
            var relation = _sut.GetUsageRelation(id);

            //Assert
            Assert.Equal(some, relation.HasValue);
            if (some)
            {
                Assert.Same(systemRelation, relation.Value);
            }
        }
        public void ExecuteMigration_Returns_Ok_With_No_RelationInterfaces_Reset_When_Own_Relation()
        {
            //Arrange
            var fromSystemUsage = CreateSystemUsage();
            var migrateToSystem = CreateSystem();
            var toSystemUsage   = CreateSystemUsage();

            ExpectAllowedGetMigration(fromSystemUsage.Id, fromSystemUsage, migrateToSystem);
            ExpectAllowModifyReturns(fromSystemUsage, true);
            var relation = new SystemRelation(fromSystemUsage)
            {
                ToSystemUsageId = toSystemUsage.Id,
            };
            var usageRelations = new List <SystemRelation>
            {
                relation
            };
            var usedByRelations = new List <SystemRelation>();

            fromSystemUsage = AddRelationsToSystemUsage(fromSystemUsage, usageRelations, usedByRelations);
            var transaction = ExpectBeginTransaction();

            //Act
            var result = _sut.ExecuteSystemUsageMigration(fromSystemUsage.Id, migrateToSystem.Id);

            //Assert
            Assert.True(result.Ok);
            var migration = result.Value;

            VerifyModifyRelationCalled(relation, Times.Never());
            Assert.Equal(migration.UsageRelations.First().Id, usageRelations.First().Id);
            VerifySystemMigrationCommitted(fromSystemUsage, migrateToSystem, transaction);
        }
Ejemplo n.º 3
0
        private void ModifyRelation_GivenAnyUserWithItSystemWriteAccess_AllowsModifications(bool allowModifications)
        {
            // Arrange
            var fromSystemUsage = new ItSystemUsage {
                Id = FromSystemUsageId
            };
            var toSystemUsage = new ItSystemUsage {
                Id = ToSystemUsageId
            };
            var systemRelation = new SystemRelation(fromSystemUsage)
            {
                Id = FromSystemRelationId, ToSystemUsage = toSystemUsage
            };

            fromSystemUsage.UsageRelations = new List <SystemRelation> {
                systemRelation
            };
            _mockSystemRelationRepository.Setup(r => r.GetByKey(FromSystemRelationId)).Returns(systemRelation);
            _mockSystemUsageRepository.Setup(r => r.GetByKey(FromSystemUsageId)).Returns(fromSystemUsage);
            _mockSystemUsageRepository.Setup(r => r.GetByKey(ToSystemUsageId)).Returns(toSystemUsage);
            _mockAuthorizationContext.Setup(c => c.AllowModify(fromSystemUsage)).Returns(allowModifications);

            // Act
            var result = _sut.ModifyRelation(FromSystemUsageId, FromSystemRelationId, ToSystemUsageId, null, null, null, null, null);

            // Assert
            Assert.True(allowModifications ? result.Ok : result.Error.FailureType == OperationFailure.Forbidden);
        }
        private void ExpectSystemUsageServiceToRemoveRelationInterface(SystemRelation relation, bool shouldSucceed)
        {
            var newRelation = new SystemRelation(relation.FromSystemUsage)
            {
                Id                   = relation.Id,
                Description          = relation.Description,
                AssociatedContract   = relation.AssociatedContract,
                AssociatedContractId = relation.AssociatedContractId,
                Reference            = relation.Reference,
                ToSystemUsage        = relation.ToSystemUsage,
                ToSystemUsageId      = relation.ToSystemUsageId,
                UsageFrequency       = relation.UsageFrequency,
                UsageFrequencyId     = relation.UsageFrequencyId,
                RelationInterfaceId  = null,
                RelationInterface    = null
            };

            _itSystemUsageService
            .Setup(x => x.ModifyRelation(
                       relation.FromSystemUsageId,
                       relation.Id,
                       relation.ToSystemUsageId,
                       relation.Description,
                       relation.Reference,
                       null,
                       relation.AssociatedContractId,
                       relation.UsageFrequencyId))
            .Returns(
                shouldSucceed
                    ? Result <SystemRelation, OperationError> .Success(newRelation)
                    : Result <SystemRelation, OperationError> .Failure(new OperationError(OperationFailure.UnknownError)));
        }
        public void ExecuteMigration_Returns_UnknownError_If_Deletion_Of_Relation_Interface_Fails()
        {
            //Arrange
            var fromSystemUsage   = CreateSystemUsage();
            var migrateToSystem   = CreateSystem();
            var toSystemUsage     = CreateSystemUsage();
            var relationInterface = CreateInterface();
            var relation          = new SystemRelation(fromSystemUsage)
            {
                ToSystemUsageId     = toSystemUsage.Id,
                RelationInterfaceId = relationInterface.Id,
                RelationInterface   = relationInterface
            };

            var usageRelations  = new List <SystemRelation>();
            var usedByRelations = new List <SystemRelation>
            {
                relation
            };

            fromSystemUsage = AddRelationsToSystemUsage(fromSystemUsage, usageRelations, usedByRelations);
            ExpectSystemUsageServiceToRemoveRelationInterface(usedByRelations.First(), false);
            ExpectAllowedGetMigration(fromSystemUsage.Id, fromSystemUsage, migrateToSystem);
            ExpectAllowModifyReturns(fromSystemUsage, true);
            var transaction = ExpectBeginTransaction();

            //Act
            var result = _sut.ExecuteSystemUsageMigration(fromSystemUsage.Id, migrateToSystem.Id);

            //Assert
            Assert.False(result.Ok);
            VerifyTransactionRollback(transaction);
        }
        public void GetSystemUsageMigration_Returns_Ok_With_No_Affected_Relation_From_UsageRelations()
        {
            //Arrange
            var fromSystemUsage = CreateSystemUsage();
            var migrateToSystem = CreateSystem();
            var toSystemUsage   = CreateSystemUsage();
            var relation        = new SystemRelation(fromSystemUsage)
            {
                ToSystemUsageId = toSystemUsage.Id
            };

            ExpectAllowedGetMigration(fromSystemUsage.Id, fromSystemUsage, migrateToSystem);
            var usageRelations = new List <SystemRelation>
            {
                relation
            };
            var usedByRelations = new List <SystemRelation>();

            fromSystemUsage = AddRelationsToSystemUsage(fromSystemUsage, usageRelations, usedByRelations);

            //Act
            var result = _sut.GetSystemUsageMigration(fromSystemUsage.Id, migrateToSystem.Id);

            //Assert
            Assert.True(result.Ok);
            var migration = result.Value;

            Assert.Empty(migration.AffectedSystemRelations);
        }
Ejemplo n.º 7
0
        private SystemRelation CreateRelation()
        {
            var systemRelation = new SystemRelation(new ItSystemUsage());

            systemRelation.SetRelationTo(new ItSystemUsage {
                Id = A <int>()
            });
            return(systemRelation);
        }
 private static RelationMigrationDTO Map(SystemRelation input)
 {
     return(new RelationMigrationDTO
     {
         ToSystemUsage = input.ToSystemUsage.MapToNamedEntityWithEnabledStatusDTO(),
         FromSystemUsage = input.FromSystemUsage.MapToNamedEntityWithEnabledStatusDTO(),
         Description = input.Description,
         Contract = input.AssociatedContract?.MapToNamedEntityDTO(),
         FrequencyType = input.UsageFrequency?.MapToNamedEntityDTO(),
         Interface = input.RelationInterface?.MapToNamedEntityDTO()
     });
 }
 private void VerifyModifyRelationCalled(SystemRelation relation, Times numberOfTimesCalled)
 {
     _itSystemUsageService.Verify(x => x.ModifyRelation(
                                      relation.FromSystemUsageId,
                                      relation.Id,
                                      relation.ToSystemUsageId,
                                      relation.Description,
                                      relation.Reference,
                                      null,
                                      relation.AssociatedContractId,
                                      relation.UsageFrequencyId), numberOfTimesCalled);
 }
Ejemplo n.º 10
0
        private SystemRelation CreateRelation(ItSystemUsage deletedSystemUsage)
        {
            var fromSystemUsage = new ItSystemUsage {
                Id = A <int>()
            };
            var systemRelation = new SystemRelation(fromSystemUsage)
            {
                FromSystemUsageId = fromSystemUsage.Id,
                ToSystemUsage     = deletedSystemUsage,
                Id = A <int>()
            };

            fromSystemUsage.UsageRelations.Add(systemRelation);
            return(systemRelation);
        }
Ejemplo n.º 11
0
 private static SystemRelationDTO MapRelation(SystemRelation relation)
 {
     return(new SystemRelationDTO
     {
         Id = relation.Id,
         Uuid = relation.Uuid,
         FromUsage = relation.FromSystemUsage.MapToNamedEntityWithEnabledStatusDTO(),
         ToUsage = relation.ToSystemUsage.MapToNamedEntityWithEnabledStatusDTO(),
         Description = relation.Description,
         Reference = relation.Reference,
         Contract = relation.AssociatedContract?.MapToNamedEntityDTO(),
         FrequencyType = relation.UsageFrequency?.MapToNamedEntityDTO(),
         Interface = relation.RelationInterface?.MapToNamedEntityDTO()
     });
 }
Ejemplo n.º 12
0
        private SystemRelation CreateRelation(ItInterface affectedInterface)
        {
            var fromSystemUsage = new ItSystemUsage {
                Id = A <int>()
            };
            var systemRelation = new SystemRelation(fromSystemUsage)
            {
                RelationInterface = affectedInterface,
                ToSystemUsage     = new ItSystemUsage {
                    Id = A <int>()
                }
            };

            fromSystemUsage.UsageRelations.Add(systemRelation);
            return(systemRelation);
        }
Ejemplo n.º 13
0
        private SystemRelation CreateRelation(ItContract deletedContract)
        {
            var fromSystemUsage = new ItSystemUsage {
                Id = A <int>()
            };
            var systemRelation = new SystemRelation(fromSystemUsage)
            {
                AssociatedContract = deletedContract,
                ToSystemUsage      = new ItSystemUsage {
                    Id = A <int>()
                }
            };

            fromSystemUsage.UsageRelations.Add(systemRelation);
            return(systemRelation);
        }
        public void ExecuteMigration_Returns_Ok_And_Resets_RelationInterface_From_UsedByRelation_With_Interface()
        {
            //Arrange
            var fromSystemUsage       = CreateSystemUsage();
            var migrateToSystem       = CreateSystem();
            var toSystemUsage         = CreateSystemUsage();
            var relationInterface     = CreateInterface();
            var relationFrequenceType = new RelationFrequencyType()
            {
                Id   = A <int>(),
                Name = A <string>()
            };
            var relation = new SystemRelation(fromSystemUsage)
            {
                ToSystemUsageId     = toSystemUsage.Id,
                RelationInterfaceId = relationInterface.Id,
                RelationInterface   = relationInterface,
                UsageFrequencyId    = relationFrequenceType.Id,
                UsageFrequency      = relationFrequenceType,
                Description         = A <string>()
            };

            ExpectAllowedGetMigration(fromSystemUsage.Id, fromSystemUsage, migrateToSystem);
            ExpectAllowModifyReturns(fromSystemUsage, true);
            var usageRelations  = new List <SystemRelation>();
            var usedByRelations = new List <SystemRelation>
            {
                relation
            };

            fromSystemUsage = AddRelationsToSystemUsage(fromSystemUsage, usageRelations, usedByRelations);
            ExpectSystemUsageServiceToRemoveRelationInterface(usedByRelations.First(), true);
            var transaction = ExpectBeginTransaction();

            //Act
            var result = _sut.ExecuteSystemUsageMigration(fromSystemUsage.Id, migrateToSystem.Id);

            //Assert
            Assert.True(result.Ok);
            var migration = result.Value;

            VerifyModifyRelationCalled(relation, Times.Once());
            Assert.Equal(relation.Id, migration.UsedByRelations.First().Id);
            VerifySystemMigrationCommitted(fromSystemUsage, migrateToSystem, transaction);
        }
        public void GetSystemUsageMigration_Returns_Ok_With_Affected_Relation_From_UsedByRelation_With_Interface()
        {
            //Arrange
            var fromSystemUsage       = CreateSystemUsage();
            var migrateToSystem       = CreateSystem();
            var toSystemUsage         = CreateSystemUsage();
            var relationInterface     = CreateInterface();
            var relationFrequenceType = new RelationFrequencyType()
            {
                Id   = A <int>(),
                Name = A <string>()
            };
            var relation = new SystemRelation(fromSystemUsage)
            {
                ToSystemUsageId     = toSystemUsage.Id,
                RelationInterfaceId = relationInterface.Id,
                RelationInterface   = relationInterface,
                UsageFrequencyId    = relationFrequenceType.Id,
                UsageFrequency      = relationFrequenceType,
                Description         = A <string>()
            };

            ExpectAllowedGetMigration(fromSystemUsage.Id, fromSystemUsage, migrateToSystem);
            var usageRelations  = new List <SystemRelation>();
            var usedByRelations = new List <SystemRelation>
            {
                relation
            };

            fromSystemUsage = AddRelationsToSystemUsage(fromSystemUsage, usageRelations, usedByRelations);

            //Act
            var result = _sut.GetSystemUsageMigration(fromSystemUsage.Id, migrateToSystem.Id);

            //Assert
            Assert.True(result.Ok);
            var migration = result.Value;

            Assert.Equal(1, migration.AffectedSystemRelations.Count);
            Assert.Equal(relation.Id, migration.AffectedSystemRelations.First().Id);
            Assert.Equal(relationInterface.Id, migration.AffectedSystemRelations.First().RelationInterfaceId);
            Assert.Equal(relation.Description, migration.AffectedSystemRelations.First().Description);
            Assert.Equal(relationFrequenceType.Id, migration.AffectedSystemRelations.First().UsageFrequencyId);
            Assert.Equal(relationFrequenceType.Name, migration.AffectedSystemRelations.First().UsageFrequency.Name);
        }
Ejemplo n.º 16
0
        public void RemoveUsageRelation_Returns_NotFound()
        {
            //Arrange
            var id = A <int>();
            var ignoredRelation = new SystemRelation(new ItSystemUsage())
            {
                Id = A <int>()
            };

            _sut.UsageRelations.Add(ignoredRelation);

            //Act
            var result = _sut.RemoveUsageRelation(id);

            //Assert
            Assert.False(result.Ok);
            Assert.Equal(OperationFailure.NotFound, result.Error);
        }
Ejemplo n.º 17
0
        private void SetupSystemRelation(int systemRelationId, Mock <ItSystemUsage> sourceSystemUsage, Mock <ItSystemUsage> targetSystemUsage)
        {
            var usageSystemRelation = new SystemRelation(sourceSystemUsage.Object)
            {
                Id                = systemRelationId,
                Description       = "MyDescription",
                Reference         = "https://dummy.dk",
                RelationInterface = new ItInterface {
                    Id = Interface1Id
                },
                AssociatedContract = new ItContract {
                    Id = Contract1Id
                },
                UsageFrequency = new RelationFrequencyType {
                    Id = FrequencyType1Id
                }
            };

            usageSystemRelation.SetRelationTo(targetSystemUsage.Object);
            sourceSystemUsage.SetupGet(u => u.UsageRelations).Returns(new List <SystemRelation> {
                usageSystemRelation
            });
            var itInterfaceExhibits = new List <ItInterfaceExhibit>
            {
                new ItInterfaceExhibit {
                    ItInterface = new ItInterface {
                        Id = Interface1Id
                    }
                },
                new ItInterfaceExhibit {
                    ItInterface = new ItInterface {
                        Id = Interface2Id
                    }
                }
            };
            var mockTargetItSystem = new Mock <ItSystem>();

            mockTargetItSystem.SetupGet(s => s.ItInterfaceExhibits).Returns(itInterfaceExhibits);
            targetSystemUsage.SetupGet(u => u.ItSystem).Returns(mockTargetItSystem.Object);
            _mockSystemRelationRepository.Setup(r => r.GetByKey(usageSystemRelation.Id)).Returns(usageSystemRelation);
        }
Ejemplo n.º 18
0
        public void RemoveUsageRelation_Returns_Ok()
        {
            //Arrange
            var id = A <int>();
            var removedRelation = new SystemRelation(new ItSystemUsage())
            {
                Id = id
            };
            var ignoredRelation = new SystemRelation(new ItSystemUsage())
            {
                Id = A <int>()
            };

            _sut.UsageRelations.Add(ignoredRelation);
            _sut.UsageRelations.Add(removedRelation);

            //Act
            var result = _sut.RemoveUsageRelation(id);

            //Assert
            Assert.True(result.Ok);
            Assert.Same(removedRelation, result.Value);
        }
        public void Apply_Generates_Correct_Read_Model()
        {
            //Arrange
            var outgoingRelationItSystem = new ItSystem
            {
                Id = A<int>(),
                Name = A<string>()
            };
            var outgoingRelationInterface = new ItInterface
            {
                Id = A<int>(),
                Name = A<string>()
            };
            var outgoingRelationItSystemUsage = new ItSystemUsage
            {
                Id = A<int>(),
                OrganizationId = A<int>(),
                ItSystem = outgoingRelationItSystem
            };
            var outgoingRelation = new SystemRelation(outgoingRelationItSystemUsage)
            {
                Id = A<int>(),
                RelationInterface = outgoingRelationInterface,
                ToSystemUsage = outgoingRelationItSystemUsage
            };

            var incomingRelationItSystem = new ItSystem
            {
                Id = A<int>(),
                Name = A<string>()
            };
            var incomingRelationItSystemUsage = new ItSystemUsage
            {
                Id = A<int>(),
                OrganizationId = A<int>(),
                ItSystem = incomingRelationItSystem
            };
            var incomingRelation = new SystemRelation(incomingRelationItSystemUsage)
            {
                Id = A<int>()
            };

            var supplier = new Organization
            {
                Id = A<int>(),
                Name = A<string>()
            };
            var user = new User
            {
                Id = A<int>(),
                Name = A<string>(),
                LastName = A<string>(),
                Email = $"{A<string>()}@{A<string>()}.dk"
            };
            var right = new ItSystemRight
            {
                Id = A<int>(),
                User = user,
                UserId = user.Id,
                RoleId = A<int>()
            };
            var contract = new ItContract
            {
                Id = A<int>(),
                Name = A<string>(),
                Supplier = supplier
            };
            var project = new ItProject
            {
                Id = A<int>(),
                Name = A<string>()
            };
            var dataProcessingRegistration = new DataProcessingRegistration()
            {
                Id = A<int>(),
                Name = A<string>(),
                IsAgreementConcluded = A<YesNoIrrelevantOption>()
            };
            var parentSystem = new ItSystem
            {
                Id = A<int>(),
                Name = A<string>(),
                Disabled = A<bool>()
            };
            var system = new ItSystem
            {
                Id = A<int>(),
                OrganizationId = A<int>(),
                Name = A<string>(),
                Disabled = A<bool>(),
                Parent = parentSystem,
                Uuid = A<Guid>(),
                BelongsTo = new Organization
                {
                    Id = A<int>(),
                    Name = A<string>()
                },
                BusinessType = new BusinessType
                {
                    Id = A<int>(),
                    Name = A<string>()
                },
                TaskRefs = new List<TaskRef>
                {
                    new TaskRef
                    {
                        Id = A<int>(),
                        TaskKey = A<string>(),
                        Description = A<string>()
                    }
                }
            };
            var systemUsage = new ItSystemUsage
            {
                Id = A<int>(),
                OrganizationId = A<int>(),
                ItSystem = system,
                Active = A<bool>(),
                ExpirationDate = DateTime.Now.AddDays(-1),
                Version = A<string>(),
                LocalCallName = A<string>(),
                LocalSystemId = A<string>(),
                Rights = new List<ItSystemRight>
                {
                    right
                },
                Reference = new ExternalReference
                {
                    Id = A<int>(),
                    Title = A<string>(),
                    ExternalReferenceId = A<string>(),
                    URL = A<string>()
                },
                ObjectOwnerId = user.Id,
                ObjectOwner = user,
                LastChangedByUserId = user.Id,
                LastChangedByUser = user,
                LastChanged = A<DateTime>(),
                Concluded = A<DateTime>(),
                ItProjects = new List<ItProject>
                {
                    project
                },
                ArchiveDuty = A<ArchiveDutyTypes>(),
                Registertype = A<bool>(),
                riskAssessment = DataOptions.YES,
                RiskSupervisionDocumentationUrlName = A<string>(),
                RiskSupervisionDocumentationUrl = A<string>(),
                LinkToDirectoryUrlName = A<string>(),
                LinkToDirectoryUrl = A<string>(),
                AssociatedDataProcessingRegistrations = new List<DataProcessingRegistration>
                {
                    dataProcessingRegistration
                },
                GeneralPurpose = A<string>(),
                HostedAt = A<HostedAt>(),
                UsageRelations = new List<SystemRelation>
                {
                    outgoingRelation
                },
                UsedByRelations = new List<SystemRelation>
                {
                    incomingRelation
                }
            };

            // Add ResponsibleOrganizationUnit
            var organizationUnit = new OrganizationUnit
            {
                Id = A<int>(),
                Name = A<string>()
            };
            var systemUsageOrgUnitUsage = new ItSystemUsageOrgUnitUsage
            {
                OrganizationUnit = organizationUnit,
                OrganizationUnitId = organizationUnit.Id,
                ItSystemUsage = systemUsage,
                ItSystemUsageId = systemUsage.Id
            };
            systemUsage.ResponsibleUsage = systemUsageOrgUnitUsage;

            _businessTypeService.Setup(x => x.GetOption(system.OrganizationId, system.BusinessType.Id)).Returns(Maybe<(BusinessType, bool)>.Some((system.BusinessType, true)));

            // Add MainContract
            var mainContract = new ItContractItSystemUsage
            {
                ItContractId = contract.Id,
                ItContract = contract,
                ItSystemUsageId = systemUsage.Id,
                ItSystemUsage = systemUsage
            };
            systemUsage.MainContract = mainContract;

            // Add SensitiveDataLevel
            var sensitiveDataLevel = new ItSystemUsageSensitiveDataLevel
            {
                Id = A<int>(),
                ItSystemUsage = systemUsage,
                SensitivityDataLevel = A<SensitiveDataLevel>()
            };
            systemUsage.SensitiveDataLevels = new List<ItSystemUsageSensitiveDataLevel> { sensitiveDataLevel };

            // Add ArchivePeriod
            var archivePeriods = new List<ArchivePeriod>
            {
                new ArchivePeriod
                {
                    Id = A<int>(),
                    ItSystemUsage = systemUsage,
                    StartDate = DateTime.Now.AddDays(-1),
                    EndDate = DateTime.Now.AddDays(1)
                }
            };
            systemUsage.ArchivePeriods = archivePeriods;

            var readModel = new ItSystemUsageOverviewReadModel();

            //Act
            _sut.Apply(systemUsage, readModel);

            //Assert
            //System usage
            Assert.Equal(systemUsage.Id, readModel.SourceEntityId);
            Assert.Equal(systemUsage.OrganizationId, readModel.OrganizationId);
            Assert.Equal(systemUsage.IsActive, readModel.IsActive);
            Assert.Equal(systemUsage.Version, readModel.Version);
            Assert.Equal(systemUsage.LocalCallName, readModel.LocalCallName);
            Assert.Equal(systemUsage.LocalSystemId, readModel.LocalSystemId);
            Assert.Equal(user.Id, readModel.ObjectOwnerId);
            Assert.Equal(user.GetFullName(), readModel.ObjectOwnerName);
            Assert.Equal(user.Id, readModel.LastChangedById);
            Assert.Equal(user.GetFullName(), readModel.LastChangedByName);
            Assert.Equal(systemUsage.LastChanged, readModel.LastChangedAt);
            Assert.Equal(systemUsage.Concluded, readModel.Concluded);
            Assert.Equal(systemUsage.ArchiveDuty, readModel.ArchiveDuty);
            Assert.Equal(systemUsage.Registertype, readModel.IsHoldingDocument);
            Assert.Equal(systemUsage.RiskSupervisionDocumentationUrlName, readModel.RiskSupervisionDocumentationName);
            Assert.Equal(systemUsage.RiskSupervisionDocumentationUrl, readModel.RiskSupervisionDocumentationUrl);
            Assert.Equal(systemUsage.LinkToDirectoryUrlName, readModel.LinkToDirectoryName);
            Assert.Equal(systemUsage.LinkToDirectoryUrl, readModel.LinkToDirectoryUrl);
            Assert.Equal(systemUsage.GeneralPurpose, readModel.GeneralPurpose);
            Assert.Equal(systemUsage.HostedAt, readModel.HostedAt);

            // Sensitive data levels
            var rmSensitiveDataLevel = Assert.Single(readModel.SensitiveDataLevels);
            Assert.Equal(sensitiveDataLevel.SensitivityDataLevel, rmSensitiveDataLevel.SensitivityDataLevel);
            Assert.Equal(sensitiveDataLevel.SensitivityDataLevel.GetReadableName(), readModel.SensitiveDataLevelsAsCsv);

            //System
            Assert.Equal(system.Name, readModel.SystemName);
            Assert.Equal(system.Disabled, readModel.ItSystemDisabled);
            Assert.Equal(system.Uuid.ToString("D"), readModel.ItSystemUuid);
            Assert.Equal(system.BelongsTo.Id, readModel.ItSystemRightsHolderId);
            Assert.Equal(system.BelongsTo.Name, readModel.ItSystemRightsHolderName);
            Assert.Equal(system.BusinessType.Id, readModel.ItSystemBusinessTypeId);
            Assert.Equal(system.BusinessType.Name, readModel.ItSystemBusinessTypeName);

            //Parent System
            Assert.Equal(parentSystem.Name, readModel.ParentItSystemName);
            Assert.Equal(parentSystem.Id, readModel.ParentItSystemId);
            Assert.Equal(parentSystem.Disabled, readModel.ParentItSystemDisabled);

            //Assigned Roles
            var roleAssignment = Assert.Single(readModel.RoleAssignments);
            Assert.Equal(user.Id, roleAssignment.UserId);
            Assert.Equal(user.GetFullName(), roleAssignment.UserFullName);
            Assert.Equal(right.RoleId, roleAssignment.RoleId);
            Assert.Equal(user.Email, roleAssignment.Email);

            //Responsible Organization Unit
            Assert.Equal(organizationUnit.Id, readModel.ResponsibleOrganizationUnitId);
            Assert.Equal(organizationUnit.Name, readModel.ResponsibleOrganizationUnitName);

            //KLE
            Assert.Equal(system.TaskRefs.First().TaskKey, readModel.ItSystemKLEIdsAsCsv);
            Assert.Equal(system.TaskRefs.First().Description, readModel.ItSystemKLENamesAsCsv);
            var taskRef = Assert.Single(readModel.ItSystemTaskRefs);
            Assert.Equal(system.TaskRefs.First().TaskKey, taskRef.KLEId);
            Assert.Equal(system.TaskRefs.First().Description, taskRef.KLEName);

            //Reference
            Assert.Equal(systemUsage.Reference.Title, readModel.LocalReferenceTitle);
            Assert.Equal(systemUsage.Reference.URL, readModel.LocalReferenceUrl);
            Assert.Equal(systemUsage.Reference.ExternalReferenceId, readModel.LocalReferenceDocumentId);

            //Main Contract
            Assert.Equal(contract.Id, readModel.MainContractId);
            Assert.Equal(contract.Supplier.Id, readModel.MainContractSupplierId);
            Assert.Equal(contract.Supplier.Name, readModel.MainContractSupplierName);
            Assert.Equal(contract.IsActive, readModel.MainContractIsActive.GetValueOrDefault(false));
            Assert.True(readModel.HasMainContract);

            //Projects
            Assert.Equal(project.Name, readModel.ItProjectNamesAsCsv);
            var rmProject = Assert.Single(readModel.ItProjects);
            Assert.Equal(project.Id, rmProject.ItProjectId);
            Assert.Equal(project.Name, rmProject.ItProjectName);

            //ArchivePeriods
            var rmArchivePeriod = Assert.Single(readModel.ArchivePeriods);
            Assert.Equal(archivePeriods.First().StartDate, rmArchivePeriod.StartDate);
            Assert.Equal(archivePeriods.First().EndDate, rmArchivePeriod.EndDate);
            Assert.Equal(archivePeriods.First().EndDate, readModel.ActiveArchivePeriodEndDate);

            //DataProcessingRegistrations
            Assert.Equal(dataProcessingRegistration.Name, readModel.DataProcessingRegistrationNamesAsCsv);
            Assert.Equal(dataProcessingRegistration.IsAgreementConcluded.GetValueOrDefault(YesNoIrrelevantOption.UNDECIDED).GetReadableName(), readModel.DataProcessingRegistrationsConcludedAsCsv);
            var rmDataProcessingRegistration = Assert.Single(readModel.DataProcessingRegistrations);
            Assert.Equal(dataProcessingRegistration.Name, rmDataProcessingRegistration.DataProcessingRegistrationName);
            Assert.Equal(dataProcessingRegistration.IsAgreementConcluded, rmDataProcessingRegistration.IsAgreementConcluded);

            //Outgoing Relation interfaces
            Assert.Equal(outgoingRelationInterface.Name, readModel.DependsOnInterfacesNamesAsCsv);
            var rmDependsOnInterface = Assert.Single(readModel.DependsOnInterfaces);
            Assert.Equal(outgoingRelationInterface.Id, rmDependsOnInterface.InterfaceId);
            Assert.Equal(outgoingRelationInterface.Name, rmDependsOnInterface.InterfaceName);

            //Outgoing Relation systems
            Assert.Equal(outgoingRelationItSystem.Name, readModel.OutgoingRelatedItSystemUsagesNamesAsCsv);
            var rmDependsOnSystem = Assert.Single(readModel.OutgoingRelatedItSystemUsages);
            Assert.Equal(outgoingRelationItSystemUsage.Id, rmDependsOnSystem.ItSystemUsageId);
            Assert.Equal(outgoingRelationItSystem.Name, rmDependsOnSystem.ItSystemUsageName);

            //Incoming Relations
            Assert.Equal(incomingRelationItSystem.Name, readModel.IncomingRelatedItSystemUsagesNamesAsCsv);
            var rmIncomingRelatedSystemUsage = Assert.Single(readModel.IncomingRelatedItSystemUsages);
            Assert.Equal(incomingRelationItSystemUsage.Id, rmIncomingRelatedSystemUsage.ItSystemUsageId);
            Assert.Equal(incomingRelationItSystem.Name, rmIncomingRelatedSystemUsage.ItSystemUsageName);
        }