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();
            EventHubNamespaceResource   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
            var exception = Assert.ThrowsAsync <RequestFailedException>(async() => { await namespaceCollection.GetAsync(namespaceName); });

            Assert.AreEqual(404, exception.Status);
            Assert.IsFalse(await namespaceCollection.ExistsAsync(namespaceName));
        }
        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(true, 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(true);

            //validate if deleted successfully
            eventHubNamespace = await namespaceCollection.GetIfExistsAsync(namespaceName);

            Assert.IsNull(eventHubNamespace);
            Assert.IsFalse(await namespaceCollection.ExistsAsync(namespaceName));
        }
        public async Task GetIfExist()
        {
            #region Snippet:Managing_Namespaces_GetNamespaceIfExists
            EventHubNamespaceCollection namespaceCollection = resourceGroup.GetEventHubNamespaces();
            EventHubNamespace           eventHubNamespace   = await namespaceCollection.GetIfExistsAsync("foo");

            if (eventHubNamespace != null)
            {
                Console.WriteLine("namespace 'foo' exists");
            }
            if (await namespaceCollection.ExistsAsync("bar"))
            {
                Console.WriteLine("namespace 'bar' exists");
            }
            #endregion
        }