Ejemplo n.º 1
0
 /// <summary>
 /// Update an event subscription for a topic.
 /// </summary>
 /// <remarks>
 /// Update an existing event subscription for a topic.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the user's subscription.
 /// </param>
 /// <param name='topicName'>
 /// Name of the domain.
 /// </param>
 /// <param name='eventSubscriptionName'>
 /// Name of the event subscription to be updated.
 /// </param>
 /// <param name='eventSubscriptionUpdateParameters'>
 /// Updated event subscription information.
 /// </param>
 public static EventSubscription BeginUpdate(this ITopicEventSubscriptionsOperations operations, string resourceGroupName, string topicName, string eventSubscriptionName, EventSubscriptionUpdateParameters eventSubscriptionUpdateParameters)
 {
     return(operations.BeginUpdateAsync(resourceGroupName, topicName, eventSubscriptionName, eventSubscriptionUpdateParameters).GetAwaiter().GetResult());
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Update an event subscription for a topic.
 /// </summary>
 /// <remarks>
 /// Update an existing event subscription for a topic.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the user's subscription.
 /// </param>
 /// <param name='topicName'>
 /// Name of the domain.
 /// </param>
 /// <param name='eventSubscriptionName'>
 /// Name of the event subscription to be updated.
 /// </param>
 /// <param name='eventSubscriptionUpdateParameters'>
 /// Updated event subscription information.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <EventSubscription> BeginUpdateAsync(this ITopicEventSubscriptionsOperations operations, string resourceGroupName, string topicName, string eventSubscriptionName, EventSubscriptionUpdateParameters eventSubscriptionUpdateParameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, topicName, eventSubscriptionName, eventSubscriptionUpdateParameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Ejemplo n.º 3
0
        public void EventSubscriptionToCustomTopicCreateGetUpdateDeleteWithEventDeliverySchema()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                this.InitializeClients(context);

                var location = this.ResourceManagementClient.GetLocationFromProvider();

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

                var topicName = TestUtilities.GenerateName(EventGridManagementHelper.TopicPrefix);

                var createTopicResponse = this.EventGridManagementClient.Topics.CreateOrUpdateAsync(resourceGroup, topicName,
                                                                                                    new Topic()
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "tag1", "value1" },
                        { "tag2", "value2" }
                    }
                }).Result;

                Assert.NotNull(createTopicResponse);
                Assert.Equal(createTopicResponse.Name, topicName);

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

                // Get the created topic
                var getTopicResponse = EventGridManagementClient.Topics.Get(resourceGroup, topicName);
                if (string.Compare(getTopicResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                getTopicResponse = EventGridManagementClient.Topics.Get(resourceGroup, topicName);
                Assert.NotNull(getTopicResponse);
                Assert.Equal("Succeeded", getTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal(location, getTopicResponse.Location, StringComparer.CurrentCultureIgnoreCase);

                // Create an event subscription to this topic
                var    eventSubscriptionName = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix);
                string scope = $"/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/{resourceGroup}/providers/Microsoft.EventGrid/topics/{topicName}";

                EventSubscription eventSubscription = new EventSubscription()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl                            = AzureFunctionEndpointUrl,
                        MaxEventsPerBatch                      = 1000,
                        PreferredBatchSizeInKilobytes          = 1000,
                        AzureActiveDirectoryTenantId           = SampleAzureActiveDirectoryTenantId,
                        AzureActiveDirectoryApplicationIdOrUri = SampleAzureActiveDirectoryApplicationIdOrUri,
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes     = null,
                        IsSubjectCaseSensitive = true,
                        SubjectBeginsWith      = "TestPrefix",
                        SubjectEndsWith        = "TestSuffix"
                    },
                    Labels = new List <string>()
                    {
                        "TestLabel1",
                        "TestLabel2"
                    },
                };

                var eventSubscriptionResponse = this.EventGridManagementClient.EventSubscriptions.CreateOrUpdateAsync(scope, eventSubscriptionName, eventSubscription).Result;
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal(eventSubscriptionResponse.Name, eventSubscriptionName);

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

                // Get the created event subscription
                eventSubscriptionResponse = EventGridManagementClient.EventSubscriptions.Get(scope, eventSubscriptionName);
                if (string.Compare(eventSubscriptionResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                eventSubscriptionResponse = EventGridManagementClient.EventSubscriptions.Get(scope, eventSubscriptionName);
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal("Succeeded", eventSubscriptionResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestPrefix", eventSubscriptionResponse.Filter.SubjectBeginsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestSuffix", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);

                // Update the event subscription
                var eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl                   = AzureFunctionEndpointUrl,
                        MaxEventsPerBatch             = 4400,
                        PreferredBatchSizeInKilobytes = 900,
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes = new List <string>()
                        {
                            "Event1",
                            "Event2"
                        },
                        SubjectEndsWith   = ".jpg",
                        SubjectBeginsWith = "TestPrefix"
                    },
                    Labels = new List <string>()
                    {
                        "UpdatedLabel1",
                        "UpdatedLabel2",
                    }
                };

                eventSubscriptionResponse = this.eventGridManagementClient.EventSubscriptions.UpdateAsync(scope, eventSubscriptionName, eventSubscriptionUpdateParameters).Result;
                Assert.Equal(".jpg", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Contains(eventSubscriptionResponse.Labels, label => label == "UpdatedLabel1");

                // List event subscriptions
                var eventSubscriptionsPage = this.EventGridManagementClient.EventSubscriptions.ListRegionalByResourceGroupAsync(resourceGroup, location).Result;
                List <EventSubscription> eventSubscriptionsList = new List <EventSubscription>();
                string nextLink = null;

                if (eventSubscriptionsPage != null)
                {
                    eventSubscriptionsList.AddRange(eventSubscriptionsPage);
                    nextLink = eventSubscriptionsPage.NextPageLink;
                    while (nextLink != null)
                    {
                        eventSubscriptionsPage = this.EventGridManagementClient.EventSubscriptions.ListRegionalByResourceGroupNextAsync(nextLink).Result;
                        eventSubscriptionsList.AddRange(eventSubscriptionsPage);
                        nextLink = eventSubscriptionsPage.NextPageLink;
                    }
                }

                Assert.Contains(eventSubscriptionsList, es => es.Name == eventSubscriptionName);

                // Delete the event subscription
                EventGridManagementClient.EventSubscriptions.DeleteAsync(scope, eventSubscriptionName).Wait();

                // Delete the topic
                EventGridManagementClient.Topics.DeleteAsync(resourceGroup, topicName).Wait();
            }
        }
 /// <summary>
 /// Update an event subscription for a domain.
 /// </summary>
 /// <remarks>
 /// Update an existing event subscription for a topic.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the user's subscription.
 /// </param>
 /// <param name='domainName'>
 /// Name of the domain.
 /// </param>
 /// <param name='eventSubscriptionName'>
 /// Name of the event subscription to be updated.
 /// </param>
 /// <param name='eventSubscriptionUpdateParameters'>
 /// Updated event subscription information.
 /// </param>
 public static EventSubscription Update(this IDomainEventSubscriptionsOperations operations, string resourceGroupName, string domainName, string eventSubscriptionName, EventSubscriptionUpdateParameters eventSubscriptionUpdateParameters)
 {
     return(operations.UpdateAsync(resourceGroupName, domainName, eventSubscriptionName, eventSubscriptionUpdateParameters).GetAwaiter().GetResult());
 }
