Ejemplo n.º 1
0
        public async Task GetSubscribers_with_mapped_events_supports_polymorphism()
        {
            var settings = new AzureStorageAddressingSettings(new QueueAddressGenerator(s => s), "subscriber",
                                                              table.Name, new Dictionary <string, AccountInfo>(),
                                                              new AccountInfo("", queueServiceClient, cloudTableClient));

            var publisherAccount = new AccountInfo("publisher", queueServiceClient, cloudTableClient);

            publisherAccount.AddEndpoint("publisherEndpoint", new[] { typeof(MyEvent) }, subscriptionTableName: table.Name);
            settings.Add(publisherAccount);

            var subscriptionStore = new SubscriptionStore(settings);

            await subscriptionStore.Subscribe("subscriberEndpoint", "subscriberAddress", typeof(MyEvent));

            var subcribers =
                await subscriptionStore.GetSubscribers(typeof(MyOtherEvent));

            CollectionAssert.AreEqual(new[] { "subscriberAddress@subscriber" }, subcribers);
        }
Ejemplo n.º 2
0
        public async Task Subscribe_with_mapped_events_should_create_topics()
        {
            var settings = new AzureStorageAddressingSettings(new QueueAddressGenerator(s => s), "subscriber",
                                                              table.Name, new Dictionary <string, AccountInfo>(),
                                                              new AccountInfo("", queueServiceClient, cloudTableClient));

            var publisherAccount = new AccountInfo("publisher", queueServiceClient, cloudTableClient);

            publisherAccount.AddEndpoint("publisherEndpoint", new[] { typeof(MyEventPublishedOnAnotherAccount) }, subscriptionTableName: table.Name);
            settings.Add(publisherAccount);

            var subscriptionStore = new SubscriptionStore(settings);

            await subscriptionStore.Subscribe("subscriberEndpoint", "subscriberAddress", typeof(MyOtherEvent));

            await subscriptionStore.Subscribe("subscriberEndpoint", "subscriberAddress", typeof(MyOtherUnrelatedEvent));

            await subscriptionStore.Subscribe("subscriberEndpoint", "subscriberAddress", typeof(MyEventPublishedOnAnotherAccount));

            var query    = new TableQuery <DynamicTableEntity>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, "subscriberEndpoint"));
            var entities = (await table.QueryUpTo(query, maxItemsToReturn: 100)).ToArray();

            CollectionAssert.AreEqual(new[]
            {
                typeof(MyEventPublishedOnAnotherAccount).FullName,
                typeof(MyOtherEvent).FullName,
                typeof(MyOtherUnrelatedEvent).FullName
            }, entities.Select(x => x.PartitionKey).ToList());

            CollectionAssert.AreEqual(new[]
            {
                "subscriberAddress@subscriber",
                "subscriberAddress",
                "subscriberAddress"
            }, entities.Select(x => x["Address"].StringValue).ToList());
        }