public void ReplaceRangeOnSecond_FirstContainsNewItems_RaisesNotifyCollectionChangedWithOneAddAndRemoveActionsForEachItemReplacedRemoved2()
        {
            var people = new List <Person> {
                new Person(), new Person()
            };

            _first = new ObservableCollection <Person> {
                _person1, _person2, people[0], people[1]
            };
            var continuousSecondCollection = new ContinuousCollection <Person> {
                _person1, _person2
            };

            _target = new ExceptReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.ReplaceRange(0, people);

            Assert.AreEqual(3, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 2, _person1, _person2);
            TestUtilities.AssertRemove(eventArgsList[1], 0, people[0]);
            TestUtilities.AssertRemove(eventArgsList[2], 0, people[1]);
        }
        public void Test()
        {
            // Collection with 1 item to make this test simple
            Items = new ContinuousCollection<NotifiableItem>
                                {
                                    new NotifiableItem { TestValue1 = 3, TestValue2 = 10 },
                                };

            // Start with TestValue1
            MaxValueCV = Items.ContinuousMax(item => item.TestValue1, value => Max = value);
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            Console.WriteLine("Max = " + Max);
            Console.WriteLine();

            // Switch to TestValue2
            MaxValueCV = Items.ContinuousMax(item => item.TestValue2, value => Max = value);
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            Console.WriteLine("Max = " + Max);
            Console.WriteLine();
            GC.Collect();
            WeakPropertyChangedEventManager.RemoveCollectedEntries();
            GC.Collect();
            // Now set TestValue1
            Items[0].TestValue1 = 20;
            Console.WriteLine("(BUG)");
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            // BUG: Max is set to 20 when it should be 10
            Console.WriteLine("Max = " + Max);

            Assert.AreEqual(10, Max);

            Console.Write("Hit enter to continue...");
            Console.ReadLine();
        }
 public void Initialize()
 {
     _list = new ContinuousCollection <PropertyChangedClass>
     {
         new PropertyChangedClass {
             DecimalTargetValue = 10, TargetValue = 10
         },
         new PropertyChangedClass {
             DecimalTargetValue = 23, TargetValue = 23
         },
         new PropertyChangedClass {
             DecimalTargetValue = null, TargetValue = null
         },
         new PropertyChangedClass {
             DecimalTargetValue = 2, TargetValue = 2
         },
         new PropertyChangedClass {
             DecimalTargetValue = null, TargetValue = null
         },
         new PropertyChangedClass {
             DecimalTargetValue = null, TargetValue = null
         },
         new PropertyChangedClass {
             DecimalTargetValue = 1, TargetValue = 1
         },
     };
     _target = _list.AsReadOnly();
 }
Esempio n. 4
0
        public void Initialize()
        {
            _target = null;
            _source = new ContinuousCollection <Person>();

            AddItemsToSource();
        }
        public void RemoveRangeFromFirst_Always_RaisesNotifyCollectionChangedWithAddActionAndCorrectValues2()
        {
            var continuousSecondCollection = new ContinuousCollection <Person>(_first.ToList());

            _target = new ExceptReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.RemoveRange(0, 2);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 0, _first.ToArray());
        }
        public void RemoveRangeFromSecond_Always_RaisesNotifyCollectionChangedWithRemoveActionAndCorrectValuesForEachItemRemoved()
        {
            var continuousSecondCollection = new ContinuousCollection <Person>(_first.ToList());

            _target = new ConcatReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.RemoveRange(0, 2);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertRemove(eventArgsList[0], 2, _person1, _person2);
        }
        public void AddRangeToSecond_Always_RaisesNotifyCollectionChangedWithRemoveActionAndCorrectValuesForEachItemRemoved()
        {
            var continuousSecondCollection = new ContinuousCollection <Person>();

            _target = new ExceptReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.AddRange(_first);

            Assert.AreEqual(2, eventArgsList.Count);

            TestUtilities.AssertRemove(eventArgsList[0], 0, _person1);
            TestUtilities.AssertRemove(eventArgsList[1], 0, _person2);
        }
Esempio n. 8
0
        public void SortingViewAdapater_ByName_ReturnsCollectionOrderedAscendingByName()
        {
            _target = from item in _source
                      orderby item.Name
                      select item;

            Assert.AreEqual(6, _target.Count);
            Assert.AreEqual("Erb", _target[1].Name);
            Assert.AreEqual("Steve", _target[5].Name);

            _source.Add(new Person("Dan", 100));

            Assert.AreEqual("Dan", _target[0].Name);
            Assert.AreEqual("David", _target[1].Name);
        }
