public void GarbageCollectingTopicsAfterGettingTopicsNoops() { var dr = new DefaultDependencyResolver(); var configuration = dr.Resolve <IConfigurationManager>(); configuration.KeepAlive = null; using (var bus = new MessageBus(dr)) { var subscriber = new TestSubscriber(new[] { "key" }); IDisposable subscription = null; bus.AfterTopicMarkedSuccessfully = (key, topic) => { bus.GarbageCollectTopics(); }; try { subscription = bus.Subscribe(subscriber, null, (result, state) => TaskAsyncHelper.True, 10, null); Assert.Equal(1, bus.Topics.Count); Topic topic; Assert.True(bus.Topics.TryGetValue("key", out topic)); Assert.Equal(TopicState.HasSubscriptions, topic.State); } finally { if (subscription != null) { subscription.Dispose(); } } } }
public void GarbageCollectingTopicsBeforeSubscribingTopicSetsStateToHasSubscription() { var dr = new DefaultDependencyResolver(); var configuration = dr.Resolve <IConfigurationManager>(); configuration.DisconnectTimeout = TimeSpan.FromSeconds(6); configuration.KeepAlive = null; using (var bus = new MessageBus(dr)) { bus.BeforeTopicMarked = (key, t) => { bus.GarbageCollectTopics(); }; Topic topic = bus.SubscribeTopic("key"); Assert.Equal(1, bus.Topics.Count); Assert.True(bus.Topics.TryGetValue("key", out topic)); Assert.Equal(TopicState.HasSubscriptions, topic.State); } }