Ejemplo n.º 1
0
        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 Delete()
        {
            #region Snippet:Managing_Namespaces_DeleteNamespace
            EventHubNamespaceCollection namespaceCollection = resourceGroup.GetEventHubNamespaces();
            EventHubNamespace           eventHubNamespace   = await namespaceCollection.GetAsync("myNamespace");

            await eventHubNamespace.DeleteAsync(true);

            #endregion
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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);
        }