public void CreateWorkspaceIfMissing_NoWorkspace_ShouldCreateNewWorkspace() { var folder = SetupMockWithFolder(); var internalmodel = new global::Ardoq.Models.Model(); IArdoqModel template = new ArdoqModel(internalmodel); var templateId = "987"; template.Id = templateId; _readerMock.Setup(r => r.GetTemplateByName(templateName)) .Returns(Task.FromResult(template)); var ws = new Workspace(workspaceName, ""); _writerMock .Setup(w => w.CreateWorkspace(It.IsAny <Workspace>())) .Returns(Task.FromResult(ws)); //_writerMock // .Setup(client => client.WorkspaceService.CreateWorkspace( // It.Is<Workspace>(w => w.Name == workspaceName && w.ComponentTemplate == templateId), null)) // .Returns(Task.FromResult(ws)); var workspace = _workspaceCreator.CreateWorkspaceIfMissing(folderName, templateName, workspaceName).Result; Assert.Equal(ws, workspace); }
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); }
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); }
public ArdoqModel(global::Ardoq.Models.Model model) { _internalModel = model; }
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); }
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); }