Ejemplo n.º 5
0
        public EventSubscription UpdateEventSubscription(
            string scope,
            string eventSubscriptionName,
            string endpoint,
            string endpointType,
            string subjectBeginsWith,
            string subjectEndsWith,
            bool?isSubjectCaseSensitive,
            string[] includedEventTypes,
            string[] labels)
        {
            EventSubscriptionUpdateParameters eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters();
            const string WebHookEventSubscriptionDestination  = "webhook";
            const string EventHubEventSubscriptionDestination = "eventhub";

            if (!string.IsNullOrEmpty(endpoint))
            {
                // An endpoint was specified, so it needs to be included as part of the update parameters
                // Defaulting to webhook if endpoint type was not specified
                if (string.IsNullOrEmpty(endpointType) ||
                    string.Equals(endpointType, WebHookEventSubscriptionDestination, StringComparison.OrdinalIgnoreCase))
                {
                    eventSubscriptionUpdateParameters.Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = endpoint
                    };
                }
                else if (string.Equals(endpointType, EventHubEventSubscriptionDestination, StringComparison.OrdinalIgnoreCase))
                {
                    eventSubscriptionUpdateParameters.Destination = new EventHubEventSubscriptionDestination()
                    {
                        ResourceId = endpoint
                    };
                }
                else
                {
                    throw new ArgumentNullException(nameof(endpointType), "EndpointType should be WebHook or EventHub");
                }
            }

            if (includedEventTypes == null)
            {
                includedEventTypes    = new string[1];
                includedEventTypes[0] = "All";
            }

            eventSubscriptionUpdateParameters.Filter = new EventSubscriptionFilter()
            {
                SubjectBeginsWith      = subjectBeginsWith,
                SubjectEndsWith        = subjectEndsWith,
                IsSubjectCaseSensitive = isSubjectCaseSensitive,
                IncludedEventTypes     = new List <string>(includedEventTypes)
            };

            if (labels != null)
            {
                eventSubscriptionUpdateParameters.Labels = new List <string>(labels);
            }

            return(this.Client.EventSubscriptions.Update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters));
        }
