Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.


namespace EventHub.Tests.ScenarioTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.Azure.Management.EventHub;
using Microsoft.Azure.Management.EventHub.Models;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using TestHelper;
using Xunit;
public partial class ScenarioTests
{
[Fact]
public void ConsumerGroupsCreateGetUpdateDelete_Length()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
InitializeClients(context);

var location = this.ResourceManagementClient.GetLocationFromProvider();

var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location);
if (string.IsNullOrWhiteSpace(resourceGroup))
{
resourceGroup = TestUtilities.GenerateName(EventHubManagementHelper.ResourceGroupPrefix);
this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup);
}

var namespaceName = TestUtilities.GenerateName(EventHubManagementHelper.NamespacePrefix);
var createNamespaceResponse = this.EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName,
new EHNamespace()
{
Location = location,
Sku = new Sku
{
Name = SkuName.Standard,
Tier = SkuTier.Standard
},
Tags = new Dictionary<string, string>()
{
{"tag1", "value1"},
{"tag2", "value2"}
}
});

Assert.NotNull(createNamespaceResponse);
Assert.Equal(createNamespaceResponse.Name, namespaceName);

TestUtilities.Wait(TimeSpan.FromSeconds(5));

// Create Eventhub
var eventhubName = EventHubManagementHelper.EventHubPrefix + "thisisthenamewithmorethan53charschecktoverifytheremovlaof50charsnamelengthlimit";

var createEventhubResponse = this.EventHubManagementClient.EventHubs.CreateOrUpdate(resourceGroup, namespaceName, eventhubName,
new Eventhub() { MessageRetentionInDays = 5 });

Assert.NotNull(createEventhubResponse);
Assert.Equal(createEventhubResponse.Name, eventhubName);

//Get the created EventHub
var geteventhubResponse = EventHubManagementClient.EventHubs.Get(resourceGroup, namespaceName, eventhubName);
Assert.NotNull(geteventhubResponse);
Assert.Equal(EntityStatus.Active, geteventhubResponse.Status);
Assert.Equal(geteventhubResponse.Name, eventhubName);

// Create ConsumerGroup.
var consumergroupName = "thisisthenamewithmorethan53charschecktoverifqwert";
string UserMetadata = "Newly Created";
var createConsumergroupResponse = EventHubManagementClient.ConsumerGroups.CreateOrUpdate(resourceGroup, namespaceName, eventhubName, consumergroupName, new ConsumerGroup { UserMetadata = UserMetadata});
Assert.NotNull(createConsumergroupResponse);
Assert.Equal(createConsumergroupResponse.Name, consumergroupName);

// Get Created ConsumerGroup
var getConsumergroupGetResponse = EventHubManagementClient.ConsumerGroups.Get(resourceGroup, namespaceName, eventhubName, consumergroupName);
Assert.NotNull(getConsumergroupGetResponse);
Assert.Equal(getConsumergroupGetResponse.Name, consumergroupName);

// Get all ConsumerGroup
var getSubscriptionsListAllResponse = EventHubManagementClient.ConsumerGroups.ListByEventHub(resourceGroup, namespaceName, eventhubName);
Assert.NotNull(getSubscriptionsListAllResponse);
Assert.True(getSubscriptionsListAllResponse.All(ns => ns.Id.Contains(resourceGroup)));

//Update the Created consumergroup
createConsumergroupResponse.UserMetadata = "Updated the user meta data";
var updateconsumergroupResponse = EventHubManagementClient.ConsumerGroups.CreateOrUpdate(resourceGroup, namespaceName, eventhubName, consumergroupName, createConsumergroupResponse);
Assert.NotNull(updateconsumergroupResponse);
Assert.Equal(updateconsumergroupResponse.Name, createConsumergroupResponse.Name);
Assert.Equal(updateconsumergroupResponse.UserMetadata, "Updated the user meta data");

// Get Created ConsumerGroup
var getConsumergroupResponse = EventHubManagementClient.ConsumerGroups.Get(resourceGroup, namespaceName, eventhubName, consumergroupName);
Assert.NotNull(getConsumergroupResponse);
Assert.Equal(getConsumergroupResponse.Name, consumergroupName);
Assert.Equal(getConsumergroupResponse.UserMetadata, updateconsumergroupResponse.UserMetadata);

// Delete Created ConsumerGroup and check for the NotFound exception
EventHubManagementClient.ConsumerGroups.Delete(resourceGroup, namespaceName, eventhubName, consumergroupName);

// Delete Created EventHub and check for the NotFound exception
EventHubManagementClient.EventHubs.Delete(resourceGroup, namespaceName, eventhubName);

