コード例 #1
0
        public void GetComponentsOfType_Twice_GetsSameComponents()
        {
            // Arrange
            var workspace = new Workspace("MyWorkspace", null)
            {
                Id = "454923f0-b1b0-48b3-9015-251dad9b4cea"
            };
            var componentType = "MyType";

            _readerMock.Setup(r => r.GetWorkspaceById(workspace.Id))
            .Returns(Task.FromResult(workspace));

            var components = new List <Component>
            {
                new Component("C1", workspace.Id, null)
                {
                    Type = componentType
                }
            };

            _readerMock.Setup(r => r.GetAllComponents(workspace.Id))
            .Returns(Task.FromResult <IEnumerable <Component> >(components));

            var session = new ArdoqSession(workspace.Id, _readerMock.Object, _writerMock.Object);

            // Act
            var comps1 = session.GetComponentsOfType(componentType);
            var comps2 = session.GetComponentsOfType(componentType);

            // Assert
            Assert.Same(comps1.First(), comps2.First());
            _readerMock.Verify(r => r.GetAllComponents(workspace.Id), Times.Once);
        }
コード例 #2
0
        public void DeleteComponent_HappyDays_SendsDeletionToArdoqAndUncaches()
        {
            // Arrange
            var workspace = new Workspace("MyWorkspace", null)
            {
                Id = "454923f0-b1b0-48b3-9015-251dad9b4cea"
            };
            var componentType = "MyType";

            _readerMock.Setup(r => r.GetWorkspaceById(workspace.Id))
            .Returns(Task.FromResult(workspace));

            var compId = "3a1949ef-8b44-4af3-939f-a49d24376248";

            var component = new Component("C1", workspace.Id, null)
            {
                Id = compId, Type = componentType
            };

            _readerMock.Setup(r => r.GetAllComponents(workspace.Id))
            .Returns(Task.FromResult <IEnumerable <Component> >(new List <Component> {
                component
            }));

            var session = new ArdoqSession(workspace.Id, _readerMock.Object, _writerMock.Object);

            // Act
            session.DeleteComponent(component);

            // Assert
            _writerMock.Verify(w => w.DeleteComponent(compId), Times.Once);
            Assert.True(!session.GetComponentsOfType(componentType).Any());
        }
コード例 #3
0
        public void GetReference_DoesNotExist_ReturnsNull()
        {
            // Arrange
            var sourceComponentType = "ST";
            var sourceKey           = "source-1";
            var sourceId            = "source-id-1";
            var targetComponentType = "TT";
            var targetKey           = "target-2";
            var targetId            = "target-id-2";

            var relationType = "my-rel";

            var componentModel = "my-comp-model";
            var workspace      = new Workspace("MyWorkspace", null)
            {
                Id             = "454923f0-b1b0-48b3-9015-251dad9b4cea",
                ComponentModel = componentModel
            };

            var internalmodel = new global::Ardoq.Models.Model(
                "model-id",
                "MyModel",
                null,
                null,
                new Dictionary <string, int> {
                ["my-rel"] = 1
            });
            IArdoqModel model = new ArdoqModel(internalmodel);

            _readerMock.Setup(r => r.GetWorkspaceById(workspace.Id))
            .Returns(Task.FromResult(workspace));
            _readerMock.Setup(r => r.GetModelById(componentModel))
            .Returns(Task.FromResult(model));

            var sourceComponent = new Component(sourceKey, workspace.Id, null)
            {
                Type = sourceComponentType, Id = sourceId
            };
            var targetComponent = new Component(targetKey, workspace.Id, null)
            {
                Type = targetComponentType, Id = targetId
            };

            _readerMock.Setup(r => r.GetAllComponents(workspace.Id))
            .Returns(Task.FromResult <IEnumerable <Component> >(new List <Component> {
                sourceComponent, targetComponent
            }));

            _readerMock.Setup(r => r.GetReferencesById(workspace.Id))
            .Returns(Task.FromResult(new List <Reference>()));
            var session = new ArdoqSession(workspace.Id, _readerMock.Object, _writerMock.Object);

            // Act
            var relation = session.GetReference(relationType, sourceComponentType, sourceKey, targetComponentType, targetKey);

            // Assert
            Assert.Null(relation);
        }
