public void SubscriptionsAreSortedWhenRemoving()
        {
            var subscriptionColletion = new SubscriptionCollection();
            var subscription          = CreateSubscription(Resolution.Second, Futures.Metals.Gold, false, SecurityType.Future);
            var subscription2         = CreateSubscription(Resolution.Second, "SPY");
            var subscription3         = CreateSubscription(Resolution.Second, "AAPL", false, SecurityType.Option);
            var subscription4         = CreateSubscription(Resolution.Second, "EURGBP");
            var subscription5         = CreateSubscription(Resolution.Second, "AAPL", false, SecurityType.Option, TickType.OpenInterest);
            var subscription6         = CreateSubscription(Resolution.Second, "AAPL", false, SecurityType.Option, TickType.Quote);

            subscriptionColletion.TryAdd(subscription);
            subscriptionColletion.TryAdd(subscription2);
            subscriptionColletion.TryAdd(subscription3);
            subscriptionColletion.TryAdd(subscription4);
            subscriptionColletion.TryAdd(subscription5);
            subscriptionColletion.TryAdd(subscription6);
            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription4, subscription2, subscription3, subscription6, subscription5, subscription });

            subscriptionColletion.TryRemove(subscription2.Configuration, out subscription2);
            Assert.AreEqual(subscriptionColletion.Select(x => x.Configuration.SecurityType).ToList(), new[] { SecurityType.Equity, SecurityType.Option,
                                                                                                              SecurityType.Option, SecurityType.Option, SecurityType.Future });

            subscriptionColletion.TryRemove(subscription3.Configuration, out subscription3);
            Assert.AreEqual(subscriptionColletion.Select(x => x.Configuration.SecurityType).ToList(), new[] { SecurityType.Equity, SecurityType.Option, SecurityType.Option, SecurityType.Future });

            subscriptionColletion.TryRemove(subscription.Configuration, out subscription);
            Assert.AreEqual(subscriptionColletion.Select(x => x.Configuration.SecurityType).ToList(), new[] { SecurityType.Equity, SecurityType.Option, SecurityType.Option });
            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription4, subscription6, subscription5 });

            subscriptionColletion.TryRemove(subscription6.Configuration, out subscription6);
            Assert.AreEqual(subscriptionColletion.Select(x => x.Configuration.SecurityType).ToList(), new[] { SecurityType.Equity, SecurityType.Option });
            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription4, subscription5 });

            subscriptionColletion.TryRemove(subscription5.Configuration, out subscription5);
            Assert.AreEqual(subscriptionColletion.Select(x => x.Configuration.SecurityType).ToList(), new[] { SecurityType.Equity });

            subscriptionColletion.TryRemove(subscription4.Configuration, out subscription4);
            Assert.IsTrue(subscriptionColletion.Select(x => x.Configuration.SecurityType).ToList().IsNullOrEmpty());

            subscription.Dispose();
            subscription2.Dispose();
            subscription3.Dispose();
            subscription4.Dispose();
            subscription5.Dispose();
            subscription6.Dispose();
        }
Esempio n. 2
0
        public void SubscriptionsAreSortedWhenAdding2()
        {
            var subscriptionColletion = new SubscriptionCollection();
            var subscription          = CreateSubscription(Resolution.Second, "GC", false, SecurityType.Future);
            var subscription2         = CreateSubscription(Resolution.Second, "SPY");
            var subscription3         = CreateSubscription(Resolution.Second, "AAPL", false, SecurityType.Option);
            var subscription4         = CreateSubscription(Resolution.Second, "EURGBP");

            subscriptionColletion.TryAdd(subscription);
            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription });
            subscriptionColletion.TryAdd(subscription2);
            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription2, subscription });
            subscriptionColletion.TryAdd(subscription3);
            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription2, subscription3, subscription });
            subscriptionColletion.TryAdd(subscription4);

            Assert.AreEqual(subscriptionColletion.ToList(), new[] { subscription4, subscription2, subscription3, subscription });
            Assert.AreEqual(subscriptionColletion.Select(x => x.Security.Type).ToList(), new[] { SecurityType.Equity, SecurityType.Equity, SecurityType.Option, SecurityType.Future });
        }