Ejemplo n.º 6
0
        public void DomainEventSubscriptionCreateGetUpdateDelete()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                this.InitializeClients(context);

                var location = this.ResourceManagementClient.GetLocationFromProvider();

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

                var domainName      = TestUtilities.GenerateName(EventGridManagementHelper.DomainPrefix);
                var domainTopicName = TestUtilities.GenerateName(EventGridManagementHelper.DomainTopicPrefix);

                var createDomainResponse = this.EventGridManagementClient.Domains.CreateOrUpdateAsync(resourceGroup, domainName,
                                                                                                      new Domain()
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "tag1", "value1" },
                        { "tag2", "value2" }
                    }
                }).Result;

                Assert.NotNull(createDomainResponse);
                Assert.Equal(createDomainResponse.Name, domainName);

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

                // Get the created domain
                var getDomainResponse = EventGridManagementClient.Domains.Get(resourceGroup, domainName);
                if (string.Compare(getDomainResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                getDomainResponse = EventGridManagementClient.Domains.Get(resourceGroup, domainName);
                Assert.NotNull(getDomainResponse);
                Assert.Equal("Succeeded", getDomainResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal(location, getDomainResponse.Location, StringComparer.CurrentCultureIgnoreCase);

                // Create an event subscription to this domain
                var eventSubscriptionName           = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix);
                EventSubscription eventSubscription = new EventSubscription()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = AzureFunctionEndpointUrl
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes     = null,
                        IsSubjectCaseSensitive = true,
                        SubjectBeginsWith      = "TestPrefix",
                        SubjectEndsWith        = "TestSuffix"
                    },
                    Labels = new List <string>()
                    {
                        "TestLabel1",
                        "TestLabel2"
                    }
                };

                var eventSubscriptionResponse = EventGridManagementClient.DomainEventSubscriptions.CreateOrUpdateAsync(resourceGroup, domainName, eventSubscriptionName, eventSubscription).Result;
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal(eventSubscriptionResponse.Name, eventSubscriptionName);

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

                // Get the created event subscription
                eventSubscriptionResponse = EventGridManagementClient.DomainEventSubscriptions.Get(resourceGroup, domainName, eventSubscriptionName);
                if (string.Compare(eventSubscriptionResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                eventSubscriptionResponse = EventGridManagementClient.DomainEventSubscriptions.Get(resourceGroup, domainName, eventSubscriptionName);
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal("Succeeded", eventSubscriptionResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestPrefix", eventSubscriptionResponse.Filter.SubjectBeginsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestSuffix", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);

                // Update the event subscription
                var eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = AzureFunctionEndpointUrl,
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes = new List <string>()
                        {
                            "Event1",
                            "Event2"
                        },
                        SubjectEndsWith   = ".jpg",
                        SubjectBeginsWith = "TestPrefix"
                    },
                    Labels = new List <string>()
                    {
                        "UpdatedLabel1",
                        "UpdatedLabel2",
                    }
                };

                eventSubscriptionResponse = EventGridManagementClient.DomainEventSubscriptions.UpdateAsync(resourceGroup, domainName, eventSubscriptionName, eventSubscriptionUpdateParameters).Result;
                Assert.Equal(".jpg", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Contains(eventSubscriptionResponse.Labels, label => label == "UpdatedLabel1");

                // Test getting full URL and delivery attributes
                var fullUrlResponse = EventGridManagementClient.DomainEventSubscriptions.GetFullUrlAsync(resourceGroup, domainName, eventSubscriptionName).Result;
                Assert.NotNull(fullUrlResponse);
                Assert.NotNull(fullUrlResponse.EndpointUrl);

                var deliveryAttributesResponse = EventGridManagementClient.DomainEventSubscriptions.GetDeliveryAttributesAsync(resourceGroup, domainName, eventSubscriptionName).Result;
                Assert.NotNull(deliveryAttributesResponse);

                // List domain event subscriptions
                var listDomainEventSubscriptionsResponse = this.EventGridManagementClient.DomainEventSubscriptions.List(resourceGroup, domainName);
                Assert.NotNull(listDomainEventSubscriptionsResponse);
                Assert.True(listDomainEventSubscriptionsResponse.IsAny());

                // Delete the event subscription
                EventGridManagementClient.DomainEventSubscriptions.DeleteAsync(resourceGroup, domainName, eventSubscriptionName).Wait();

                // Create an event subscription to a domain topic scope
                eventSubscriptionName = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix);
                eventSubscription     = new EventSubscription()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = AzureFunctionEndpointUrl
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes     = null,
                        IsSubjectCaseSensitive = true,
                        SubjectBeginsWith      = "TestPrefix",
                        SubjectEndsWith        = "TestSuffix"
                    },
                    Labels = new List <string>()
                    {
                        "TestLabel1",
                        "TestLabel2"
                    }
                };

                eventSubscriptionResponse = EventGridManagementClient.DomainTopicEventSubscriptions.CreateOrUpdateAsync(resourceGroup, domainName, domainTopicName, eventSubscriptionName, eventSubscription).Result;
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal(eventSubscriptionResponse.Name, eventSubscriptionName);

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

                // Get the created event subscription
                eventSubscriptionResponse = EventGridManagementClient.DomainTopicEventSubscriptions.Get(resourceGroup, domainName, domainTopicName, eventSubscriptionName);
                if (string.Compare(eventSubscriptionResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                eventSubscriptionResponse = EventGridManagementClient.DomainTopicEventSubscriptions.Get(resourceGroup, domainName, domainTopicName, eventSubscriptionName);
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal("Succeeded", eventSubscriptionResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestPrefix", eventSubscriptionResponse.Filter.SubjectBeginsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestSuffix", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);

                // List domain topic event subscriptions
                var listDomainTopicEventSubscriptionsResponse = this.EventGridManagementClient.DomainTopicEventSubscriptions.List(resourceGroup, domainName, domainTopicName);
                Assert.NotNull(listDomainTopicEventSubscriptionsResponse);
                Assert.True(listDomainTopicEventSubscriptionsResponse.IsAny());

                // Test getting full URL and delivery attributes
                fullUrlResponse = EventGridManagementClient.DomainTopicEventSubscriptions.GetFullUrlAsync(resourceGroup, domainName, domainTopicName, eventSubscriptionName).Result;
                Assert.NotNull(fullUrlResponse);
                Assert.NotNull(fullUrlResponse.EndpointUrl);

                deliveryAttributesResponse = EventGridManagementClient.DomainTopicEventSubscriptions.GetDeliveryAttributesAsync(resourceGroup, domainName, domainTopicName, eventSubscriptionName).Result;
                Assert.NotNull(deliveryAttributesResponse);

                // Delete the domain topic event subscription
                EventGridManagementClient.DomainTopicEventSubscriptions.DeleteAsync(resourceGroup, domainName, domainTopicName, eventSubscriptionName).Wait();

                // Delete the Domain
                EventGridManagementClient.Domains.DeleteAsync(resourceGroup, domainName).Wait();
            }
        }
        public void PartnerCreateGetUpdateDelete()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                this.InitializeClients(context);

                var location = this.ResourceManagementClient.GetLocationFromProvider();

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

                bool partnerRegistrationCreated = false;
                bool partnerNamespaceCreated    = false;
                bool eventChannelCreated        = false;
                bool partnerTopicCreated        = false;
                bool eventSubscriptionCreated   = false;
                var  partnerNamespaceName       = TestUtilities.GenerateName(EventGridManagementHelper.PartnerNamespacePrefix);
                var  eventChannelName           = TestUtilities.GenerateName(EventGridManagementHelper.EventChannelPrefix);
                var  partnerTopicName           = TestUtilities.GenerateName(EventGridManagementHelper.PartnerTopicPrefix);
                var  eventSubscriptionName      = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix);

                var partnerRegistrationName = TestUtilities.GenerateName(EventGridManagementHelper.PartnerRegistrationPrefix);

                // Temporarily commenting this out as this is not yet enabled for the new API version
                // var operationsResponse = this.EventGridManagementClient.Operations.List();

                var originalTagsDictionary = new Dictionary <string, string>()
                {
                    { "originalTag1", "originalValue1" },
                    { "originalTag2", "originalValue2" }
                };

                Guid   uniqueId = Guid.NewGuid();
                string subId    = "5b4b650e-28b9-4790-b3ab-ddbd88d727c4";

                try
                {
                    PartnerRegistration partnerRegistration = new PartnerRegistration()
                    {
                        Location                       = "global",
                        Tags                           = originalTagsDictionary,
                        LogoUri                        = "https://www.contoso.com/logo.png",
                        SetupUri                       = "https://www.contoso.com/setup.html",
                        PartnerName                    = "Contoso",
                        PartnerResourceTypeName        = $"Accounts.{uniqueId}",
                        PartnerResourceTypeDisplayName = $"DisplayName Text -- {uniqueId}",
                        PartnerResourceTypeDescription = $"Description Text -- {uniqueId}",
                        AuthorizedAzureSubscriptionIds = new List <string>
                        {
                            subId
                        },
                    };

                    var createPartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.CreateOrUpdateAsync(resourceGroup, partnerRegistrationName, partnerRegistration).Result;

                    partnerRegistrationCreated = true;

                    Assert.NotNull(createPartnerRegistrationResponse);
                    Assert.Equal(createPartnerRegistrationResponse.Name, partnerRegistrationName);

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

                    // Get the created partnerRegistration
                    var getPartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.Get(resourceGroup, partnerRegistrationName);
                    if (string.Compare(getPartnerRegistrationResponse.ProvisioningState, "Succeeded", true) != 0)
                    {
                        TestUtilities.Wait(TimeSpan.FromSeconds(5));
                    }

                    getPartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.Get(resourceGroup, partnerRegistrationName);
                    Assert.NotNull(getPartnerRegistrationResponse);
                    Assert.Equal("Succeeded", getPartnerRegistrationResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Equal("global", getPartnerRegistrationResponse.Location, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Contains(getPartnerRegistrationResponse.Tags, tag => tag.Key == "originalTag1");

                    // Get all partnerRegistrations created within a resourceGroup
                    IPage <PartnerRegistration> partnerRegistrationsInResourceGroupPage = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupAsync(resourceGroup).Result;
                    var partnerRegistrationsInResourceGroupList = new List <PartnerRegistration>();
                    if (partnerRegistrationsInResourceGroupPage.Any())
                    {
                        partnerRegistrationsInResourceGroupList.AddRange(partnerRegistrationsInResourceGroupPage);
                        var nextLink = partnerRegistrationsInResourceGroupPage.NextPageLink;
                        while (nextLink != null)
                        {
                            partnerRegistrationsInResourceGroupPage = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupNextAsync(nextLink).Result;
                            partnerRegistrationsInResourceGroupList.AddRange(partnerRegistrationsInResourceGroupPage);
                            nextLink = partnerRegistrationsInResourceGroupPage.NextPageLink;
                        }
                    }

                    Assert.NotNull(partnerRegistrationsInResourceGroupList);
                    Assert.True(partnerRegistrationsInResourceGroupList.Count() >= 1);
                    Assert.Contains(partnerRegistrationsInResourceGroupList, t => t.Name == partnerRegistrationName);
                    Assert.True(partnerRegistrationsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup)));

                    IPage <PartnerRegistration> partnerRegistrationsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupAsync(resourceGroup, null, 5).Result;
                    var partnerRegistrationsInResourceGroupListWithTop = new List <PartnerRegistration>();
                    if (partnerRegistrationsInResourceGroupPageWithTop.Any())
                    {
                        partnerRegistrationsInResourceGroupListWithTop.AddRange(partnerRegistrationsInResourceGroupPageWithTop);
                        var nextLink = partnerRegistrationsInResourceGroupPageWithTop.NextPageLink;
                        while (nextLink != null)
                        {
                            partnerRegistrationsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupNextAsync(nextLink).Result;
                            partnerRegistrationsInResourceGroupListWithTop.AddRange(partnerRegistrationsInResourceGroupPageWithTop);
                            nextLink = partnerRegistrationsInResourceGroupPageWithTop.NextPageLink;
                        }
                    }

                    Assert.NotNull(partnerRegistrationsInResourceGroupListWithTop);
                    Assert.True(partnerRegistrationsInResourceGroupListWithTop.Count() >= 1);
                    Assert.Contains(partnerRegistrationsInResourceGroupListWithTop, t => t.Name == partnerRegistrationName);
                    Assert.True(partnerRegistrationsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup)));

                    // Get all partnerRegistrations created within the subscription irrespective of the resourceGroup
                    IPage <PartnerRegistration> partnerRegistrationsInAzureSubscription = this.EventGridManagementClient.PartnerRegistrations.ListBySubscriptionAsync(null, 100).Result;
                    var partnerRegistrationsInAzureSubscriptionList = new List <PartnerRegistration>();
                    if (partnerRegistrationsInAzureSubscription.Any())
                    {
                        partnerRegistrationsInAzureSubscriptionList.AddRange(partnerRegistrationsInAzureSubscription);
                        var nextLink = partnerRegistrationsInAzureSubscription.NextPageLink;
                        while (nextLink != null)
                        {
                            try
                            {
                                partnerRegistrationsInAzureSubscription = this.EventGridManagementClient.PartnerRegistrations.ListBySubscriptionNextAsync(nextLink).Result;
                                partnerRegistrationsInAzureSubscriptionList.AddRange(partnerRegistrationsInAzureSubscription);
                                nextLink = partnerRegistrationsInAzureSubscription.NextPageLink;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                                break;
                            }
                        }
                    }

                    Assert.NotNull(partnerRegistrationsInAzureSubscriptionList);
                    Assert.True(partnerRegistrationsInAzureSubscriptionList.Count() >= 1);
                    Assert.Contains(partnerRegistrationsInAzureSubscriptionList, t => t.Name == partnerRegistrationName);

                    var replacePartnerRegistrationTagsDictionary = new Dictionary <string, string>()
                    {
                        { "replacedTag1", "replacedValue1" },
                        { "replacedTag2", "replacedValue2" }
                    };

                    // Replace the partnerRegistration
                    partnerRegistration.Tags = replacePartnerRegistrationTagsDictionary;
                    var replacePartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.CreateOrUpdateAsync(resourceGroup, partnerRegistrationName, partnerRegistration).Result;

                    Assert.Contains(replacePartnerRegistrationResponse.Tags, tag => tag.Key == "replacedTag1");
                    Assert.DoesNotContain(replacePartnerRegistrationResponse.Tags, tag => tag.Key == "originalTag1");

                    // Update the partnerRegistration with tags
                    //////PartnerRegistrationUpdateParameters partnerRegistrationUpdateParameters = new PartnerRegistrationUpdateParameters();
                    //////partnerRegistrationUpdateParameters.Tags = new Dictionary<string, string>()
                    //////{
                    //////    { "updatedTag1", "updatedValue1" },
                    //////    { "updatedTag2", "updatedValue2" }
                    //////};

                    //////var updatePartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.UpdateAsync(resourceGroup, partnerRegistrationName, partnerRegistrationUpdateParameters).Result;
                    //////Assert.Contains(updatePartnerRegistrationResponse.Tags, tag => tag.Key == "updatedTag1");
                    //////Assert.DoesNotContain(updatePartnerRegistrationResponse.Tags, tag => tag.Key == "replacedTag1");

                    // Partner namespace operations

                    var originalNamespaceTagsDictionary = new Dictionary <string, string>()
                    {
                        { "originalTag111", "originalValue111" },
                        { "originalTag222", "originalValue222" }
                    };

                    PartnerNamespace partnerNamespace = new PartnerNamespace()
                    {
                        Location = location,
                        Tags     = originalNamespaceTagsDictionary,
                        PartnerRegistrationFullyQualifiedId = getPartnerRegistrationResponse.Id
                    };

                    var createPartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.CreateOrUpdateAsync(resourceGroup, partnerNamespaceName, partnerNamespace).Result;
                    partnerNamespaceCreated = true;

                    Assert.NotNull(createPartnerNamespaceResponse);
                    Assert.Equal(createPartnerNamespaceResponse.Name, partnerNamespaceName);

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

                    // Get the created partnerNamespace
                    var getPartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.Get(resourceGroup, partnerNamespaceName);
                    if (string.Compare(getPartnerNamespaceResponse.ProvisioningState, "Succeeded", true) != 0)
                    {
                        TestUtilities.Wait(TimeSpan.FromSeconds(5));
                    }

                    getPartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.Get(resourceGroup, partnerNamespaceName);
                    Assert.NotNull(getPartnerNamespaceResponse);
                    Assert.Equal("Succeeded", getPartnerNamespaceResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Equal(location, getPartnerNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Contains(getPartnerNamespaceResponse.Tags, tag => tag.Key == "originalTag111");

                    // Get all partnerNamespaces created within a resourceGroup
                    IPage <PartnerNamespace> partnerNamespacesInResourceGroupPage = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupAsync(resourceGroup).Result;
                    var partnerNamespacesInResourceGroupList = new List <PartnerNamespace>();
                    if (partnerNamespacesInResourceGroupPage.Any())
                    {
                        partnerNamespacesInResourceGroupList.AddRange(partnerNamespacesInResourceGroupPage);
                        var nextLink = partnerNamespacesInResourceGroupPage.NextPageLink;
                        while (nextLink != null)
                        {
                            partnerNamespacesInResourceGroupPage = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupNextAsync(nextLink).Result;
                            partnerNamespacesInResourceGroupList.AddRange(partnerNamespacesInResourceGroupPage);
                            nextLink = partnerNamespacesInResourceGroupPage.NextPageLink;
                        }
                    }

                    Assert.NotNull(partnerNamespacesInResourceGroupList);
                    Assert.True(partnerNamespacesInResourceGroupList.Count() >= 1);
                    Assert.Contains(partnerNamespacesInResourceGroupList, t => t.Name == partnerNamespaceName);
                    Assert.True(partnerNamespacesInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup)));

                    IPage <PartnerNamespace> partnerNamespacesInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupAsync(resourceGroup, null, 5).Result;
                    var partnerNamespacesInResourceGroupListWithTop = new List <PartnerNamespace>();
                    if (partnerNamespacesInResourceGroupPageWithTop.Any())
                    {
                        partnerNamespacesInResourceGroupListWithTop.AddRange(partnerNamespacesInResourceGroupPageWithTop);
                        var nextLink = partnerNamespacesInResourceGroupPageWithTop.NextPageLink;
                        while (nextLink != null)
                        {
                            partnerNamespacesInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupNextAsync(nextLink).Result;
                            partnerNamespacesInResourceGroupListWithTop.AddRange(partnerNamespacesInResourceGroupPageWithTop);
                            nextLink = partnerNamespacesInResourceGroupPageWithTop.NextPageLink;
                        }
                    }

                    Assert.NotNull(partnerNamespacesInResourceGroupListWithTop);
                    Assert.True(partnerNamespacesInResourceGroupListWithTop.Count() >= 1);
                    Assert.Contains(partnerNamespacesInResourceGroupListWithTop, t => t.Name == partnerNamespaceName);
                    Assert.True(partnerNamespacesInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup)));

                    // Get all partnerNamespaces created within the subscription irrespective of the resourceGroup
                    IPage <PartnerNamespace> partnerNamespacesInAzureSubscription = this.EventGridManagementClient.PartnerNamespaces.ListBySubscriptionAsync(null, 100).Result;
                    var partnerNamespacesInAzureSubscriptionList = new List <PartnerNamespace>();
                    if (partnerNamespacesInAzureSubscription.Any())
                    {
                        partnerNamespacesInAzureSubscriptionList.AddRange(partnerNamespacesInAzureSubscription);
                        var nextLink = partnerNamespacesInAzureSubscription.NextPageLink;
                        while (nextLink != null)
                        {
                            try
                            {
                                partnerNamespacesInAzureSubscription = this.EventGridManagementClient.PartnerNamespaces.ListBySubscriptionNextAsync(nextLink).Result;
                                partnerNamespacesInAzureSubscriptionList.AddRange(partnerNamespacesInAzureSubscription);
                                nextLink = partnerNamespacesInAzureSubscription.NextPageLink;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                                break;
                            }
                        }
                    }

                    Assert.NotNull(partnerNamespacesInAzureSubscriptionList);
                    Assert.True(partnerNamespacesInAzureSubscriptionList.Count() >= 1);
                    Assert.Contains(partnerNamespacesInAzureSubscriptionList, t => t.Name == partnerNamespaceName);

                    var replacePartnerNamespaceTagsDictionary = new Dictionary <string, string>()
                    {
                        { "replacedTag111", "replacedValue111" },
                        { "replacedTag222", "replacedValue222" }
                    };

                    // Replace the partnerNamespace
                    partnerNamespace.Tags = replacePartnerNamespaceTagsDictionary;
                    var replacePartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.CreateOrUpdateAsync(resourceGroup, partnerNamespaceName, partnerNamespace).Result;

                    Assert.Contains(replacePartnerNamespaceResponse.Tags, tag => tag.Key == "replacedTag111");
                    Assert.DoesNotContain(replacePartnerNamespaceResponse.Tags, tag => tag.Key == "originalTag111");

                    // EventChannel/PartnerTopic operations
                    var originalPartnerTopicTagsDictionary = new Dictionary <string, string>()
                    {
                        { "originalTag11111", "originalValue11111" },
                        { "originalTag22222", "originalValue22222" }
                    };

                    EventChannel eventChannel = new EventChannel()
                    {
                        Source = new EventChannelSource
                        {
                            Source = $"Accounts.User.{uniqueId}",
                        },
                        Destination = new EventChannelDestination
                        {
                            AzureSubscriptionId = subId,
                            ResourceGroup       = resourceGroup,
                            PartnerTopicName    = partnerTopicName
                        },
                    };

                    var createEventChannelResponse = this.EventGridManagementClient.EventChannels.CreateOrUpdateAsync(resourceGroup, partnerNamespaceName, eventChannelName, eventChannel).Result;
                    eventChannelCreated = true;
                    partnerTopicCreated = true;

                    Assert.NotNull(createEventChannelResponse);
                    Assert.Equal(createEventChannelResponse.Name, eventChannelName);

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

                    // Get the created eventChannel
                    var getEventChannelResponse = this.EventGridManagementClient.EventChannels.Get(resourceGroup, partnerNamespaceName, eventChannelName);
                    if (string.Compare(getEventChannelResponse.ProvisioningState, "Succeeded", true) != 0)
                    {
                        TestUtilities.Wait(TimeSpan.FromSeconds(5));
                    }

                    getEventChannelResponse = this.EventGridManagementClient.EventChannels.Get(resourceGroup, partnerNamespaceName, eventChannelName);
                    Assert.NotNull(getEventChannelResponse);
                    Assert.Equal("Succeeded", getEventChannelResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);

                    // Get all eventChannels created within a partnerNamespace
                    IPage <EventChannel> eventChannelsInPartnerNamespacePage = this.EventGridManagementClient.EventChannels.ListByPartnerNamespaceAsync(resourceGroup, partnerNamespaceName).Result;
                    var eventChannelsInPartnerNamespaceList = new List <EventChannel>();
                    if (eventChannelsInPartnerNamespacePage.Any())
                    {
                        eventChannelsInPartnerNamespaceList.AddRange(eventChannelsInPartnerNamespacePage);
                        var nextLink = eventChannelsInPartnerNamespacePage.NextPageLink;
                        while (nextLink != null)
                        {
                            eventChannelsInPartnerNamespacePage = this.EventGridManagementClient.EventChannels.ListByPartnerNamespaceNextAsync(nextLink).Result;
                            eventChannelsInPartnerNamespaceList.AddRange(eventChannelsInPartnerNamespacePage);
                            nextLink = eventChannelsInPartnerNamespacePage.NextPageLink;
                        }
                    }

                    Assert.NotNull(eventChannelsInPartnerNamespaceList);
                    Assert.True(eventChannelsInPartnerNamespaceList.Count() >= 1);
                    Assert.Contains(eventChannelsInPartnerNamespaceList, t => t.Name == eventChannelName);
                    Assert.True(eventChannelsInPartnerNamespaceList.All(ns => ns.Id.Contains(resourceGroup)));

                    // Partner topic operations

                    // Get the created partnerTopic
                    var getPartnerTopicResponse = this.EventGridManagementClient.PartnerTopics.Get(resourceGroup, partnerTopicName);
                    if (string.Compare(getPartnerTopicResponse.ProvisioningState, "Succeeded", true) != 0)
                    {
                        TestUtilities.Wait(TimeSpan.FromSeconds(5));
                    }

                    getPartnerTopicResponse = this.EventGridManagementClient.PartnerTopics.Get(resourceGroup, partnerTopicName);
                    Assert.NotNull(getPartnerTopicResponse);
                    Assert.Equal("Succeeded", getPartnerTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Equal(location, getPartnerTopicResponse.Location, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Null(getPartnerTopicResponse.Tags);

                    // Get all partnerTopics created within a resourceGroup
                    IPage <PartnerTopic> partnerTopicsInResourceGroupPage = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupAsync(resourceGroup).Result;
                    var partnerTopicsInResourceGroupList = new List <PartnerTopic>();
                    if (partnerTopicsInResourceGroupPage.Any())
                    {
                        partnerTopicsInResourceGroupList.AddRange(partnerTopicsInResourceGroupPage);
                        var nextLink = partnerTopicsInResourceGroupPage.NextPageLink;
                        while (nextLink != null)
                        {
                            partnerTopicsInResourceGroupPage = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupNextAsync(nextLink).Result;
                            partnerTopicsInResourceGroupList.AddRange(partnerTopicsInResourceGroupPage);
                            nextLink = partnerTopicsInResourceGroupPage.NextPageLink;
                        }
                    }

                    Assert.NotNull(partnerTopicsInResourceGroupList);
                    Assert.True(partnerTopicsInResourceGroupList.Count() >= 1);
                    Assert.Contains(partnerTopicsInResourceGroupList, t => t.Name == partnerTopicName);
                    Assert.True(partnerTopicsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup)));

                    IPage <PartnerTopic> partnerTopicsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupAsync(resourceGroup, null, 5).Result;
                    var partnerTopicsInResourceGroupListWithTop = new List <PartnerTopic>();
                    if (partnerTopicsInResourceGroupPageWithTop.Any())
                    {
                        partnerTopicsInResourceGroupListWithTop.AddRange(partnerTopicsInResourceGroupPageWithTop);
                        var nextLink = partnerTopicsInResourceGroupPageWithTop.NextPageLink;
                        while (nextLink != null)
                        {
                            partnerTopicsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupNextAsync(nextLink).Result;
                            partnerTopicsInResourceGroupListWithTop.AddRange(partnerTopicsInResourceGroupPageWithTop);
                            nextLink = partnerTopicsInResourceGroupPageWithTop.NextPageLink;
                        }
                    }

                    Assert.NotNull(partnerTopicsInResourceGroupListWithTop);
                    Assert.True(partnerTopicsInResourceGroupListWithTop.Count() >= 1);
                    Assert.Contains(partnerTopicsInResourceGroupListWithTop, t => t.Name == partnerTopicName);
                    Assert.True(partnerTopicsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup)));

                    // Get all partnerTopics created within the subscription irrespective of the resourceGroup
                    IPage <PartnerTopic> partnerTopicsInAzureSubscription = this.EventGridManagementClient.PartnerTopics.ListBySubscriptionAsync(null, 100).Result;
                    var partnerTopicsInAzureSubscriptionList = new List <PartnerTopic>();
                    if (partnerTopicsInAzureSubscription.Any())
                    {
                        partnerTopicsInAzureSubscriptionList.AddRange(partnerTopicsInAzureSubscription);
                        var nextLink = partnerTopicsInAzureSubscription.NextPageLink;
                        while (nextLink != null)
                        {
                            try
                            {
                                partnerTopicsInAzureSubscription = this.EventGridManagementClient.PartnerTopics.ListBySubscriptionNextAsync(nextLink).Result;
                                partnerTopicsInAzureSubscriptionList.AddRange(partnerTopicsInAzureSubscription);
                                nextLink = partnerTopicsInAzureSubscription.NextPageLink;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                                break;
                            }
                        }
                    }

                    Assert.NotNull(partnerTopicsInAzureSubscriptionList);
                    Assert.True(partnerTopicsInAzureSubscriptionList.Count() >= 1);
                    Assert.Contains(partnerTopicsInAzureSubscriptionList, t => t.Name == partnerTopicName);

                    EventSubscription eventSubscription = new EventSubscription()
                    {
                        Destination = new StorageQueueEventSubscriptionDestination()
                        {
                            QueueName  = "queue1",
                            ResourceId = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/DevExpRg/providers/Microsoft.Storage/storageAccounts/devexpstg"
                        },
                        Filter = new EventSubscriptionFilter()
                        {
                            IncludedEventTypes     = null,
                            IsSubjectCaseSensitive = true,
                            SubjectBeginsWith      = "TestPrefix",
                            SubjectEndsWith        = "TestSuffix"
                        },
                        Labels = new List <string>()
                        {
                            "TestLabel1",
                            "TestLabel2"
                        }
                    };

                    var eventSubscriptionResponse = this.EventGridManagementClient.PartnerTopicEventSubscriptions.CreateOrUpdateAsync(resourceGroup, partnerTopicName, eventSubscriptionName, eventSubscription).Result;
                    eventSubscriptionCreated = true;

                    Assert.NotNull(eventSubscriptionResponse);
                    Assert.Equal(eventSubscriptionResponse.Name, eventSubscriptionName);

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

                    // Get the created event subscription
                    eventSubscriptionResponse = EventGridManagementClient.PartnerTopicEventSubscriptions.Get(resourceGroup, partnerTopicName, eventSubscriptionName);
                    if (string.Compare(eventSubscriptionResponse.ProvisioningState, "Succeeded", true) != 0)
                    {
                        TestUtilities.Wait(TimeSpan.FromSeconds(5));
                    }

                    eventSubscriptionResponse = EventGridManagementClient.PartnerTopicEventSubscriptions.Get(resourceGroup, partnerTopicName, eventSubscriptionName);
                    Assert.NotNull(eventSubscriptionResponse);
                    Assert.Equal("Succeeded", eventSubscriptionResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Equal("TestPrefix", eventSubscriptionResponse.Filter.SubjectBeginsWith, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Equal("TestSuffix", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);

                    // Update the event subscription
                    var eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters()
                    {
                        Destination = new StorageQueueEventSubscriptionDestination()
                        {
                            QueueName  = "queue1",
                            ResourceId = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/DevExpRg/providers/Microsoft.Storage/storageAccounts/devexpstg"
                        },
                        Filter = new EventSubscriptionFilter()
                        {
                            IncludedEventTypes = new List <string>()
                            {
                                "Event1",
                                "Event2"
                            },
                            SubjectEndsWith   = ".jpg",
                            SubjectBeginsWith = "TestPrefix"
                        },
                        Labels = new List <string>()
                        {
                            "UpdatedLabel1",
                            "UpdatedLabel2",
                        }
                    };

                    eventSubscriptionResponse = this.eventGridManagementClient.PartnerTopicEventSubscriptions.UpdateAsync(resourceGroup, partnerTopicName, eventSubscriptionName, eventSubscriptionUpdateParameters).Result;
                    Assert.Equal(".jpg", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);
                    Assert.Contains(eventSubscriptionResponse.Labels, label => label == "UpdatedLabel1");

                    // List event subscriptions
                    ////////var eventSubscriptionsPage = this.EventGridManagementClient.PartnerTopicEventSubscriptions.ListByPartnerTopicAsync(resourceGroup, partnerTopicName).Result;
                    ////////List<EventSubscription> eventSubscriptionsList = new List<EventSubscription>();
                    ////////string nextLink = null;

                    ////////if (eventSubscriptionsPage != null)
                    ////////{
                    ////////    eventSubscriptionsList.AddRange(eventSubscriptionsPage);
                    ////////    nextLink = eventSubscriptionsPage.NextPageLink;
                    ////////    while (nextLink != null)
                    ////////    {
                    ////////        eventSubscriptionsPage = this.EventGridManagementClient.EventSubscriptions.ListRegionalByResourceGroupNextAsync(nextLink).Result;
                    ////////        eventSubscriptionsList.AddRange(eventSubscriptionsPage);
                    ////////        nextLink = eventSubscriptionsPage.NextPageLink;
                    ////////    }
                    ////////}
                }
                finally
                {
                    if (eventSubscriptionCreated)
                    {
                        // Delete the event subscription
                        EventGridManagementClient.PartnerTopicEventSubscriptions.DeleteAsync(resourceGroup, partnerTopicName, eventSubscriptionName).Wait();
                    }

                    if (partnerTopicCreated)
                    {
                        // Delete partnerTopic
                        this.EventGridManagementClient.PartnerTopics.DeleteAsync(resourceGroup, partnerTopicName).Wait();
                    }

                    if (eventChannelCreated)
                    {
                        // Delete eventChannel
                        this.EventGridManagementClient.EventChannels.DeleteAsync(resourceGroup, partnerNamespaceName, eventChannelName).Wait();
                    }

                    if (partnerNamespaceCreated)
                    {
                        // Delete partnerNamespace
                        this.EventGridManagementClient.PartnerNamespaces.DeleteAsync(resourceGroup, partnerNamespaceName).Wait();
                    }

                    if (partnerRegistrationCreated)
                    {
                        // Delete partnerRegistration
                        this.EventGridManagementClient.PartnerRegistrations.DeleteAsync(resourceGroup, partnerRegistrationName).Wait();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public EventSubscription UpdateEventSubscription(
            string scope,
            string eventSubscriptionName,
            string endpoint,
            string endpointType,
            string subjectBeginsWith,
            string subjectEndsWith,
            bool?isSubjectCaseSensitive,
            string[] includedEventTypes,
            string[] labels,
            RetryPolicy retryPolicy,
            string deadLetterEndpoint)
        {
            EventSubscriptionUpdateParameters eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters();

            if (!string.IsNullOrEmpty(endpoint))
            {
                // An endpoint was specified, so it needs to be included as part of the update parameters
                // Defaulting to webhook if endpoint type was not specified
                if (string.IsNullOrEmpty(endpointType) ||
                    string.Equals(endpointType, EventGridConstants.Webhook, StringComparison.OrdinalIgnoreCase))
                {
                    eventSubscriptionUpdateParameters.Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = endpoint
                    };
                }
                else if (string.Equals(endpointType, EventGridConstants.EventHub, StringComparison.OrdinalIgnoreCase))
                {
                    eventSubscriptionUpdateParameters.Destination = new EventHubEventSubscriptionDestination()
                    {
                        ResourceId = endpoint
                    };
                }
                else if (string.Equals(endpointType, EventGridConstants.StorageQueue, StringComparison.OrdinalIgnoreCase))
                {
                    eventSubscriptionUpdateParameters.Destination = this.GetStorageQueueEventSubscriptionDestinationFromEndpoint(endpoint);
                }
                else if (string.Equals(endpointType, EventGridConstants.HybridConnection, StringComparison.OrdinalIgnoreCase))
                {
                    eventSubscriptionUpdateParameters.Destination = new HybridConnectionEventSubscriptionDestination()
                    {
                        ResourceId = endpoint
                    };
                }
                else
                {
                    throw new ArgumentNullException(nameof(endpointType), "EndpointType should be WebHook, EventHub, storage queue, or hybrid connection");
                }
            }

            if (includedEventTypes == null)
            {
                includedEventTypes    = new string[1];
                includedEventTypes[0] = "All";
            }

            eventSubscriptionUpdateParameters.Filter = new EventSubscriptionFilter()
            {
                SubjectBeginsWith      = subjectBeginsWith,
                SubjectEndsWith        = subjectEndsWith,
                IsSubjectCaseSensitive = isSubjectCaseSensitive,
                IncludedEventTypes     = new List <string>(includedEventTypes)
            };

            if (labels != null)
            {
                eventSubscriptionUpdateParameters.Labels = new List <string>(labels);
            }

            if (retryPolicy != null)
            {
                eventSubscriptionUpdateParameters.RetryPolicy = retryPolicy;
            }

            if (!string.IsNullOrEmpty(deadLetterEndpoint))
            {
                eventSubscriptionUpdateParameters.DeadLetterDestination = this.GetStorageBlobDeadLetterDestinationFromEndPoint(deadLetterEndpoint);
            }

            return(this.Client.EventSubscriptions.Update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters));
        }
Ejemplo n.º 9
0
        public void EventSubscriptionCreateGetUpdateDelete()
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                this.InitializeClients(context);

                var location = this.ResourceManagementClient.GetLocationFromProvider();

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

                var topicName = TestUtilities.GenerateName(EventGridManagementHelper.TopicPrefix);

                var createTopicResponse = this.EventGridManagementClient.Topics.CreateOrUpdateAsync(resourceGroup, topicName,
                                                                                                    new Topic()
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "tag1", "value1" },
                        { "tag2", "value2" }
                    }
                }).Result;

                Assert.NotNull(createTopicResponse);
                Assert.Equal(createTopicResponse.Name, topicName);

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

                // Get the created topic
                var getTopicResponse = EventGridManagementClient.Topics.Get(resourceGroup, topicName);
                if (string.Compare(getTopicResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                getTopicResponse = EventGridManagementClient.Topics.Get(resourceGroup, topicName);
                Assert.NotNull(getTopicResponse);
                Assert.Equal("Succeeded", getTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal(location, getTopicResponse.Location, StringComparer.CurrentCultureIgnoreCase);

                // Create an event subscription to this topic
                var    eventSubscriptionName = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix);
                string scope = $"/subscriptions/55f3dcd4-cac7-43b4-990b-a139d62a1eb2/resourceGroups/{resourceGroup}/providers/Microsoft.EventGrid/topics/{topicName}";

                EventSubscription eventSubscription = new EventSubscription()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = AzureFunctionEndpointUrl
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes = new List <string>()
                        {
                            "All"
                        },
                        IsSubjectCaseSensitive = true,
                        SubjectBeginsWith      = "TestPrefix",
                        SubjectEndsWith        = "TestSuffix"
                    },
                    Labels = new List <string>()
                    {
                        "TestLabel1",
                        "TestLabel2"
                    }
                };

                var eventSubscriptionResponse = this.EventGridManagementClient.EventSubscriptions.CreateOrUpdateAsync(scope, eventSubscriptionName, eventSubscription).Result;
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal(eventSubscriptionResponse.Name, eventSubscriptionName);

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

                // Get the created event subscription
                eventSubscriptionResponse = EventGridManagementClient.EventSubscriptions.Get(scope, eventSubscriptionName);
                if (string.Compare(eventSubscriptionResponse.ProvisioningState, "Succeeded", true) != 0)
                {
                    TestUtilities.Wait(TimeSpan.FromSeconds(5));
                }

                eventSubscriptionResponse = EventGridManagementClient.EventSubscriptions.Get(scope, eventSubscriptionName);
                Assert.NotNull(eventSubscriptionResponse);
                Assert.Equal("Succeeded", eventSubscriptionResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestPrefix", eventSubscriptionResponse.Filter.SubjectBeginsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Equal("TestSuffix", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);

                // Update the event subscription
                var eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters()
                {
                    Destination = new WebHookEventSubscriptionDestination()
                    {
                        EndpointUrl = AzureFunctionEndpointUrl,
                    },
                    Filter = new EventSubscriptionFilter()
                    {
                        IncludedEventTypes = new List <string>()
                        {
                            "Event1",
                            "Event2"
                        },
                        SubjectEndsWith   = ".jpg",
                        SubjectBeginsWith = "TestPrefix"
                    },
                    Labels = new List <string>()
                    {
                        "UpdatedLabel1",
                        "UpdatedLabel2",
                    }
                };

                eventSubscriptionResponse = this.eventGridManagementClient.EventSubscriptions.UpdateAsync(scope, eventSubscriptionName, eventSubscriptionUpdateParameters).Result;
                Assert.Equal(".jpg", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase);
                Assert.Contains(eventSubscriptionResponse.Labels, label => label == "UpdatedLabel1");

                // List event subscriptions
                var eventSubscriptionsList = this.EventGridManagementClient.EventSubscriptions.ListRegionalByResourceGroupAsync(resourceGroup, location).Result;
                Assert.Contains(eventSubscriptionsList, es => es.Name == eventSubscriptionName);

                // Delete the event subscription
                EventGridManagementClient.EventSubscriptions.DeleteAsync(scope, eventSubscriptionName).Wait();

                // Delete the topic
                EventGridManagementClient.Topics.DeleteAsync(resourceGroup, topicName).Wait();
            }
        }