public void WhenUnsubscribedIsCalledShouldCallAction()
		{
			var bus = MockRepository.GenerateStub<IServiceBus>();
			var obs = MockRepository.GenerateStub<IObserver<PingMessage>>();
			bool disposed = false;
			bus.Stub(b => b.Subscribe<PingMessage>(obs.OnNext)).Return(() => disposed = true);

			var sbs = new ServiceBusSubscription<PingMessage>(bus, obs, null);
			sbs.Dispose();

			Assert.IsTrue(disposed);
		}
示例#2
0
        public ISubscriptionClient Create(ServiceBusSubscription subscription)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }

            var client = new SubscriptionClient(
                connectionStringBuilder: _connectionStringBuilder,
                subscriptionName: subscription.Name);

            return(client);
        }
        public void TestUpdateSubscription()
        {
            foreach (var dataService in DataServices)
            {
                // Arrange.
                string        clientId      = "Client ID";
                string        messageTypeId = "MessageType ID";
                TransportType transportType = TransportType.WEB;
                DateTime      expiryDate    = new DateTime(2015, 7, 20);

                var service = new DefaultSubscriptionsManager(dataService, GetMockStatisticsService());

                service.CreateClient(clientId, "Client name");
                service.CreateMessageType(new ServiceBusMessageType
                {
                    ID   = messageTypeId,
                    Name = "MessageType name",
                });

                service.SubscribeOrUpdate(clientId, messageTypeId, true, transportType, expiryDate);

                // Act && Assert.
                var subscriptionLcs = LoadingCustomizationStruct.GetSimpleStruct(typeof(Subscription), Subscription.Views.SendingByCallbackView);
                var subscriptions   = dataService.LoadObjects(subscriptionLcs).Cast <Subscription>().ToList();

                Assert.Equal(subscriptions.Count(), 1);
                Assert.Equal(subscriptions[0].MessageType.ID, messageTypeId);
                Assert.Equal(subscriptions[0].Client.ID, clientId);
                Assert.Equal(subscriptions[0].IsCallback, true);
                Assert.Equal(subscriptions[0].TransportType, transportType);
                Assert.Equal(subscriptions[0].ExpiryDate, expiryDate);

                ServiceBusSubscription newSubscriptionData = new ServiceBusSubscription()
                {
                    Callback    = false,
                    Description = "new description",
                    ExpiryDate  = new DateTime(2017, 8, 20),
                    SendBy      = "MAIL",
                };

                service.UpdateSubscription(subscriptions[0].__PrimaryKey.ToString(), newSubscriptionData);

                var newSubscriptions = dataService.LoadObjects(subscriptionLcs).Cast <Subscription>().ToList();
                Assert.Equal(newSubscriptions.Count(), 1);
                Assert.Equal(newSubscriptions[0].MessageType.ID, messageTypeId);
                Assert.Equal(newSubscriptions[0].Client.ID, clientId);
                Assert.Equal(newSubscriptions[0].IsCallback, newSubscriptionData.Callback);
                Assert.Equal(newSubscriptions[0].TransportType.ToString(), newSubscriptionData.SendBy);
                Assert.Equal(newSubscriptions[0].ExpiryDate, newSubscriptionData.ExpiryDate);
            }
        }
        public void WhenUnsubscribedIsCalledShouldCallAction()
        {
            var  bus      = MockRepository.GenerateStub <IServiceBus>();
            var  obs      = MockRepository.GenerateStub <IObserver <PingMessage> >();
            bool disposed = false;

            bus.Stub(b => b.Subscribe <PingMessage>(obs.OnNext)).Return(() => disposed = true);

            var sbs = new ServiceBusSubscription <PingMessage>(bus, obs, null);

            sbs.Dispose();

            Assert.IsTrue(disposed);
        }
        /// <summary>
        /// Обновить подписку.
        /// </summary>
        /// <param name="subscriptionId">Идентификатор подписки, которую нужно обновить.</param>
        /// <param name="subscription">Новые данные подписки.</param>
        public void UpdateSubscription(string subscriptionId, ServiceBusSubscription subscription)
        {
            Subscription currentSubscription = new Subscription {
                __PrimaryKey = subscriptionId
            };
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            _dataService.LoadObject(currentSubscription);

            stopwatch.Stop();
            long time = stopwatch.ElapsedMilliseconds;

            _statisticsService.NotifyAvgTimeSql(null, (int)time, "DefaultSubscriptionsManager.UpdateSubscription() load subscription.");

            if (subscription.ExpiryDate != null)
            {
                currentSubscription.ExpiryDate = subscription.ExpiryDate.Value;
            }

            if (subscription.Description != null)
            {
                currentSubscription.Description = subscription.Description;
            }

            if (subscription.Callback != null)
            {
                bool callback = subscription.Callback.Value;
                currentSubscription.IsCallback = callback;
            }

            TransportType transportType;

            EnumCaption.TryGetValueFor(subscription.SendBy, out transportType);
            if (transportType != default(TransportType))
            {
                currentSubscription.TransportType = transportType;
            }

            stopwatch = new Stopwatch();
            stopwatch.Start();

            _dataService.UpdateObject(currentSubscription);

            stopwatch.Stop();
            time = stopwatch.ElapsedMilliseconds;
            _statisticsService.NotifyAvgTimeSql(null, (int)time, "DefaultSubscriptionsManager.UpdateSubscription() update subscription.");
        }
