public void Find_FindsSubscriptionsEntityCI() { IQueue subscription = Substitute.For <IQueue, IEntity>(); subscription.Name.Returns("sub"); var subscriptions = new Dictionary <string, IQueue> { [subscription.Name] = subscription }; ITopic topic = Substitute.For <ITopic, IEntity>(); topic.Name.Returns("T"); topic.Subscriptions.Returns(subscriptions); var topics = new Dictionary <string, ITopic> { [topic.Name] = topic }; IServiceBusSimulator fakeSimulator = Substitute.For <IServiceBusSimulator>(); fakeSimulator.Topics.Returns(topics); var lookup = new EntityLookup(fakeSimulator); lookup.Find("T/Subscriptions/sub").ShouldBeSameAs(subscription); lookup.Find("t/subscriptions/sub").ShouldBeSameAs(subscription); }
public void Find_FindsAllRegisteredEntities() { IQueue subscription = Substitute.For <IQueue, IEntity>(); subscription.Name.Returns("bar"); var subscriptions = new Dictionary <string, IQueue> { [subscription.Name] = subscription }; ITopic topic = Substitute.For <ITopic, IEntity>(); topic.Name.Returns("foo"); topic.Subscriptions.Returns(subscriptions); var topics = new Dictionary <string, ITopic> { [topic.Name] = topic }; IQueue queue = Substitute.For <IQueue, IEntity>(); queue.Name.Returns("qux"); var queues = new Dictionary <string, IQueue> { [queue.Name] = queue }; IServiceBusSimulator fakeSimulator = Substitute.For <IServiceBusSimulator>(); fakeSimulator.Topics.Returns(topics); fakeSimulator.Queues.Returns(queues); var lookup = new EntityLookup(fakeSimulator); lookup.Find("foo").ShouldBeSameAs(topic); lookup.Find("foo/Subscriptions/Bar").ShouldBeSameAs(subscription); lookup.Find("qux").ShouldBeSameAs(queue); lookup.Find("baz").ShouldBeNull(); }
public void GetEnumerator_ReturnsAllEntriesFromTopicAndSubscriptionsAndQueues([Values] bool genericEnumerator) { IQueue subscription1 = Substitute.For <IQueue, IEntity>(); subscription1.Name.Returns("sub1"); IQueue subscription2 = Substitute.For <IQueue, IEntity>(); subscription2.Name.Returns("sub2"); var subscriptions = new Dictionary <string, IQueue> { [subscription1.Name] = subscription1, [subscription2.Name] = subscription2 }; ITopic topic = Substitute.For <ITopic, IEntity>(); topic.Name.Returns("topic"); topic.Subscriptions.Returns(subscriptions); var topics = new Dictionary <string, ITopic> { [topic.Name] = topic }; IQueue queue = Substitute.For <IQueue, IEntity>(); queue.Name.Returns("que"); var queues = new Dictionary <string, IQueue> { [queue.Name] = queue }; IServiceBusSimulator fakeSimulator = Substitute.For <IServiceBusSimulator>(); fakeSimulator.Topics.Returns(topics); fakeSimulator.Queues.Returns(queues); var lookup = new EntityLookup(fakeSimulator); var data = new Dictionary <string, IEntity>(); IEnumerator enumerator = genericEnumerator ? lookup.GetEnumerator() : ((IEnumerable)lookup).GetEnumerator(); using (enumerator as IDisposable) { while (enumerator.MoveNext()) { (string address, IEntity entity) = ((string, IEntity))enumerator.Current; data.Add(address, entity); } } data.ShouldSatisfyAllConditions( () => data.Count.ShouldBe(4), () => data["que"].ShouldBeSameAs(queue), () => data["topic"].ShouldBeSameAs(topic), () => data["topic/Subscriptions/sub1"].ShouldBeSameAs(subscription1), () => data["topic/Subscriptions/sub2"].ShouldBeSameAs(subscription2) ); }
public void Find_FindsQueueEntityCI() { IQueue queue = Substitute.For <IQueue, IEntity>(); queue.Name.Returns("myQue"); var queues = new Dictionary <string, IQueue> { [queue.Name] = queue }; IServiceBusSimulator fakeSimulator = Substitute.For <IServiceBusSimulator>(); fakeSimulator.Queues.Returns(queues); var lookup = new EntityLookup(fakeSimulator); lookup.Find("myQue").ShouldBeSameAs(queue); lookup.Find("myque").ShouldBeSameAs(queue); }
public void Find_FindsTopicEntityCI() { ITopic topic = Substitute.For <ITopic, IEntity>(); topic.Name.Returns("myTopic"); var topics = new Dictionary <string, ITopic> { [topic.Name] = topic }; IServiceBusSimulator fakeSimulator = Substitute.For <IServiceBusSimulator>(); fakeSimulator.Topics.Returns(topics); var lookup = new EntityLookup(fakeSimulator); lookup.Find("myTopic").ShouldBeSameAs(topic); lookup.Find("mytopic").ShouldBeSameAs(topic); }
public async Task TestAzureServiceBusQueueSend() { X509Certificate2 testCertificate = TestCertificate.Find(); if (testCertificate == null) { Assert.Inconclusive("The test SSL certificate is not available."); } using ISimulation simulation = Simulation.Create(); const string queueName = "my-queue-3278"; var messageBody = Encoding.ASCII.GetBytes("DTESTa"); IServiceBusSimulator bus = simulation.AddServiceBus() .SetCertificate(testCertificate) .AddQueue(queueName) .Build(); await bus.StartAsync(); var queueClient = new QueueClient(bus.ConnectionString, queueName); var message = new Message(messageBody) { CorrelationId = "3278" }; message.UserProperties["BoldManTrue"] = 32; await queueClient.SendAsync(message); await queueClient.CloseAsync(); await bus.StopAsync(); IReadOnlyList <IDelivery> deliveries = bus.Queues[queueName].Deliveries; bus.ShouldSatisfyAllConditions( () => deliveries.Count.ShouldBe(1), () => deliveries[0].Message.Body.ShouldBe(messageBody), () => deliveries[0].Message.ApplicationProperties["BoldManTrue"].ShouldBe(32) ); }
internal EntityLookup(IServiceBusSimulator simulator) { var topics = simulator.Topics.Values .Select(topic => new { topic.Name, Entity = (IEntity)topic }); var subscriptions = simulator.Topics.Values .SelectMany(topic => topic .Subscriptions .Values .Select(subscription => new { Name = $"{topic.Name}/Subscriptions/{subscription.Name}", Entity = (IEntity)subscription }) ); var queues = simulator.Queues.Values .Select(queue => new { queue.Name, Entity = (IEntity)queue }); _entities = topics .Concat(subscriptions) .Concat(queues) .ToDictionary( item => item.Name, item => item.Entity, StringComparer.OrdinalIgnoreCase ); }
public async Task TestAzureServiceBusQueueReceive() { X509Certificate2 testCertificate = TestCertificate.Find(); using ISimulation simulation = Simulation.Create(); const string queueName = "sb-queue-x"; Exception busException = null; IDelivery[] deliveries = null; IServiceBusSimulator bus = simulation.AddServiceBus() .SetCertificate(testCertificate) .AddQueue(queueName) .Build(); await bus.StartAsync(); IQueue busQueue = bus.Queues[queueName]; var receiver = new MessageReceiver(bus.ConnectionString, queueName); try { receiver.ServiceBusConnection.OperationTimeout = TimeSpan.FromHours(1); receiver.RegisterMessageHandler(async(message, cancellationToken) => { cancellationToken.ThrowIfCancellationRequested(); if (message.MessageId == "2481") { await receiver.DeadLetterAsync(message.SystemProperties.LockToken); } else if (message.MessageId == "51847") { await receiver.AbandonAsync(message.SystemProperties.LockToken); } else { await receiver.CompleteAsync(message.SystemProperties.LockToken); } }, new MessageHandlerOptions(e => { if (!(e.Exception is OperationCanceledException)) { busException = e.Exception; } return(Task.CompletedTask); }) { AutoComplete = false }); busQueue.Post(new Amqp.Message { Properties = new Amqp.Framing.Properties { MessageId = "2481" } }); busQueue.Post(new Amqp.Message { Properties = new Amqp.Framing.Properties { MessageId = "51847" }, }); busQueue.Post(new Amqp.Message { Properties = new Amqp.Framing.Properties { MessageId = "33782" }, }); busQueue.Post(new Amqp.Message()); deliveries = busQueue.Deliveries.ToArray(); IEnumerable <Task <bool> > deliveryTasks = deliveries.Select(d => d.WaitAsync(TimeSpan.FromSeconds(5))); await Task.WhenAll(deliveryTasks); } finally { await receiver.CloseAsync(); await bus.StopAsync(); } bus.ShouldSatisfyAllConditions( () => deliveries.Length.ShouldBe(4), () => deliveries[0].Result.ShouldBe(DeliveryResult.DeadLettered), () => deliveries[1].Result.ShouldBe(DeliveryResult.Abandoned), () => deliveries[2].Result.ShouldBe(DeliveryResult.Completed), () => deliveries[3].Result.ShouldBe(DeliveryResult.Completed) ); }