コード例 #4
0
        public void AddReference_HappyDays_CreatesReferenceInArdoq()
        {
            // Arrange
            var sourceComponentType = "ST";
            var sourceKey           = "source-1";
            var sourceId            = "source-id-1";
            var targetComponentType = "TT";
            var targetKey           = "target-2";
            var targetId            = "target-id-2";
            var refType             = "my-rel";

            var componentModel = "my-comp-model";
            var workspace      = new Workspace("MyWorkspace", null)
            {
                Id             = "454923f0-b1b0-48b3-9015-251dad9b4cea",
                ComponentModel = componentModel
            };

            var internalmodel = new global::Ardoq.Models.Model(
                "model-id",
                "MyModel",
                null,
                null,
                new Dictionary <string, int> {
                [refType] = 1
            });
            IArdoqModel model = new ArdoqModel(internalmodel);

            _readerMock.Setup(r => r.GetWorkspaceById(workspace.Id))
            .Returns(Task.FromResult(workspace));
            _readerMock.Setup(r => r.GetModelById(componentModel))
            .Returns(Task.FromResult(model));

            _readerMock.Setup(r => r.GetReferencesById(workspace.Id))
            .Returns(Task.FromResult(new List <Reference>()));

            var sourceComponent = new Component(sourceKey, workspace.Id, null)
            {
                Type = sourceComponentType, Id = sourceId
            };
            var targetComponent = new Component(targetKey, workspace.Id, null)
            {
                Type = targetComponentType, Id = targetId
            };

            _readerMock.Setup(r => r.GetAllComponents(workspace.Id))
            .Returns(Task.FromResult <IEnumerable <Component> >(new List <Component> {
                sourceComponent, targetComponent
            }));

            var session = new ArdoqSession(workspace.Id, _readerMock.Object, _writerMock.Object);

            // Arrange
            session.AddReference(1, sourceComponentType, sourceKey, targetComponentType, targetKey);

            // Assert
            _writerMock.Verify(w => w.CreateReference(workspace.Id, sourceId, targetId, 1), Times.Once);
        }
コード例 #5
0
        private IArdoqSession GetSession(Workspace workspace, IExternalReferenceSpecification referenceSpecification)
        {
            if (_sessions.ContainsKey(workspace.Id))
            {
                return(_sessions[workspace.Id]);
            }

            var session = new ArdoqSession(workspace.Id, _reader, _writer);

            _sessions[workspace.Id] = session;

            return(session);
        }
コード例 #6
0
        public static IArdoqSession GetSession(string workspaceId = null, List <Component> components = null, List <Tag> tags = null)
        {
            workspaceId = workspaceId ?? Guid.NewGuid().ToString();
            components  = components ?? new List <Component>();
            tags        = tags ?? new List <Tag>();

            var reader = new FakeArdoqReader(components, tags);
            var writer = new FakeArdoqWriter(components, tags);

            var session = new ArdoqSession(workspaceId, reader, writer);

            return(session);
        }
コード例 #7
0
        public async Task Run(ISourceModelProvider modelProvider)
        {
            //var creator = new ArdoqWorkspaceCreator(_reader, _writer);
            var workspace = await _workspaceCreator.CreateWorkspaceIfMissing(_builder.FolderName, _builder.TemplateName, _builder.WorkspaceName);

            var session = new ArdoqSession(workspace.Id, _reader, _writer);

            var mappingsMap = _builder.ComponentMappings.Aggregate(
                new Dictionary <Type, IBuiltComponentMapping>(),
                (map, m) =>
            {
                map[m.SourceType] = m;
                return(map);
            });

            var finder           = new ParentChildRelationFinder(mappingsMap);
            var hierarchyBuilder = new ParentChildRelationHierarchyBuilder(mappingsMap);

            var allSourceObjects = modelProvider.GetSourceModel().ToList();
            var relations        = finder.FindRelations(allSourceObjects);
            var hierarchies      = hierarchyBuilder.BuildRelationHierarchies(relations).ToList();

            _logger.LogMessage("Starting component maintanence phase.");

            var created    = 0;
            var updated    = 0;
            var tagUpdated = 0;
            var deleted    = 0;

            foreach (var hierarchy in hierarchies)
            {
                var maintainer = new ComponentHierarchyMaintainer(mappingsMap, session);
                created    += maintainer.AddMissingComponents(hierarchy);
                updated    += maintainer.UpdateComponents(hierarchy);
                tagUpdated += maintainer.UpdateComponentTags(hierarchy);
            }

            if (!SafeMode)
            {
                deleted = new ComponentHierarchyMaintainer(mappingsMap, session).DeleteComponents(hierarchies);
            }

            _logger.LogMessage($"Component maintanence phase complete. Created: {created} Updated: {updated} Tag updated: {tagUpdated} Deleted: {deleted} .");

            LinkInternally(relations, workspace, session);
            LinkExternally(relations, session);
            LinkByTags(relations, session);
            LinkBySearch(relations, session);
        }