Esempio n. 9
0
        public MonitorWindowModel() : base()
        {
            _tickerData = new ContinuousCollection <StockSaleTick>();
            _vwapTicks  = new ContinuousCollection <StockSaleTick>();
            _allQuotes  = new ContinuousCollection <StockQuoteTick>();

            _bidTicks = from quote in _allQuotes
                        where quote.Side == QuoteSide.Bid
                        select quote;

            _askTicks = from quote in _allQuotes
                        where quote.Side == QuoteSide.Ask
                        select quote;

            _allTicks =
                from tick in _tickerData
                where tick.Symbol == "AAPL"
                select tick;

            _graphWindowTicks =
                from tick in _tickerData
                where tick.TimeStamp >= DateTime.Now.AddMinutes(-5) &&
                tick.Symbol == "AAPL"
                select tick; // return last 5 minutes worth of ticks for AAPL */

            _liveVwap = _allTicks.ContinuousVwap <StockSaleTick>(
                tick => tick.Price,
                tick => tick.Quantity);

            _liveHigh = _allTicks.ContinuousMax <StockSaleTick>(
                tick => tick.Price);

            _liveMin = _allTicks.ContinuousMin <StockSaleTick>(
                tick => tick.Price);

            _liveMin.PropertyChanged +=
                new PropertyChangedEventHandler(_liveMin_PropertyChanged);
            _liveHigh.PropertyChanged +=
                new PropertyChangedEventHandler(_liveHigh_PropertyChanged);
            _liveVwap.PropertyChanged +=
                new PropertyChangedEventHandler(_liveVwap_PropertyChanged);

            _simulationTimer          = new Timer();
            _simulationTimer.Elapsed += new ElapsedEventHandler(_simulationTimer_Elapsed);
            _simulationTimer.Interval = 1000;
            _simulationTimer.Start(); // create a new tick every second
        }
        public void AddRangeToSecond_Always_RaisesNotifyCollectionChangedWithAddActionAndCorrectValues()
        {
            var continuousSecondCollection = new ContinuousCollection <Person>();

            _target = new ConcatReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection);

            var people = new List <Person> {
                new Person(), new Person()
            };

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.AddRange(people);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 2, people.ToArray());
        }
        public void ReplaceRangeOnSecond_Always_RaisesNotifyCollectionChangedWithReplaceAction()
        {
            var continuousSecondCollection = new ContinuousCollection <Person>(_first.ToList());

            _target = new ConcatReadOnlyContinuousCollection <Person>(_first, continuousSecondCollection);

            var people = new List <Person> {
                new Person(), new Person()
            };

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.ReplaceRange(0, people);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertReplace(eventArgsList[0], 2, people.ToArray(), new[] { _person1, _person2 });
        }
Esempio n. 12
0
        public void FilteringViewAdapter_OnAgeGreaterThan30_ReturnsCollectionWithPersonsOlderThan30()
        {
            _target = from item in _source
                      where item.Age > 30
                      select item;

            Assert.AreEqual(2, _target.Count);
            Assert.AreEqual("Jordan", _target[0].Name);
            Assert.AreEqual("Erb", _target[1].Name);

            _source.Add(new Person("John", 12));

            Assert.AreEqual(2, _target.Count);

            _source.Add(new Person("Tim", 34));

            Assert.AreEqual(3, _target.Count);
            Assert.AreEqual("Tim", _target[2].Name);
        }
        public void ReplaceRangeOnFirst_Always_RaisesNotifyCollectionChangedWithRemoveActionsForEachItemReplacedAndOneAdd()
        {
            var continuousFirstCollection = new ContinuousCollection <Person>(_first.ToList());

            _target = new ExceptReadOnlyContinuousCollection <Person>(continuousFirstCollection, _second);

            var people = new List <Person> {
                new Person(), new Person()
            };

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousFirstCollection.ReplaceRange(0, people);

            Assert.AreEqual(3, eventArgsList.Count);

            TestUtilities.AssertRemove(eventArgsList[0], 0, _person1);
            TestUtilities.AssertRemove(eventArgsList[1], 0, _person2);

            TestUtilities.AssertAdd(eventArgsList[2], 0, people.ToArray());
        }