示例#6
0
        public async Task CreateGetUpdateDeleteRule()
        {
            IgnoreTestInLiveMode();

            const string strSqlExp = "myproperty=test";

            //create namespace
            ResourceGroup resourceGroup = await CreateResourceGroupAsync();

            string namespaceName = await CreateValidNamespaceName("testnamespacemgmt");

            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace           serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //create a topic
            ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics();
            string          topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic     = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value;

            Assert.NotNull(topic);
            Assert.AreEqual(topic.Id.Name, topicName);

            //create a subscription
            ServiceBusSubscriptionCollection serviceBusSubscriptionCollection = topic.GetServiceBusSubscriptions();
            string subscriptionName = Recording.GenerateAssetName("subscription");
            ServiceBusSubscriptionData parameters             = new ServiceBusSubscriptionData();
            ServiceBusSubscription     serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, parameters)).Value;

            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);

            //create rule with no filters
            string ruleName1 = Recording.GenerateAssetName("rule");
            ServiceBusRuleCollection ruleCollection = serviceBusSubscription.GetServiceBusRules();
            ServiceBusRule           rule1          = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName1, new ServiceBusRuleData())).Value;

            Assert.NotNull(rule1);
            Assert.AreEqual(rule1.Id.Name, ruleName1);

            //create rule with correlation filter
            string         ruleName2 = Recording.GenerateAssetName("rule");
            ServiceBusRule rule2     = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName2, new ServiceBusRuleData()
            {
                FilterType = FilterType.CorrelationFilter
            })).Value;

            Assert.NotNull(rule2);
            Assert.AreEqual(rule2.Id.Name, ruleName2);

            //get created rules
            rule1 = await ruleCollection.GetAsync(ruleName1);

            Assert.NotNull(rule1);
            Assert.AreEqual(rule1.Id.Name, ruleName1);

            //get all rules
            List <ServiceBusRule> rules = await ruleCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(2, rules.Count);

            //update rule with sql filter and action
            ServiceBusRuleData updateParameters = new ServiceBusRuleData()
            {
                Action = new SqlRuleAction()
                {
                    RequiresPreprocessing = true,
                    SqlExpression         = "SET " + strSqlExp,
                },
                SqlFilter = new SqlFilter()
                {
                    SqlExpression = strSqlExp
                },
                FilterType        = FilterType.SqlFilter,
                CorrelationFilter = new CorrelationFilter()
            };

            rule1 = (await ruleCollection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName1, updateParameters)).Value;

            await rule1.DeleteAsync(WaitUntil.Completed);

            await rule2.DeleteAsync(WaitUntil.Completed);
        }