コード例 #8
0
        public void GetComponentsOfType_HappyDays_GetsExpectedComponents()
        {
            // Arrange
            var workspace = new Workspace("MyWorkspace", null)
            {
                Id = "454923f0-b1b0-48b3-9015-251dad9b4cea"
            };
            var componentType = "MyType";

            _readerMock.Setup(r => r.GetWorkspaceById(workspace.Id))
            .Returns(Task.FromResult(workspace));

            var components = new List <Component>
            {
                new Component("C1", workspace.Id, null)
                {
                    Type = componentType
                },
                new Component("C2", workspace.Id, null)
                {
                    Type = componentType
                },
                new Component("C3", workspace.Id, null)
                {
                    Type = "SomeOtherType"
                }
            };

            _readerMock.Setup(r => r.GetAllComponents(workspace.Id))
            .Returns(Task.FromResult <IEnumerable <Component> >(components));

            var session = new ArdoqSession(workspace.Id, _readerMock.Object, _writerMock.Object);

            // Act
            var comps = session.GetComponentsOfType(componentType);

            // Assert
            Assert.Equal(2, comps.Count());
        }
コード例 #9
0
        public void AddComponent_HappyDays_SendsComponentToArdoqAndCaches()
        {
            // Arrange
            var componentModel = "my-comp-model";
            var workspace      = new Workspace("MyWorkspace", null)
            {
                Id             = "454923f0-b1b0-48b3-9015-251dad9b4cea",
                ComponentModel = componentModel
            };

            var componentType   = "MyType";
            var componentTypeId = "3a1949ef-8b44-4af3-939f-a49d24376248";

            var internalmodel = new global::Ardoq.Models.Model(
                "model-id",
                "MyModel",
                null,
                new Dictionary <string, string> {
                [componentType] = componentTypeId
            },
                null);

            IArdoqModel model = new ArdoqModel(internalmodel);


            var componentName = "MyNewComponent";
            var parentName    = "parentCompName";
            var vals          = new Dictionary <string, object>
            {
                ["k1"] = "v1",
                ["k2"] = "v2"
            };

            _readerMock.Setup(r => r.GetWorkspaceById(workspace.Id))
            .Returns(Task.FromResult(workspace));
            _readerMock.Setup(r => r.GetModelById(componentModel))
            .Returns(Task.FromResult(model));

            var parentComponentId = "f7e4256e-1d84-4fba-96b7-35ed16234b45";
            var parentComponent   = new Component(parentName, workspace.Id, null)
            {
                Id = parentComponentId
            };

            _readerMock.Setup(r => r.GetAllComponents(workspace.Id))
            .Returns(Task.FromResult <IEnumerable <Component> >(new List <Component> {
                parentComponent
            }));

            _writerMock.Setup(w => w.CreateComponent(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                                     It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IDictionary <string, object> >()))
            .Returns(Task.FromResult(new Component(componentName, null, null)
            {
                Type = componentType
            }));

            var session = new ArdoqSession(workspace.Id, _readerMock.Object, _writerMock.Object);

            // Act
            session.AddComponent(componentName, vals, componentType, parentName);

            // Assert
            _writerMock.Verify(w => w.CreateComponent(componentName, workspace.Id, componentType, componentTypeId, parentComponentId, vals));
            Assert.True(session.GetComponentsOfType(componentType).Count() == 1);
        }