Esempio n. 14
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double ActualWidth  = 300;
            double ActualHeight = 270;

            ContinuousCollection <StockSaleTick> tickCollection =
                (ContinuousCollection <StockSaleTick>)value;

            if (tickCollection.Count == 0)
            {
                return(null);
            }

            double xConst = -tickCollection.First().TimeStamp.Ticks;
            double xScale = ActualWidth / (tickCollection.Last().TimeStamp.Ticks + xConst);

            double yMin   = Math.Min(PreviousClosingPoint, tickCollection.Min(t => t.Price) - 0.1);
            double yMax   = Math.Max(PreviousClosingPoint, tickCollection.Max(t => t.Price) + 0.1);
            double yConst = -yMax;
            double yScale = ActualHeight / (yMin + yConst);

            Func <double, double>       yConvert  = tickPrice => yScale * (tickPrice + yConst);
            Func <double, double>       xConvert  = tickTime => xScale * (tickTime + xConst);
            Func <StockSaleTick, Point> ptConvert = tick => new Point(xConvert(tick.TimeStamp.Ticks),
                                                                      yConvert(tick.Price));


            PointCollection points = new PointCollection();

            for (int i = 0; i < tickCollection.Count; i++)
            {
                Point pt = ptConvert(tickCollection[i]);
                points.Add(pt);
            }

            return(points);
        }
Esempio n. 15
0
        public void SmartFilterAdapter_OnAgeGreaterThan30_OnlyFiltersWhenTargetdPropertyChanges()
        {
            _source.Add(new Person("John", 12));
            _source.Add(new Person("Tim", 34));

            _target = from item in _source
                      where item.Age > 30
                      select item;

            bool wasCalled = false;

            _target.CollectionItemChanged += (sender, args) =>
            {
                wasCalled = true;
            };

            Assert.IsFalse(wasCalled);

            _source[0].Name = "Bob";
            Assert.IsFalse(wasCalled);

            _source[1].Age = 31;
            Assert.IsTrue(wasCalled);
        }
        public void Test()
        {
            // Collection with 1 item to make this test simple
            Items = new ContinuousCollection <NotifiableItem>
            {
                new NotifiableItem {
                    TestValue1 = 3, TestValue2 = 10
                },
            };

            // Start with TestValue1
            MaxValueCV = Items.ContinuousMax(item => item.TestValue1, value => Max = value);
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            Console.WriteLine("Max = " + Max);
            Console.WriteLine();

            // Switch to TestValue2
            MaxValueCV = Items.ContinuousMax(item => item.TestValue2, value => Max = value);
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            Console.WriteLine("Max = " + Max);
            Console.WriteLine();
            GC.Collect();
            WeakPropertyChangedEventManager.RemoveCollectedEntries();
            GC.Collect();
            // Now set TestValue1
            Items[0].TestValue1 = 20;
            Console.WriteLine("(BUG)");
            Console.WriteLine("MaxValueCV = " + MaxValueCV.CurrentValue);
            // BUG: Max is set to 20 when it should be 10
            Console.WriteLine("Max = " + Max);

            Assert.AreEqual(10, Max);

            Console.Write("Hit enter to continue...");
            Console.ReadLine();
        }
 protected void SetUp10PersonSource()
 {
     _source = new ContinuousCollection <Person>(ClinqTestFactory.CreateAnyPersonSource(10).ToList());
     setupTargetAndHandlers();
 }
 public void SetUp()
 {
     _target = new ContinuousCollection<Person>();
 }
 public void Initialize()
 {
     _list = new ContinuousCollection<PropertyChangedClass>
                   {
                       new PropertyChangedClass { DecimalTargetValue = 10, TargetValue = 10 },
                       new PropertyChangedClass { DecimalTargetValue = 23, TargetValue = 23 },
                       new PropertyChangedClass { DecimalTargetValue = null, TargetValue = null },
                       new PropertyChangedClass { DecimalTargetValue = 2, TargetValue = 2 },
                       new PropertyChangedClass { DecimalTargetValue = null, TargetValue = null },
                       new PropertyChangedClass { DecimalTargetValue = null, TargetValue = null },
                       new PropertyChangedClass { DecimalTargetValue = 1, TargetValue = 1 },
                   };
     _target = _list.AsReadOnly();
 }
Esempio n. 20
0
 public ModelRoot()
 {
     _allTransactions = new ContinuousCollection <Transaction>();
 }
        public void AddRangeToFirst_Always_RaisesNotifyCollectionChangedWithAddActionAndCorrectValues()
        {
            var continuousFirstCollection = new ContinuousCollection<Person>(_first.ToList());
            _target = new ExceptReadOnlyContinuousCollection<Person>(continuousFirstCollection, _second);

            var people = new List<Person> { new Person(), new Person() };

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousFirstCollection.AddRange(people);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 2, people.ToArray());
        }
        public void ReplaceRangeOnFirst_Always_RaisesNotifyCollectionChangedWithRemoveActionsForEachItemReplacedAndOneAdd()
        {
            var continuousFirstCollection = new ContinuousCollection<Person>(_first.ToList());
            _target = new ExceptReadOnlyContinuousCollection<Person>(continuousFirstCollection, _second);

            var people = new List<Person> { new Person(), new Person() };

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousFirstCollection.ReplaceRange(0, people);

            Assert.AreEqual(3, eventArgsList.Count);

            TestUtilities.AssertRemove(eventArgsList[0], 0, _person1);
            TestUtilities.AssertRemove(eventArgsList[1], 0, _person2);

            TestUtilities.AssertAdd(eventArgsList[2], 0, people.ToArray());
        }