// Delete namespace
EventHubManagementClient.Namespaces.Delete(resourceGroup, namespaceName);

//Subscription end
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.


namespace EventHub.Tests.ScenarioTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Microsoft.Azure.Management.EventHub;
using Microsoft.Azure.Management.EventHub.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using TestHelper;
using Xunit;
public partial class ScenarioTests
{
[Fact]
public void EventhubCreateGetUpdateDeleteAuthorizationRules_Length()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
InitializeClients(context);

var location = this.ResourceManagementClient.GetLocationFromProvider();

var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location);
if (string.IsNullOrWhiteSpace(resourceGroup))
{
resourceGroup = TestUtilities.GenerateName(EventHubManagementHelper.ResourceGroupPrefix);
this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup);
}

// Create a namespace
var namespaceName = TestUtilities.GenerateName(EventHubManagementHelper.NamespacePrefix);

var createNamespaceResponse = this.EventHubManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName,
new EHNamespace()
{
Location = location,
Sku = new Sku
{
Name = SkuName.Standard,
Tier = SkuTier.Standard
},
Tags = new Dictionary<string, string>()
{
{"tag1", "value1"},
{"tag2", "value2"}
}
});

Assert.NotNull(createNamespaceResponse);
Assert.Equal(createNamespaceResponse.Name, namespaceName);

TestUtilities.Wait(TimeSpan.FromSeconds(5));

// Get the created namespace
var getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName);
if (string.Compare(getNamespaceResponse.ProvisioningState, "Succeeded", true) != 0)
TestUtilities.Wait(TimeSpan.FromSeconds(5));