コード例 #10
0
        public void LinkAll_NoReferencesPreexist_ReferenceCreatedInArdoq()
        {
            // Arrange
            var sourceWorkspaceId   = "my-workspace-id";
            var sourceWorkspaceName = "RoleWorkspace";

            var refName         = "typical_role_in";
            var refId           = 707;
            var targetCompModel = "TargetComponentModel";
            var sourceCompModel = "SourceComponentModel";

            var targetWorkspaceId   = "industry-workspace";
            var targetWorkspaceName = "IndustryWorkspace";
            var session             = new ArdoqSession(sourceWorkspaceId, _readerMock.Object, _writerMock.Object);

            var sourceObj = new Role()
            {
                Name = "Sales"
            };
            var relation = new ParentChildRelation(null, sourceObj)
            {
                ChildUniqueName = "Sales Role"
            };
            var relations = new List <ParentChildRelation> {
                relation
            };

            var internalmodel = new global::Ardoq.Models.Model(
                "model-id",
                "MyModel",
                null,
                null,
                new Dictionary <string, int> {
                [refName] = refId
            });
            IArdoqModel model = new ArdoqModel(internalmodel);

            var referenceSpec = new ExternalReferenceSpecification <Role>(
                "Industry",
                r => r.GetNameOfIndustry(),
                refName,
                targetWorkspaceName);

            var sourceWorkspace = new Workspace(sourceWorkspaceName, null)
            {
                Id = sourceWorkspaceId, ComponentModel = sourceCompModel
            };
            var targetWorkspace = new Workspace(targetWorkspaceName, null)
            {
                Id = targetWorkspaceId, ComponentModel = targetCompModel
            };

            _readerMock.Setup(r => r.GetWorkspaceNamed(sourceWorkspaceName, null))
            .Returns(Task.FromResult(sourceWorkspace));
            _readerMock.Setup(r => r.GetWorkspaceById(sourceWorkspaceId))
            .Returns(Task.FromResult(sourceWorkspace));
            _readerMock.Setup(r => r.GetWorkspaceNamed(targetWorkspaceName, null))
            .Returns(Task.FromResult(targetWorkspace));
            _readerMock.Setup(r => r.GetWorkspaceById(targetWorkspaceId))
            .Returns(Task.FromResult(targetWorkspace));
            _readerMock.Setup(r => r.GetModelById(targetCompModel))
            .Returns(Task.FromResult(model));
            _readerMock.Setup(r => r.GetModelById(sourceCompModel))
            .Returns(Task.FromResult(model));

            _readerMock.Setup(r => r.GetReferencesById(sourceWorkspaceId))
            .Returns(Task.FromResult(new List <Reference>()));

            _readerMock.Setup(r => r.GetReferencesById(targetWorkspaceId))
            .Returns(Task.FromResult(new List <Reference>()));

            IEnumerable <Component> sourceComps = new List <Component>
            {
                new Component("Sales", sourceWorkspaceId, null)
                {
                    Type = "Role", Id = "role-comp-1"
                }
            };

            IEnumerable <Component> targetComps = new List <Component>
            {
                new Component("Sales and marketing", targetWorkspaceId, null)
                {
                    Type = "Industry", Id = "industry-comp-2"
                }
            };

            _readerMock.Setup(r => r.GetAllComponents(sourceWorkspaceId))
            .Returns(Task.FromResult(sourceComps));
            _readerMock.Setup(r => r.GetAllComponents(targetWorkspaceId))
            .Returns(Task.FromResult(targetComps));

            _maintenanceSessionMock.Setup(m => m.GetComponentType(typeof(Role))).Returns("Role");
            _maintenanceSessionMock.Setup(m => m.GetKeyForInstance(sourceObj)).Returns("Sales");


            var linkageService = new ExternalLinkageService(_readerMock.Object, _writerMock.Object);

            // Act
            linkageService.LinkAll(referenceSpec, relations, session, _maintenanceSessionMock.Object);

            // Assert
            _writerMock.Verify(w => w.CreateReference(targetWorkspaceId, "role-comp-1", "industry-comp-2", refId), Times.Once);
        }