public void BuildRelationHierarchies_SeveralSingleRelation_ReturnsExpectedHierarchies() { // Arrange var relations = new List <ParentChildRelation> { new ParentChildRelation(null, new Subscription { Name = "sub1" }), new ParentChildRelation(null, new Subscription { Name = "sub2" }), new ParentChildRelation(null, new Subscription { Name = "sub3" }), new ParentChildRelation(null, new Subscription { Name = "sub4" }), new ParentChildRelation(null, new Subscription { Name = "sub5" }) }; var builder = new ParentChildRelationHierarchyBuilder(Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub)); // Act var hiers = builder.BuildRelationHierarchies(relations); // Assert Assert.Equal(5, hiers.Count()); }
public void BuildRelationHierarchies_SingleLinearRelations_ReturnsExpectedHierarchies() { // Arrange var subscription = new Subscription { Name = "NETT-PLAYGROUND" }; var subscriptionRelation = new ParentChildRelation(null, subscription); var resourceGroup = new ResourceGroup { Name = "PLAYGROUND-RGprod" }; var resourceGroupRelation = new ParentChildRelation(subscription, resourceGroup); var relations = new List <ParentChildRelation> { subscriptionRelation, resourceGroupRelation }; var builder = new ParentChildRelationHierarchyBuilder(Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub)); // Act var hiers = builder.BuildRelationHierarchies(relations); // Assert Assert.Single(hiers); var h = hiers.First(); Assert.Equal(2, h.LevelCount); var level = h.GetLevel(0); Assert.Single(level); Assert.Contains(subscriptionRelation, level); level = h.GetLevel(1); Assert.Contains(resourceGroupRelation, level); }
public void DeleteComponents_SuperfluousComponentWithSameNameInArdoq_DeletesComponentInArdoq() { // Arrange const string componentTypeSub = "Subscription"; const string componentTypeRG = "ResourceGroup"; const string componentTypeEHN = "EventHubNamespace"; const string tagString = "tag1"; Dictionary <Type, IBuiltComponentMapping> mappings = Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace); var sub = new Subscription { Name = "subName" }; var rg1 = new ResourceGroup { Name = "rg1Name" }; var rg2 = new ResourceGroup { Name = "rg2Name" }; var ehn1 = new EventHubNamespace { Name = "ehNamespaceName", ResourceGroup = rg1, Tags = new List <string> { tagString } }; var relations = Helper.CreateRelations((null, sub), (sub, rg1), (sub, rg2), (rg1, ehn1)); var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchies = builder.BuildRelationHierarchies(relations); var existingTag = new Tag(tagString, null, null) { Components = new List <string> { "tag2" } }; var session = Helper.GetSession(null, null, new List <Tag> { existingTag }); session.AddComponent(sub.Name, null, componentTypeSub, null); session.AddComponent(rg1.Name, null, componentTypeRG, sub.Name); session.AddComponent(rg2.Name, null, componentTypeRG, sub.Name); session.AddComponent(ehn1.Name, null, componentTypeEHN, rg1.Name); session.AddComponent(ehn1.Name, null, componentTypeEHN, rg2.Name); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.DeleteComponents(hierarchies); // Assert Assert.Equal(4, session.GetAllComponents().Count()); Assert.Equal(1, c); }
public void AddMissingComponents_TwoMissingComponentsWithSameNameDifferentGrandParents_CreatesComponentInArdoq() { // Arrange const string subscriptionName = "mySub"; const string rg1Name = "myRG1"; const string rg2Name = "myRG2"; const string eventHubNamespaceName = "myEventHubNamespace"; const string eventHubName = "myEventHub"; var sub = new Subscription { Name = subscriptionName }; var rg1 = new ResourceGroup { Name = rg1Name, Subscription = sub }; var rg2 = new ResourceGroup { Name = rg2Name, Subscription = sub }; var eh1 = new EventHub { Name = eventHubName }; var eh2 = new EventHub { Name = eventHubName }; // Same name as eh1 var ehn1 = new EventHubNamespace { Name = eventHubNamespaceName, ResourceGroup = rg1, EventHubs = new List <EventHub> { eh1 } }; var ehn2 = new EventHubNamespace { Name = eventHubNamespaceName, ResourceGroup = rg2, EventHubs = new List <EventHub> { eh2 } }; // Same name as ehn1 var relations = Helper.CreateRelations((null, sub), (sub, rg1), (sub, rg2), (rg1, ehn1), (rg2, ehn2), (ehn1, eh1), (ehn2, eh2)); var mappings = Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub); var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var session = Helper.GetSession(); session.AddComponent(subscriptionName, null, "Subscription", null); session.AddComponent(rg1Name, null, "ResourceGroup", subscriptionName); session.AddComponent(rg2Name, null, "ResourceGroup", subscriptionName); session.AddComponent(eventHubNamespaceName, null, "EventHubNamespace", rg1Name); session.AddComponent(eventHubNamespaceName, null, "EventHubNamespace", rg2Name); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.AddMissingComponents(hierarchy); // Assert Assert.Equal(2, c); }
public void UpdateComponentTags_TagExistsButDoesNotReferenceComponent_UpdatesTag() { // Arrange var ehNamespaceName = "my-namespace"; var tagString = "tag1"; var componentType = "EventHubNamespace"; var m = new ComponentMapping <EventHubNamespace>(componentType) .WithKey(rg => rg.Name) .WithTags(e => e.Tags) .WithPreexistingHierarchyReference("EventHubs"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(EventHubNamespace)] = m }; var ehn = new EventHubNamespace { Name = ehNamespaceName, Tags = new List <string> { tagString } }; var relations = new List <ParentChildRelation> { new ParentChildRelation(null, ehn) { PreexistingHierarchyReference = "EventHubs" } }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var existingTag = new Tag(tagString, null, null) { Components = new List <string> { "tag2" } }; var session = Helper.GetSession(null, null, new List <Tag> { existingTag }); session.AddComponent(ehNamespaceName, null, componentType, null); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.UpdateComponentTags(hierarchy); // Assert Assert.Equal(2, existingTag.Components.Count); Assert.Equal(1, c); }
public void AddMissingComponents_WithModelledParent_CreatesComponentInArdoq() { // Arrange var m = new ComponentMapping <ResourceGroup>("ResourceGroup") .WithKey(rg => rg.Name) .WithModelledHierarchyReference(rg => rg.Subscription, ModelledReferenceDirection.Child); var m2 = new ComponentMapping <Subscription>("Subscription") .WithKey(s => s.Name) .WithPreexistingHierarchyReference("Subs"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(ResourceGroup)] = m, [typeof(Subscription)] = m2 }; var subscription = new Subscription { Name = "MySub" }; var resourceGroup = new ResourceGroup { Name = "myRG", Subscription = subscription }; var relations = new List <ParentChildRelation> { new ParentChildRelation(null, subscription) { PreexistingHierarchyReference = "Subs" }, new ParentChildRelation(subscription, resourceGroup) }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var subComponent = new Component("MySub", "workspaceId", null) { Type = "Subscription" }; var session = Helper.GetSession("workspaceId", new List <Component> { subComponent }); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.AddMissingComponents(hierarchy); // Assert var addedComp = session.GetComponents("ResourceGroup", "myRG").Single(); Assert.Equal(1, c); }
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); }
public void UpdateComponents_HasSmallChange_UpdatesComponentInArdoq() { // Arrange var m = new ComponentMapping <Employee>("Employee") .WithKey(rg => rg.EmployeeNumber) .WithField(e => e.Name, "employee-name") .WithField(e => e.Age, "age") .WithPreexistingHierarchyReference("Employees"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(Employee)] = m }; var employee = new Employee { Name = "Michael Jackson", EmployeeNumber = "XX99", Age = 55 }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var relations = new List <ParentChildRelation> { new ParentChildRelation(null, employee) { PreexistingHierarchyReference = "Employees" } }; var hierarchy = builder.BuildRelationHierarchies(relations).First(); var session = Helper.GetSession(); var fields = new Dictionary <string, object> { ["employee-name"] = "Michael Jackson", ["age"] = "54" }; session.AddComponent("XX99", fields, "Employee", null); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.UpdateComponents(hierarchy); // Assert Assert.Equal(1, c); Component updatedComponent = session.GetAllComponents().Single(); Assert.Equal("Michael Jackson", updatedComponent.Fields["employee-name"]); Assert.Equal(55, updatedComponent.Fields["age"]); }
public void BuildRelationHierarchies_SingleRelation_ReturnsExpectedHierarchy() { // Arrange var relation = new ParentChildRelation(null, new Subscription { Name = "sub1" }); var relations = new List <ParentChildRelation> { relation }; var builder = new ParentChildRelationHierarchyBuilder(Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace)); // Act var hiers = builder.BuildRelationHierarchies(relations); // Assert Assert.Single(hiers); Assert.Equal(1, hiers.First().LevelCount); }
public void DeleteComponents_WithRealSession_SessionStateModified() { // Arrange var componentType = "Employee"; var m = new ComponentMapping <Employee>(componentType) .WithKey(rg => rg.EmployeeNumber) .WithField(e => e.Name, "employee-name") .WithField(e => e.Age, "age") .WithPreexistingHierarchyReference("Employees"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(Employee)] = m }; var employee = new Employee { Name = "Michael Jackson", EmployeeNumber = "XX99", Age = 55 }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var relations = new List <ParentChildRelation> { new ParentChildRelation(null, employee) { PreexistingHierarchyReference = "Employees" } }; var hierarchies = builder.BuildRelationHierarchies(relations); var session = Helper.GetSession(); session.AddComponent("XX99", null, componentType, null); session.AddComponent("non-existing", null, componentType, null); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.DeleteComponents(hierarchies); // Assert Assert.Equal(1, c); }
public void AddMissingComponents_WithTags_CreatesComponentWithTagsInArdoq() { // Arrange var m = new ComponentMapping <EventHubNamespace>("EventHubNamespace") .WithKey(rg => rg.Name) .WithTags(e => e.Tags) .WithPreexistingHierarchyReference("EventHubs"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(EventHubNamespace)] = m }; var ehn = new EventHubNamespace() { Name = "events-1", Tags = new List <string> { "v1", "v2" } }; var relations = new List <ParentChildRelation> { new ParentChildRelation(null, ehn) { PreexistingHierarchyReference = "EventHubs" } }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var session = Helper.GetSession(); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.AddMissingComponents(hierarchy); // Assert var comp = session.GetComponents("EventHubNamespace", "events-1").Single(); Assert.NotNull(comp); Assert.Equal(1, c); }
public void GetAllChildren_ForBuiltHierarchy_GetsExpectedChildren() { // Arrange var subscription = new Subscription { Name = "NETT-PLAYGROUND" }; var subscriptionRelation = new ParentChildRelation(null, subscription); var resourceGroup = new ResourceGroup { Name = "PLAYGROUND-RGprod" }; var resourceGroupRelation = new ParentChildRelation(subscription, resourceGroup); var ehNamespace = new EventHubNamespace { Name = "my-namespace" }; var ehNamespaceReleation = new ParentChildRelation(resourceGroup, ehNamespace); var eventHub = new EventHub { Name = "my-events" }; var eventHubRelation = new ParentChildRelation(ehNamespace, eventHub); var relations = new List <ParentChildRelation> { subscriptionRelation, resourceGroupRelation, ehNamespaceReleation, eventHubRelation }; var builder = new ParentChildRelationHierarchyBuilder(Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub)); var hierarchy = builder.BuildRelationHierarchies(relations).First(); // Act var children = hierarchy.GetAllChildren().ToList(); // Assert Assert.Equal(4, children.Count()); Assert.Contains(subscription, children); Assert.Contains(resourceGroup, children); Assert.Contains(ehNamespace, children); Assert.Contains(eventHub, children); }
public void DeleteComponents_NothingToDelete_NoDeletesSendToArdoq() { // Arrange var m = new ComponentMapping <Employee>("Employee") .WithKey(rg => rg.EmployeeNumber) .WithField(e => e.Name, "employee-name") .WithField(e => e.Age, "age") .WithPreexistingHierarchyReference("Employees"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(Employee)] = m }; var employee = new Employee { Name = "Michael Jackson", EmployeeNumber = "XX99", Age = 55 }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var relations = new List <ParentChildRelation> { new ParentChildRelation(null, employee) { PreexistingHierarchyReference = "Employees" } }; var hierarchies = builder.BuildRelationHierarchies(relations); var session = Helper.GetSession(); session.AddComponent("XX99", null, "Employee", null); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.DeleteComponents(hierarchies); // Assert Assert.Single(session.GetAllComponents()); Assert.Equal(0, c); }
public void AddMissingComponents_IsNew_ExpectedFieldValuesSentToArdoq() { // Arrange var m = new ComponentMapping <Employee>("Employee") .WithKey(e => e.Name) .WithField(e => e.EmployeeNumber, "employee-number"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(Employee)] = m }; var employee = new Employee { Name = "Don Johnsen", EmployeeNumber = "808" }; var relations = new List <ParentChildRelation> { new ParentChildRelation(null, employee) { PreexistingHierarchyReference = "Employees" } }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var session = Helper.GetSession(); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act maintainer.AddMissingComponents(hierarchy); // Assert var comp = session.GetComponents("Employee", "Don Johnsen").Single(); Assert.Single(comp.Fields); Assert.Equal("808", comp.Fields["employee-number"]); }
public void AddMissingComponents_ComponentAlreadyExists_DoesNotCreateComponentInArdoq() { // Arrange var m = new ComponentMapping <ResourceGroup>("ResourceGroup") .WithKey(rg => rg.Name) .WithPreexistingHierarchyReference("ResourceGroups"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(ResourceGroup)] = m }; var resourceGroup = new ResourceGroup { Name = "myRG" }; var relations = new List <ParentChildRelation> { new ParentChildRelation(null, resourceGroup) { PreexistingHierarchyReference = "ResourceGroups" } }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var session = Helper.GetSession(); session.AddComponent("myRG", null, "ResourceGroup", null); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.AddMissingComponents(hierarchy); // Assert Assert.Single(session.GetAllComponents()); Assert.Equal(0, c); }
public void UpdateComponents_TwoComponentsWithSameName_NoChanges_NoUpdatesToArdoq() { // Arrange const string workspaceId = "workspaceId"; var d = new ComponentMapping <Department>("Department") .WithKey(dd => dd.Name); var m = new ComponentMapping <Employee>("Employee") .WithKey(rg => rg.EmployeeNumber) .WithField(e => e.Name, "employee-name") .WithField(e => e.Age, "age") .WithPreexistingHierarchyReference("Employees"); var mappings = new Dictionary <Type, IBuiltComponentMapping> { [typeof(Department)] = d, [typeof(Employee)] = m }; var department1 = new Department { Name = "Sony Music" }; var department2 = new Department { Name = "MTV" }; var employee = new Employee { Name = "Michael Jackson", EmployeeNumber = "XX99", Age = 55 }; var builder = new ParentChildRelationHierarchyBuilder(mappings); var relations = new List <ParentChildRelation> { new ParentChildRelation(null, department1) { }, new ParentChildRelation(department1, employee) { }, new ParentChildRelation(department2, employee) { } }; var hierarchy = builder.BuildRelationHierarchies(relations).First(); var compDep1 = new Component("Sony Music", workspaceId, null) { Id = "parentId1", Type = "Department" }; var compDep2 = new Component("MTV", workspaceId, null) { Id = "parentId2", Type = "Department" }; var comp1 = new Component("XX99", workspaceId, null) { Id = "id1", Parent = compDep1.Id, Type = "Employee", Fields = new Dictionary <string, object> { ["employee-name"] = "Michael Jackson", ["age"] = 55 } }; var comp2 = new Component("XX99", workspaceId, null) { Id = "id2", Parent = compDep2.Id, Type = "Employee", Fields = new Dictionary <string, object> { ["employee-name"] = "Michael Jackson", ["age"] = 55 } }; var session = Helper.GetSession(workspaceId, new List <Component> { compDep1, compDep2, comp1, comp2 }); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.UpdateComponents(hierarchy); // Assert Assert.Equal(0, c); }
public void UpdateComponentTags_TagExistsOnTwoComponentsWithSameName_UpdatesTag() { // Arrange const string componentTypeSub = "Subscription"; var componentTypeRG = "ResourceGroup"; var componentTypeEHN = "EventHubNamespace"; var tagString = "tag1"; var ehNamespaceName = "my-namespace"; string workspaceId = Guid.NewGuid().ToString(); var sub = new Subscription { Name = "subName" }; var rg1 = new ResourceGroup { Name = "rg1Name" }; var rg2 = new ResourceGroup { Name = "rg2Name" }; var ehn1 = new EventHubNamespace { Name = ehNamespaceName, ResourceGroup = rg1, Tags = new List <string> { tagString } }; var ehn2 = new EventHubNamespace { Name = ehNamespaceName, ResourceGroup = rg2, Tags = new List <string> { tagString } }; List <ParentChildRelation> relations = Helper.CreateRelations((null, sub), (sub, rg1), (sub, rg2), (rg1, ehn1), (rg2, ehn2)); var mappings = Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace); var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var compSub = new Component(sub.Name, workspaceId, null) { Type = componentTypeSub, Id = "subid" }; var compRG1 = new Component(rg1.Name, workspaceId, null) { Type = componentTypeRG, Id = "rg1id", Parent = compSub.Id }; var compRG2 = new Component(rg2.Name, workspaceId, null) { Type = componentTypeRG, Id = "rg2id", Parent = compSub.Id }; var compEHN1 = new Component(ehNamespaceName, workspaceId, null) { Type = componentTypeEHN, Id = "ehn1componentId", Parent = compRG1.Id }; var compEHN2 = new Component(ehNamespaceName, workspaceId, null) { Type = componentTypeEHN, Id = "ehn2componentId", Parent = compRG2.Id }; var existingTag = new Tag(tagString, null, null) { Components = new List <string> { "tag2" } }; var components = new List <Component> { compSub, compRG1, compRG2, compEHN1, compEHN2 }; var session = Helper.GetSession(workspaceId, components, new List <Tag> { existingTag }); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.UpdateComponentTags(hierarchy); // Assert Assert.Equal(3, existingTag.Components.Count); Assert.Equal(2, c); }
public void FindRelations_ThenBuildHierarchy_BuildsExpectedHiearchy() { // Arrange var sub = new Subscription { Name = "NETT-MDM" }; var rgDev = new ResourceGroup { Name = "MDM-RGdev", Subscription = sub }; var rgTest = new ResourceGroup { Name = "MDM-RGtest", Subscription = sub }; var eXdev = new EventHub { Name = "x-dev" }; var eYdev = new EventHub { Name = "y-dev" }; var nsDev = new EventHubNamespace { Name = "dev", ResourceGroup = rgDev, EventHubs = new List <EventHub> { eXdev, eYdev } }; var eXtest = new EventHub { Name = "x-test" }; var eYtest = new EventHub { Name = "y-test" }; var nsTest = new EventHubNamespace { Name = "test", ResourceGroup = rgTest, EventHubs = new List <EventHub> { eXtest, eYtest } }; var nakedEventHub = new EventHub { Name = "naked" }; var objs = new List <object> { sub, rgDev, rgTest, eXdev, eYdev, nsDev, eXtest, eYtest, nsTest, nakedEventHub }; var mappings = Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub); var finder = new ParentChildRelationFinder(mappings); var hierarchyBuilder = new ParentChildRelationHierarchyBuilder(mappings); // Act var relations = finder.FindRelations(objs); var hierarchies = hierarchyBuilder.BuildRelationHierarchies(relations).ToList(); // Assert Assert.Equal(2, hierarchies.Count); var h = hierarchies.Single(hi => hi.LevelCount == 4); Assert.Single(h.GetLevel(0)); Assert.Contains(h.GetLevel(0), r => r.Parent == null && r.Child == sub); Assert.Equal(2, h.GetLevel(1).Count); Assert.Contains(h.GetLevel(1), r => r.Parent == sub && r.Child == rgDev); Assert.Contains(h.GetLevel(1), r => r.Parent == sub && r.Child == rgTest); Assert.Equal(2, h.GetLevel(2).Count); Assert.Contains(h.GetLevel(2), r => r.Parent == rgTest && r.Child == nsTest); Assert.Contains(h.GetLevel(2), r => r.Parent == rgDev && r.Child == nsDev); Assert.Equal(4, h.GetLevel(3).Count); Assert.Contains(h.GetLevel(3), r => r.Parent == nsTest && r.Child == eXtest); Assert.Contains(h.GetLevel(3), r => r.Parent == nsTest && r.Child == eYtest); Assert.Contains(h.GetLevel(3), r => r.Parent == nsDev && r.Child == eXdev); Assert.Contains(h.GetLevel(3), r => r.Parent == nsDev && r.Child == eYdev); h = hierarchies.Single(hi => hi.LevelCount == 1); Assert.Single(h.GetLevel(0)); Assert.Contains(h.GetLevel(0), r => r.Parent == null && r.Child == nakedEventHub); }
public void AddMissingComponents_MissingComponentWithExistingNameDifferentGrandParent_CreatesComponentInArdoq() { // Arrange const string subscriptionName = "mySub"; const string rg1Name = "myRG1"; const string rg2Name = "myRG2"; const string eventHubNamespaceName = "myEventHubNamespace"; const string eventHubName = "myEventHub"; const string workspaceId = "workspaceId"; var sub = new Subscription { Name = subscriptionName }; var rg1 = new ResourceGroup { Name = rg1Name, Subscription = sub }; var rg2 = new ResourceGroup { Name = rg2Name, Subscription = sub }; var eh1 = new EventHub { Name = eventHubName }; var eh2 = new EventHub { Name = eventHubName }; // Same name as eh1 var ehn1 = new EventHubNamespace { Name = eventHubNamespaceName, ResourceGroup = rg1, EventHubs = new List <EventHub> { eh1 } }; var ehn2 = new EventHubNamespace { Name = eventHubNamespaceName, ResourceGroup = rg2, EventHubs = new List <EventHub> { eh2 } }; // Same name as ehn1 var relations = Helper.CreateRelations((null, sub), (sub, rg1), (sub, rg2), (rg1, ehn1), (rg2, ehn2), (ehn1, eh1), (ehn2, eh2)); var mappings = Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub); var builder = new ParentChildRelationHierarchyBuilder(mappings); var hierarchy = builder.BuildRelationHierarchies(relations).First(); var subComp = new Component(subscriptionName, workspaceId, null) { Type = "Subscription", Id = "subId" }; var rg1Comp = new Component(rg1Name, workspaceId, null) { Type = "ResourceGroup", Id = "rg1Id", Parent = subComp.Id }; var rg2Comp = new Component(rg2Name, workspaceId, null) { Type = "ResourceGroup", Id = "rg2Id", Parent = subComp.Id }; var ehn1Comp = new Component(eventHubNamespaceName, workspaceId, null) { Type = "EventHubNamespace", Id = "ehn1Id", Parent = rg1Comp.Id }; var ehn2Comp = new Component(eventHubNamespaceName, workspaceId, null) { Type = "EventHubNamespace", Id = "ehn2Id", Parent = rg2Comp.Id }; var ehComp = new Component(eventHubName, workspaceId, null) { Type = "EventHub", Id = "ehId", Parent = ehn1Comp.Id }; var session = Helper.GetSession(workspaceId, new List <Component> { subComp, rg1Comp, rg2Comp, ehn1Comp, ehn2Comp, ehComp }); var maintainer = new ComponentHierarchyMaintainer(mappings, session); // Act var c = maintainer.AddMissingComponents(hierarchy); // Assert Assert.Equal(1, c); }
public void BuildRelationHierarchies_BroadAndParalellHierachies_ReturnsExpectedHierarchies() { // Arrange var subscription = new Subscription { Name = "NETT-PLAYGROUND" }; var subscriptionRelation = new ParentChildRelation(null, subscription); var resourceGroup = new ResourceGroup { Name = "PLAYGROUND-RGprod" }; var resourceGroupRelation = new ParentChildRelation(subscription, resourceGroup); var ehNamespace = new EventHubNamespace { Name = "my-namespace" }; var ehNamespaceReleation = new ParentChildRelation(resourceGroup, ehNamespace); var eventHub = new EventHub { Name = "my-events" }; var eventHubRelation = new ParentChildRelation(ehNamespace, eventHub); var sub2 = new Subscription { Name = "NETT-MDM" }; var sub2R = new ParentChildRelation(null, sub2); var rg2 = new ResourceGroup { Name = "MDM-RGtest" }; var rg2R = new ParentChildRelation(sub2, rg2); var ehn1 = new EventHubNamespace { Name = "mdm-1" }; var ehn1R = new ParentChildRelation(rg2, ehn1); var ehn2 = new EventHubNamespace { Name = "mdm-2" }; var ehn2R = new ParentChildRelation(rg2, ehn2); var eh1 = new EventHub { Name = "eh1" }; var eh1R = new ParentChildRelation(ehn1, eh1); var eh2 = new EventHub { Name = "eh2" }; var eh2R = new ParentChildRelation(ehn2, eh2); var relations = new List <ParentChildRelation> { subscriptionRelation, resourceGroupRelation, ehNamespaceReleation, eventHubRelation, sub2R, rg2R, ehn1R, ehn2R, eh1R, eh2R }; var builder = new ParentChildRelationHierarchyBuilder(Helper.GetModel(ModelType.Subscription_ResourceGroup_EventHubNamespace_EventHub)); // Act var hiers = builder.BuildRelationHierarchies(relations).ToList(); // Assert Assert.Equal(2, hiers.Count()); var hier = hiers.Single(h => ((Subscription)h.GetLevel(0).First().Child).Name == "NETT-PLAYGROUND"); Assert.Equal(4, hier.LevelCount); var level = hier.GetLevel(0); Assert.Single(level); Assert.Contains(subscriptionRelation, level); level = hier.GetLevel(1); Assert.Contains(resourceGroupRelation, level); level = hier.GetLevel(2); Assert.Contains(ehNamespaceReleation, level); level = hier.GetLevel(3); Assert.Contains(eventHubRelation, level); hier = hiers.Single(h => ((Subscription)h.GetLevel(0).First().Child).Name == "NETT-MDM"); level = hier.GetLevel(0); Assert.Single(level); Assert.Contains(sub2R, level); level = hier.GetLevel(1); Assert.Contains(rg2R, level); level = hier.GetLevel(2); Assert.Equal(2, level.Count); Assert.Contains(ehn1R, level); Assert.Contains(ehn2R, level); level = hier.GetLevel(3); Assert.Equal(2, level.Count); Assert.Contains(eh1R, level); Assert.Contains(eh2R, level); }