public static void RunSample(IAzure azure)
        {
            Region region             = Region.USEast;
            string rgName             = SdkContext.RandomResourceName("rgeh", 15);
            string namespaceName1     = SdkContext.RandomResourceName("ns", 15);
            string namespaceName2     = SdkContext.RandomResourceName("ns", 15);
            string storageAccountName = SdkContext.RandomResourceName("stg", 14);
            string eventHubName1      = SdkContext.RandomResourceName("eh", 14);
            string eventHubName2      = SdkContext.RandomResourceName("eh", 14);

            try
            {
                //============================================================
                // Create an event hub namespace
                //
                Utilities.Log("Creating a namespace");

                IEventHubNamespace namespace1 = azure.EventHubNamespaces
                                                .Define(namespaceName1)
                                                .WithRegion(Region.USEast2)
                                                .WithNewResourceGroup(rgName)
                                                .Create();

                Utilities.Print(namespace1);
                Utilities.Log("Created a namespace");

                //============================================================
                // Create an event hub in the namespace with data capture enabled, with consumer group and auth rule
                //

                ICreatable <IStorageAccount> storageAccountCreatable = azure.StorageAccounts
                                                                       .Define(storageAccountName)
                                                                       .WithRegion(Region.USEast2)
                                                                       .WithExistingResourceGroup(rgName)
                                                                       .WithSku(StorageAccountSkuType.Standard_LRS);

                Utilities.Log("Creating an event hub with data capture enabled with a consumer group and rule in it");

                IEventHub eventHub1 = azure.EventHubs
                                      .Define(eventHubName1)
                                      .WithExistingNamespace(namespace1)
                                      // Optional - configure data capture
                                      .WithNewStorageAccountForCapturedData(storageAccountCreatable, "datacpt")
                                      .WithDataCaptureEnabled()
                                      // Optional - create one consumer group in event hub
                                      .WithNewConsumerGroup("cg1", "sometadata")
                                      // Optional - create an authorization rule for event hub
                                      .WithNewListenRule("listenrule1")
                                      .Create();

                Utilities.Log("Created an event hub with data capture enabled with a consumer group and rule in it");
                Utilities.Print(eventHub1);

                //============================================================
                // Retrieve consumer groups in the event hub
                //
                Utilities.Log("Retrieving consumer groups");

                var consumerGroups = eventHub1.ListConsumerGroups();

                Utilities.Log("Retrieved consumer groups");
                foreach (IEventHubConsumerGroup group in consumerGroups)
                {
                    Utilities.Print(group);
                }

                //============================================================
                // Create another event hub in the namespace using event hub accessor in namespace accessor
                //

                Utilities.Log("Creating another event hub in the namespace");

                IEventHub eventHub2 = azure.EventHubNamespaces
                                      .EventHubs
                                      .Define(eventHubName2)
                                      .WithExistingNamespace(namespace1)
                                      .Create();

                Utilities.Log("Created second event hub");
                Utilities.Print(eventHub2);

                //============================================================
                // Create a consumer group in the event hub using consumer group accessor in event hub accessor
                //

                Utilities.Log("Creating a consumer group in the second event hub");

                IEventHubConsumerGroup consumerGroup2 = azure.EventHubNamespaces
                                                        .EventHubs
                                                        .ConsumerGroups
                                                        .Define("cg2")
                                                        .WithExistingEventHub(eventHub2)
                                                        // Optional
                                                        .WithUserMetadata("sometadata")
                                                        .Create();

                Utilities.Log("Created a consumer group in the second event hub");
                Utilities.Print(consumerGroup2);

                //============================================================
                // Retrieve consumer groups in the event hub
                //
                Utilities.Log("Retrieving consumer groups in the second event hub");

                consumerGroups = eventHub2.ListConsumerGroups();

                Utilities.Log("Retrieved consumer groups in the seoond event hub");
                foreach (IEventHubConsumerGroup group in consumerGroups)
                {
                    Utilities.Print(group);
                }

                //============================================================
                // Create an event hub namespace with event hub
                //

                Utilities.Log("Creating an event hub namespace along with event hub");

                IEventHubNamespace namespace2 = azure.EventHubNamespaces
                                                .Define(namespaceName2)
                                                .WithRegion(Region.USEast2)
                                                .WithExistingResourceGroup(rgName)
                                                .WithNewEventHub(eventHubName2)
                                                .Create();

                Utilities.Log("Created an event hub namespace along with event hub");
                Utilities.Print(namespace2);
                foreach (IEventHub eh in namespace2.ListEventHubs())
                {
                    Utilities.Print(eh);
                }
            }
            finally
            {
                try
                {
                    azure.ResourceGroups.DeleteByName(rgName);
                }
                catch (NullReferenceException)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
                catch (Exception ex)
                {
                    Utilities.Log(ex);
                }
            }
        }
        public void CanManageConusmerGroups()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                var region        = Region.USEast;
                var groupName     = TestUtilities.GenerateName("rgns");
                var namespaceName = TestUtilities.GenerateName("ns111");
                var eventHubName  = TestUtilities.GenerateName("eh");

                var azure = TestHelper.CreateRollupClient();
                try
                {
                    var namespaceCreatable = azure.EventHubNamespaces
                                             .Define(namespaceName)
                                             .WithRegion(region)
                                             .WithNewResourceGroup(groupName);

                    IEventHub eventHub = azure.EventHubs
                                         .Define(eventHubName)
                                         .WithNewNamespace(namespaceCreatable)
                                         .WithNewConsumerGroup("grp1")
                                         .WithNewConsumerGroup("grp2", "metadata111")
                                         .Create();

                    Assert.NotNull(eventHub);
                    Assert.NotNull(eventHub.Inner);

                    var cGroups          = eventHub.ListConsumerGroups();
                    HashSet <string> set = new HashSet <string>();
                    foreach (IEventHubConsumerGroup grp in cGroups)
                    {
                        set.Add(grp.Name);
                    }
                    Assert.Contains("grp1", set);
                    Assert.Contains("grp2", set);

                    cGroups = azure.EventHubs
                              .ConsumerGroups
                              .ListByEventHub(eventHub.NamespaceResourceGroupName,
                                              eventHub.NamespaceName, eventHub.Name);

                    set.Clear();
                    foreach (IEventHubConsumerGroup rule in cGroups)
                    {
                        set.Add(rule.Name);
                    }
                    Assert.Contains("grp1", set);
                    Assert.Contains("grp2", set);

                    azure.EventHubs
                    .ConsumerGroups
                    .Define("grp3")
                    .WithExistingEventHubId(eventHub.Id)
                    .WithUserMetadata("metadata222")
                    .Create();

                    cGroups = eventHub.ListConsumerGroups();
                    set.Clear();
                    foreach (IEventHubConsumerGroup grp in cGroups)
                    {
                        set.Add(grp.Name);
                    }
                    Assert.Contains("grp1", set);
                    Assert.Contains("grp2", set);
                    Assert.Contains("grp3", set);
                }
                finally
                {
                    try
                    {
                        azure.ResourceGroups.DeleteByName(groupName);
                    }
                    catch
                    { }
                }
            }
        }