public void Link_MultipleRefsOfSameTypeFromSource_AllReferencesAreAdded() { // Arrange var linker = new ObjectReferenceLinker(GetMappingWithSameReferenceType(), null, _ardogSessionMock.Object, _maintenanceSessionMock.Object); var relations = GetAllRelations(); var relation = relations[1]; // Act linker.Link(relations, relation); // Assert _ardogSessionMock.Verify(s => s.AddReference( It.IsAny <int>(), It.IsAny <ParentChildRelation>(), It.IsAny <ParentChildRelation>()), Times.Exactly(3)); }
public void Link_NoExistingReferences_AllExpectedReferencesAreAdded2() { // Arrange var linker = new ObjectReferenceLinker(GetMapping(), null, _ardogSessionMock.Object, _maintenanceSessionMock.Object); var relations = GetAllRelations(); var relation = relations[1]; // Act linker.Link(relations, relation); // Assert _ardogSessionMock.Verify(s => s.AddReference( It.IsAny <int>(), It.IsAny <ParentChildRelation>(), It.IsAny <ParentChildRelation>()), Times.Exactly(3)); _ardogSessionMock.Verify(s => s.DeleteReference(It.IsAny <Reference>()), Times.Never); }
public void Link_TargetWorkspaceNotMatching_NothingSentToArdoq() { // Arrange var workspaceId = "my-workspace"; var workspace = new Workspace("MyWorkspace", null) { Id = workspaceId }; var compType = "Employee"; var sourceKey = "12345"; var linker = new ObjectReferenceLinker(GetMapping(), workspace, _ardogSessionMock.Object, _maintenanceSessionMock.Object); var relations = GetAllRelations(workspaceId); var relation = relations[1]; _maintenanceSessionMock.Setup(m => m.GetComponentType(typeof(Employee))).Returns(compType); _maintenanceSessionMock.Setup(m => m.GetKeyForInstance(relation.Child)).Returns(sourceKey); _ardogSessionMock.Setup(m => m.GetChildComponent(relation)).Returns(new Component(sourceKey, workspaceId, null) { Type = compType }); var staleReference = new Reference(null, null, "sourceid", "targetid", 1) { TargetWorkspace = "some-other-workspace" }; _ardogSessionMock.Setup(a => a.GetAllSourceReferencesFromChild(relation)) .Returns(new List <Reference> { staleReference }); // Act linker.Link(relations, relation); // Assert _ardogSessionMock.Verify(s => s.AddReference( It.IsAny <int>(), It.IsAny <ParentChildRelation>(), It.IsAny <ParentChildRelation>()), Times.Exactly(3)); _ardogSessionMock.Verify(s => s.DeleteReference(staleReference), Times.Never); }
public void Link_NoneMissingNoneStale_NothingSentToArdoq() { // Arrange var workspaceId = "my-workspace"; var workspace = new Workspace("MyWorkspace", null) { Id = workspaceId }; var compType = "Employee"; var compTypeDepartment = "Department"; var compTypeRole = "Role"; var sourceKey = "12345"; var sourceKeyDepartment = "HQ"; var roleKey1 = "CEO"; var roleKey2 = "BoardMember"; var dep = new Department { Name = sourceKeyDepartment }; var role1 = new Role { Name = roleKey1 }; var role2 = new Role { Name = roleKey2 }; var employee = new Employee { EmployeeNumber = sourceKey, Name = "Mickey Mouse", EmployedIn = dep, Roles = new List <Role> { role1, role2 } }; var relations = new List <ParentChildRelation> { new ParentChildRelation(null, dep), new ParentChildRelation(dep, employee), new ParentChildRelation(employee, role1), new ParentChildRelation(employee, role2) }; var relation = relations[1]; var linker = new ObjectReferenceLinker(GetMapping(), workspace, _ardogSessionMock.Object, _maintenanceSessionMock.Object); _maintenanceSessionMock.Setup(m => m.GetComponentType(typeof(Employee))).Returns(compType); _maintenanceSessionMock.Setup(m => m.GetComponentType(typeof(Department))).Returns(compTypeDepartment); _maintenanceSessionMock.Setup(m => m.GetComponentType(typeof(Role))).Returns(compTypeRole); _ardogSessionMock.Setup(s => s.GetReferenceTypeForName("works_in")).Returns(1); _ardogSessionMock.Setup(s => s.GetReferenceTypeForName("has_role")).Returns(2); var depCompId = "dep-comp-id"; _ardogSessionMock.Setup(s => s.GetChildComponent(relations[0])) .Returns(new Component { Id = depCompId }); var roleCompId1 = "role-comp-id-1"; _ardogSessionMock.Setup(s => s.GetChildComponent(relations[2])) .Returns(new Component { Id = roleCompId1 }); var roleCompId2 = "role-comp-id-2"; _ardogSessionMock.Setup(s => s.GetChildComponent(relations[3])) .Returns(new Component { Id = roleCompId2 }); var ref1 = new Reference(null, null, sourceKey, depCompId, 1) { TargetWorkspace = workspaceId }; var ref2 = new Reference(null, null, sourceKey, roleCompId1, 2) { TargetWorkspace = workspaceId }; var ref3 = new Reference(null, null, sourceKey, roleCompId2, 2) { TargetWorkspace = workspaceId }; _ardogSessionMock.Setup(a => a.GetAllSourceReferencesFromChild(relation)) .Returns(new List <Reference> { ref1, ref2, ref3 }); // Act linker.Link(relations, relation); // Assert _ardogSessionMock.Verify(s => s.AddReference( It.IsAny <int>(), It.IsAny <ParentChildRelation>(), It.IsAny <ParentChildRelation>()), Times.Never); _ardogSessionMock.Verify(s => s.DeleteReference(It.IsAny <Reference>()), Times.Never); }