示例#1
0
 private static ItSystemUsageSensitiveDataLevelDTO MapSensitiveDataLevelDTO(
     ItSystemUsageSensitiveDataLevel dataLevel)
 {
     return(new ItSystemUsageSensitiveDataLevelDTO
     {
         DataSensitivityLevel = dataLevel.SensitivityDataLevel
     });
 }
示例#2
0
        public void AddSensitiveData_Fails_With_Conflict_If_Sensitivity_Level_Already_Exists()
        {
            //Arrange
            var preAddedSensitiveDataLevel = new ItSystemUsageSensitiveDataLevel()
            {
                SensitivityDataLevel = SensitiveDataLevel.NONE
            };

            _sut.SensitiveDataLevels.Add(preAddedSensitiveDataLevel);

            //Act
            var result = _sut.AddSensitiveDataLevel(SensitiveDataLevel.NONE);

            //Assert
            AssertErrorResult(result, "Data sensitivity level already exists", OperationFailure.Conflict);
        }
示例#3
0
        public Result <ItSystemUsageSensitiveDataLevel, OperationError> AddSensitiveDataLevel(
            SensitiveDataLevel sensitiveDataLevel)
        {
            if (SensitiveDataLevelExists(sensitiveDataLevel))
            {
                return(new OperationError("Data sensitivity level already exists", OperationFailure.Conflict));
            }

            var newDataLevel = new ItSystemUsageSensitiveDataLevel()
            {
                ItSystemUsage        = this,
                SensitivityDataLevel = sensitiveDataLevel
            };

            SensitiveDataLevels.Add(newDataLevel);

            return(newDataLevel);
        }
示例#4
0
        public void RemoveSensitiveData_Returns_Ok(SensitiveDataLevel sensitiveDataLevel)
        {
            //Arrange
            var preAddedSensitiveDataLevel = new ItSystemUsageSensitiveDataLevel()
            {
                ItSystemUsage        = _sut,
                SensitivityDataLevel = sensitiveDataLevel
            };

            _sut.SensitiveDataLevels.Add(preAddedSensitiveDataLevel);

            //Act
            var result = _sut.RemoveSensitiveDataLevel(sensitiveDataLevel);

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

            Assert.Equal(preAddedSensitiveDataLevel, usageSensitiveDataLevel);
            Assert.Empty(_sut.SensitiveDataLevels);
        }
        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);
        }