Esempio n. 23
0
 public void SetUp()
 {
     _target = new ContinuousCollection <Person>();
 }
        public void AddRangeToSecond_Always_RaisesNotifyCollectionChangedWithRemoveActionAndCorrectValuesForEachItemRemoved()
        {
            var continuousSecondCollection = new ContinuousCollection<Person>();
            _target = new ExceptReadOnlyContinuousCollection<Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.AddRange(_first);

            Assert.AreEqual(2, eventArgsList.Count);

            TestUtilities.AssertRemove(eventArgsList[0], 0, _person1);
            TestUtilities.AssertRemove(eventArgsList[1], 0, _person2);
        }
        public void RemoveRangeFromFirst_Always_RaisesNotifyCollectionChangedWithAddActionAndCorrectValues2()
        {
            var continuousSecondCollection = new ContinuousCollection<Person>(_first.ToList());
            _target = new ExceptReadOnlyContinuousCollection<Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.RemoveRange(0, 2);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 0, _first.ToArray());
        }
        public void ReplaceRangeOnSecond_FirstContainsNewItems_RaisesNotifyCollectionChangedWithOneAddAndRemoveActionsForEachItemReplacedRemoved2()
        {
            var people = new List<Person> { new Person(), new Person() };

            _first = new ObservableCollection<Person> { _person1, _person2, people[0], people[1] };
            var continuousSecondCollection = new ContinuousCollection<Person> { _person1, _person2 };

            _target = new ExceptReadOnlyContinuousCollection<Person>(_first, continuousSecondCollection);

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            continuousSecondCollection.ReplaceRange(0, people);

            Assert.AreEqual(3, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 2, _person1, _person2);
            TestUtilities.AssertRemove(eventArgsList[1], 0, people[0]);
            TestUtilities.AssertRemove(eventArgsList[2], 0, people[1]);
        }
        public void GroupJoin()
        {
            Random rand = new Random();

            //_standardLinqResults = from outerPerson in _outer.AsEnumerable()
            //                       join innerPerson in _inner on outerPerson.Age equals innerPerson.Age into innersMatchingOuterAge
            //                       select new Pair<Person, IEnumerable<Person>>(outerPerson, innersMatchingOuterAge);
            Console.WriteLine("Ready");
            Console.ReadLine();

            int outerItems = 500;
            int innerItems = 7000;

            ContinuousCollection <NotifyingPerson> inner = new ContinuousCollection <NotifyingPerson>();
            ContinuousCollection <NotifyingPerson> outer = new ContinuousCollection <NotifyingPerson>();

            var clinqResults = from outerNotifyingPerson in outer
                               join innerNotifyingPerson in inner on outerNotifyingPerson.Age equals innerNotifyingPerson.Age into innersMatchingOuterAge
                               //select new KeyValuePair<NotifyingPerson, ReadOnlyContinuousCollection<NotifyingPerson>>(outerNotifyingPerson, innersMatchingOuterAge);
                               select innersMatchingOuterAge;

            TimeIt(1, () =>
            {
                //List<NotifyingPerson> innerPeople = new List<NotifyingPerson>();
                //for (int i = 0; i < innerItems; i++)
                //{
                //    innerPeople.Add(new NotifyingPerson(i.ToString(), i % outerItems));
                //}

                //inner.AddRange(innerPeople);

                for (int i = 0; i < innerItems; i++)
                {
                    inner.Add(new NotifyingPerson(i.ToString(), i % outerItems));
                }

                for (int i = 0; i < outerItems; i++)
                {
                    outer.Add(new NotifyingPerson(i.ToString(), i));
                }

                //for (int i = 0; i < outerItems; i++)
                //{
                //    outer.Move(rand.Next(outerItems), rand.Next(outerItems));
                //}

                //for (int i = outerItems - 1; i >= 0; i--)
                //{
                //    //if ((rand.Next() & 1) == 0)
                //    if(i % 2 == 0)
                //    {
                //        outer.RemoveAt(i);
                //    }
                //}

                //for (int i = 0; i < innerItems; i++)
                //{
                //    inner.Move(rand.Next(innerItems), rand.Next(innerItems));
                //}

                //for (int i = innerItems - 1; i >= 0; i--)
                //{
                //    if ((rand.Next() & 1) == 0)
                //    {
                //        inner.RemoveAt(i);
                //    }
                //}
            });

            Console.WriteLine(clinqResults.Count);
        }