示例#7
0
        public async Task CreateGetUpdateDeleteSubscription()
        {
            IgnoreTestInLiveMode();
            //create namespace
            ResourceGroup resourceGroup = await CreateResourceGroupAsync();
            string namespaceName = await CreateValidNamespaceName("testnamespacemgmt");
            ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespace serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(DefaultLocation))).Value;

            //create a topic
            ServiceBusTopicCollection topicCollection = serviceBusNamespace.GetServiceBusTopics();
            string topicName = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName, new ServiceBusTopicData())).Value;
            Assert.NotNull(topic);
            Assert.AreEqual(topic.Id.Name, topicName);

            //create a subscription
            ServiceBusSubscriptionCollection serviceBusSubscriptionCollection = topic.GetServiceBusSubscriptions();
            string subscriptionName = Recording.GenerateAssetName("subscription");
            ServiceBusSubscriptionData parameters = new ServiceBusSubscriptionData()
            {
                EnableBatchedOperations = true,
                LockDuration = TimeSpan.Parse("00:03:00"),
                DefaultMessageTimeToLive = TimeSpan.Parse("00:05:00"),
                DeadLetteringOnMessageExpiration = true,
                MaxDeliveryCount = 14,
                Status = EntityStatus.Active,
                AutoDeleteOnIdle = TimeSpan.Parse("00:07:00"),
                DeadLetteringOnFilterEvaluationExceptions = true
            };
            ServiceBusSubscription serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, parameters)).Value;
            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);

            //get created subscription
            serviceBusSubscription = await serviceBusSubscriptionCollection.GetAsync(subscriptionName);
            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);
            Assert.AreEqual(serviceBusSubscription.Data.Status, EntityStatus.Active);

            //get all subscriptions
            List<ServiceBusSubscription> serviceBusSubscriptions = await serviceBusSubscriptionCollection.GetAllAsync().ToEnumerableAsync();
            Assert.AreEqual(serviceBusSubscriptions.Count, 1);

            //create a topic for autoforward
            string topicName1 = Recording.GenerateAssetName("topic");
            ServiceBusTopic topic1 = (await topicCollection.CreateOrUpdateAsync(WaitUntil.Completed, topicName1, new ServiceBusTopicData() { EnablePartitioning = true})).Value;
            Assert.NotNull(topic1);
            Assert.AreEqual(topic1.Id.Name, topicName1);

            //update subscription and validate
            ServiceBusSubscriptionData updateParameters = new ServiceBusSubscriptionData()
            {
                EnableBatchedOperations = true,
                DeadLetteringOnMessageExpiration = true,
                ForwardDeadLetteredMessagesTo = topicName1,
                ForwardTo = topicName1
            };
            serviceBusSubscription = (await serviceBusSubscriptionCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionName, updateParameters)).Value;
            Assert.NotNull(serviceBusSubscription);
            Assert.AreEqual(serviceBusSubscription.Id.Name, subscriptionName);
            Assert.AreEqual(serviceBusSubscription.Data.Status, EntityStatus.Active);
            Assert.IsTrue(serviceBusSubscription.Data.EnableBatchedOperations);
            Assert.AreEqual(serviceBusSubscription.Data.ForwardTo, topicName1);

            //delete subscription
            await serviceBusSubscription.DeleteAsync(WaitUntil.Completed);
            Assert.IsFalse(await serviceBusSubscriptionCollection.ExistsAsync(subscriptionName));
        }
示例#8
0
 public void UpdateSubscription(string subscriptionId, ServiceBusSubscription subscription)
 {
     throw new NotImplementedException();
 }