public async Task UpdateNamespace() { //create namespace string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, true); //update namespace var updateNamespaceParameter = eventHubNamespace.Data; updateNamespaceParameter.Tags.Add("key1", "value1"); updateNamespaceParameter.Tags.Add("key2", "value2"); eventHubNamespace = await eventHubNamespace.UpdateAsync(updateNamespaceParameter); //validate Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 2); Assert.AreEqual("value1", eventHubNamespace.Data.Tags["key1"]); Assert.AreEqual("value2", eventHubNamespace.Data.Tags["key2"]); //wait until provision state is succeeded await GetSucceededNamespace(eventHubNamespace); }
public async Task CreateDeleteNamespace() { //create namespace and wait for completion string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, true); //validate if created successfully eventHubNamespace = await namespaceCollection.GetAsync(namespaceName); Assert.IsTrue(await namespaceCollection.ExistsAsync(namespaceName)); VerifyNamespaceProperties(eventHubNamespace, true); //delete namespace await eventHubNamespace.DeleteAsync(WaitUntil.Completed); //validate if deleted successfully eventHubNamespace = await namespaceCollection.GetIfExistsAsync(namespaceName); Assert.IsNull(eventHubNamespace); Assert.IsFalse(await namespaceCollection.ExistsAsync(namespaceName)); }
public async Task GetAllNamespaces() { //create two namespaces string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt1"); string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt2"); _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); _ = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new EventHubNamespaceData(DefaultLocation))).Value; _ = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new EventHubNamespaceData(DefaultLocation))).Value; int count = 0; EventHubNamespace namespace1 = null; EventHubNamespace namespace2 = null; //validate await foreach (EventHubNamespace eventHubNamespace in namespaceCollection.GetAllAsync()) { count++; if (eventHubNamespace.Id.Name == namespaceName1) { namespace1 = eventHubNamespace; } if (eventHubNamespace.Id.Name == namespaceName2) { namespace2 = eventHubNamespace; } } Assert.AreEqual(count, 2); VerifyNamespaceProperties(namespace1, true); VerifyNamespaceProperties(namespace2, true); }
public void GetRelatedObjects_HasListReference_ReturnsExpectedRelations() { // Arrange var spec = new ModelledReferenceAccessSpecification <EventHubNamespace>( rg => rg.EventHubs, ModelledReferenceDirection.Parent); var e1 = new EventHub { Name = "e1" }; var e2 = new EventHub { Name = "e2" }; var ehn = new EventHubNamespace { Name = "ehn", EventHubs = new List <EventHub> { e1, e2 } }; // Act var relations = spec.GetRelatedObjects(ehn).ToList(); // Assert Assert.Equal(2, relations.Count()); Assert.True(relations.All(t => t.Item2 == ModelledReferenceDirection.Parent)); Assert.Contains(relations, r => r.Item1 == e1); Assert.Contains(relations, r => r.Item1 == e2); }
public async Task AddSetRemoveTag() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //add a tag eventHubNamespace = await eventHubNamespace.AddTagAsync("key", "value"); Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 1); Assert.AreEqual(eventHubNamespace.Data.Tags["key"], "value"); //set the tag eventHubNamespace.Data.Tags.Add("key1", "value1"); eventHubNamespace = await eventHubNamespace.SetTagsAsync(eventHubNamespace.Data.Tags); Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 2); Assert.AreEqual(eventHubNamespace.Data.Tags["key1"], "value1"); //remove a tag eventHubNamespace = await eventHubNamespace.RemoveTagAsync("key"); Assert.AreEqual(eventHubNamespace.Data.Tags.Count, 1); //wait until provision state is succeeded await GetSucceededNamespace(eventHubNamespace); }
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 async Task CreateNamespaceAndGetEventhubCollection() { _resourceGroup = await CreateResourceGroupAsync(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); EventHubNamespace eHNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; EventHubCollection eventhubCollection = eHNamespace.GetEventHubs(); string eventhubName = Recording.GenerateAssetName("eventhub"); _eventHub = (await eventhubCollection.CreateOrUpdateAsync(WaitUntil.Completed, eventhubName, new EventHubData())).Value; _consumerGroupCollection = _eventHub.GetConsumerGroups(); }
public async Task GetPrivateLinkResources() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //get private link resource IReadOnlyList <PrivateLinkResource> privateLinkResources = (await eventHubNamespace.GetPrivateLinkResourcesAsync()).Value; Assert.NotNull(privateLinkResources); }
public async Task ClearNamespaces() { //remove all namespaces under current resource group if (_resourceGroup != null) { EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); List <EventHubNamespace> namespaceList = await namespaceCollection.GetAllAsync().ToEnumerableAsync(); foreach (EventHubNamespace EventHubNamespace in namespaceList) { await EventHubNamespace.DeleteAsync(WaitUntil.Completed); } _resourceGroup = null; } }
public void BuildRelationHierarchies_DeepLinearReleations_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 relations = new List <ParentChildRelation> { subscriptionRelation, resourceGroupRelation, ehNamespaceReleation, eventHubRelation }; 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(4, h.LevelCount); var level = h.GetLevel(0); Assert.Single(level); Assert.Contains(subscriptionRelation, level); level = h.GetLevel(1); Assert.Contains(resourceGroupRelation, level); level = h.GetLevel(2); Assert.Contains(ehNamespaceReleation, level); level = h.GetLevel(3); Assert.Contains(eventHubRelation, level); }
public async Task <EventHubNamespace> GetSucceededNamespace(EventHubNamespace eventHubNamespace) { int i = 0; while (!eventHubNamespace.Data.ProvisioningState.Equals("Succeeded") && i < 10) { if (Mode != RecordedTestMode.Playback) { await Task.Delay(10000); } eventHubNamespace = await eventHubNamespace.GetAsync(); i++; } return(eventHubNamespace); }
public async Task CreateNamespaceWithKafkaEnabled() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespaceData parameter = new EventHubNamespaceData(DefaultLocation) { KafkaEnabled = true }; EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; VerifyNamespaceProperties(eventHubNamespace, false); Assert.IsTrue(eventHubNamespace.Data.KafkaEnabled); }
public async Task GetPrivateLinkResources() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; //get private link resource await foreach (var _ in eventHubNamespace.GetPrivateLinkResourcesAsync()) { return; } Assert.Fail($"{nameof(EventHubNamespace)}.{nameof(EventHubNamespace.GetPrivateLinkResourcesAsync)} has returned an empty collection of {nameof(PrivateLinkResource)}."); }
public async Task NamespaceAuthorizationRuleRegenerateKey() { //create namespace _resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection = _resourceGroup.GetEventHubNamespaces(); string namespaceName = await CreateValidNamespaceName("testnamespacemgmt"); EventHubNamespace eventHubNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(DefaultLocation))).Value; NamespaceAuthorizationRuleCollection ruleCollection = eventHubNamespace.GetNamespaceAuthorizationRules(); //create authorization rule string ruleName = Recording.GenerateAssetName("authorizationrule"); AuthorizationRuleData parameter = new AuthorizationRuleData() { Rights = { AccessRights.Listen, AccessRights.Send } }; NamespaceAuthorizationRule authorizationRule = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, parameter)).Value; Assert.NotNull(authorizationRule); Assert.AreEqual(authorizationRule.Data.Rights.Count, parameter.Rights.Count); AccessKeys keys1 = await authorizationRule.GetKeysAsync(); Assert.NotNull(keys1); Assert.NotNull(keys1.PrimaryConnectionString); Assert.NotNull(keys1.SecondaryConnectionString); AccessKeys keys2 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.PrimaryKey)); if (Mode != RecordedTestMode.Playback) { Assert.AreNotEqual(keys1.PrimaryKey, keys2.PrimaryKey); Assert.AreEqual(keys1.SecondaryKey, keys2.SecondaryKey); } AccessKeys keys3 = await authorizationRule.RegenerateKeysAsync(new RegenerateAccessKeyOptions(KeyType.SecondaryKey)); if (Mode != RecordedTestMode.Playback) { Assert.AreEqual(keys2.PrimaryKey, keys3.PrimaryKey); Assert.AreNotEqual(keys2.SecondaryKey, keys3.SecondaryKey); } }
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 async Task GetNamespacesInSubscription() { //create two namespaces in two resourcegroups string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt1"); string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt2"); _resourceGroup = await CreateResourceGroupAsync(); ResourceGroup resourceGroup = await CreateResourceGroupAsync(); EventHubNamespaceCollection namespaceCollection1 = _resourceGroup.GetEventHubNamespaces(); EventHubNamespaceCollection namespaceCollection2 = resourceGroup.GetEventHubNamespaces(); _ = (await namespaceCollection1.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new EventHubNamespaceData(DefaultLocation))).Value; _ = (await namespaceCollection2.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new EventHubNamespaceData(DefaultLocation))).Value; int count = 0; EventHubNamespace namespace1 = null; EventHubNamespace namespace2 = null; //validate await foreach (EventHubNamespace eventHubNamespace in DefaultSubscription.GetEventHubNamespacesAsync()) { count++; if (eventHubNamespace.Id.Name == namespaceName1) { namespace1 = eventHubNamespace; } if (eventHubNamespace.Id.Name == namespaceName2) { namespace2 = eventHubNamespace; } } VerifyNamespaceProperties(namespace1, true); VerifyNamespaceProperties(namespace2, true); Assert.AreEqual(namespace1.Id.ResourceGroupName, _resourceGroup.Id.Name); Assert.AreEqual(namespace2.Id.ResourceGroupName, resourceGroup.Id.Name); await namespace2.DeleteAsync(WaitUntil.Completed); }