getNamespaceResponse = EventHubManagementClient.Namespaces.Get(resourceGroup, namespaceName);
Assert.NotNull(getNamespaceResponse);
Assert.Equal("Succeeded", getNamespaceResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
Assert.Equal(location, getNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase);

// Create Eventhub
var eventhubName = EventHubManagementHelper.EventHubPrefix + "thisisthenamewithmorethan53charschecktoverifytheremovlaof50charsnamelengthlimit";
var createEventhubResponse = this.EventHubManagementClient.EventHubs.CreateOrUpdate(resourceGroup, namespaceName, eventhubName,
new Eventhub() { MessageRetentionInDays = 5 });

Assert.NotNull(createEventhubResponse);
Assert.Equal(createEventhubResponse.Name, eventhubName);

// Get the created EventHub
var geteventhubResponse = EventHubManagementClient.EventHubs.Get(resourceGroup, namespaceName, eventhubName);
Assert.NotNull(geteventhubResponse);
Assert.Equal(EntityStatus.Active, geteventhubResponse.Status);
Assert.Equal(geteventhubResponse.Name, eventhubName);

// Create a EventHub AuthorizationRule
var authorizationRuleName = EventHubManagementHelper.AuthorizationRulesPrefix + "thisisthenamewithmorethan53charschecktoverifytheremovlaof50charsnamelengthlimit";
string createPrimaryKey = HttpMockServer.GetVariable("CreatePrimaryKey", EventHubManagementHelper.GenerateRandomKey());
var createAutorizationRuleParameter = new AuthorizationRule()
{
Rights = new List<string>() { AccessRights.Listen, AccessRights.Send }
};

var jsonStr = EventHubManagementHelper.ConvertObjectToJSon(createAutorizationRuleParameter);

var createEventhubAuthorizationRuleResponse = EventHubManagementClient.EventHubs.CreateOrUpdateAuthorizationRule(resourceGroup, namespaceName, eventhubName,
authorizationRuleName, createAutorizationRuleParameter);
Assert.NotNull(createEventhubAuthorizationRuleResponse);
Assert.True(createEventhubAuthorizationRuleResponse.Rights.Count == createAutorizationRuleParameter.Rights.Count);
foreach (var right in createAutorizationRuleParameter.Rights)
{
Assert.True(createEventhubAuthorizationRuleResponse.Rights.Any(r => r == right));
}

// Get created Eventhub AuthorizationRules
var getEventhubAuthorizationRulesResponse = EventHubManagementClient.EventHubs.GetAuthorizationRule(resourceGroup, namespaceName, eventhubName, authorizationRuleName);
Assert.NotNull(getEventhubAuthorizationRulesResponse);
Assert.True(getEventhubAuthorizationRulesResponse.Rights.Count == createAutorizationRuleParameter.Rights.Count);
foreach (var right in createAutorizationRuleParameter.Rights)
{
Assert.True(getEventhubAuthorizationRulesResponse.Rights.Any(r => r == right));
}

// Get all Eventhub AuthorizationRules
var getAllNamespaceAuthorizationRulesResponse = EventHubManagementClient.EventHubs.ListAuthorizationRules(resourceGroup, namespaceName, eventhubName);
Assert.NotNull(getAllNamespaceAuthorizationRulesResponse);
Assert.Equal(getAllNamespaceAuthorizationRulesResponse.Count(), 1);
Assert.True(getAllNamespaceAuthorizationRulesResponse.Any(ns => ns.Name == authorizationRuleName));

// Update Eventhub authorizationRule
string updatePrimaryKey = HttpMockServer.GetVariable("UpdatePrimaryKey", EventHubManagementHelper.GenerateRandomKey());
AuthorizationRule updateEventhubAuthorizationRuleParameter = new AuthorizationRule();
updateEventhubAuthorizationRuleParameter.Rights = new List<string>() { AccessRights.Listen };

var updateEventhubAuthorizationRuleResponse = EventHubManagementClient.EventHubs.CreateOrUpdateAuthorizationRule(resourceGroup,
namespaceName, eventhubName, authorizationRuleName, updateEventhubAuthorizationRuleParameter);

Assert.NotNull(updateEventhubAuthorizationRuleResponse);
Assert.Equal(authorizationRuleName, updateEventhubAuthorizationRuleResponse.Name);
Assert.True(updateEventhubAuthorizationRuleResponse.Rights.Count == updateEventhubAuthorizationRuleParameter.Rights.Count);
foreach (var right in updateEventhubAuthorizationRuleParameter.Rights)
{
Assert.True(updateEventhubAuthorizationRuleResponse.Rights.Any(r => r.Equals(right)));
}

// Get the updated Eventhub AuthorizationRule
var getEventhubAuthorizationRuleResponse = EventHubManagementClient.EventHubs.GetAuthorizationRule(resourceGroup, namespaceName, eventhubName,
authorizationRuleName);
Assert.NotNull(getEventhubAuthorizationRuleResponse);
Assert.Equal(authorizationRuleName, getEventhubAuthorizationRuleResponse.Name);
Assert.True(getEventhubAuthorizationRuleResponse.Rights.Count == updateEventhubAuthorizationRuleParameter.Rights.Count);
foreach (var right in updateEventhubAuthorizationRuleParameter.Rights)
{
Assert.True(getEventhubAuthorizationRuleResponse.Rights.Any(r => r.Equals(right)));
}

// Get the connectionString to the Eventhub for a Authorization rule created
var listKeysResponse = EventHubManagementClient.EventHubs.ListKeys(resourceGroup, namespaceName, eventhubName, authorizationRuleName);
Assert.NotNull(listKeysResponse);
Assert.NotNull(listKeysResponse.PrimaryConnectionString);
Assert.NotNull(listKeysResponse.SecondaryConnectionString);

//New connection string
var regenerateConnection_primary = EventHubManagementClient.EventHubs.RegenerateKeys(resourceGroup, namespaceName, eventhubName, authorizationRuleName, new RegenerateAccessKeyParameters(KeyType.PrimaryKey));
Assert.NotNull(regenerateConnection_primary);
Assert.NotEqual(listKeysResponse.PrimaryConnectionString, regenerateConnection_primary.PrimaryConnectionString);
Assert.Equal(listKeysResponse.SecondaryConnectionString, regenerateConnection_primary.SecondaryConnectionString);

var regenerateConnection_Secondary = EventHubManagementClient.EventHubs.RegenerateKeys(resourceGroup, namespaceName, eventhubName, authorizationRuleName, new RegenerateAccessKeyParameters(KeyType.SecondaryKey));
Assert.NotNull(regenerateConnection_Secondary);
Assert.NotEqual(listKeysResponse.SecondaryConnectionString, regenerateConnection_Secondary.SecondaryConnectionString);
Assert.Equal(regenerateConnection_primary.PrimaryConnectionString, regenerateConnection_Secondary.PrimaryConnectionString);

// Delete Eventhub authorizationRule
EventHubManagementClient.EventHubs.DeleteAuthorizationRule(resourceGroup, namespaceName, eventhubName, authorizationRuleName);

TestUtilities.Wait(TimeSpan.FromSeconds(5));

// Delete Eventhub and check for the NotFound exception
EventHubManagementClient.EventHubs.Delete(resourceGroup, namespaceName, eventhubName);

// Delete namespace and check for the NotFound exception
EventHubManagementClient.Namespaces.Delete(resourceGroup, namespaceName);
}
}
}
}
Loading