Пример #1
0
        public void FirstOrDefault_WithPredicate()
        {
            ContinuousValue <Person> firstOverTen = _source.ContinuousFirstOrDefault(p => p.Age > 10);

            Assert.AreEqual(firstOverTen.CurrentValue.Name, "Jim");
            Assert.AreEqual(firstOverTen.CurrentValue.Age, 20);
        }
Пример #2
0
        public void FirstOrDefault_Test_GetFirstItem()
        {
            Person actualFirst = _source[0];
            ContinuousValue <Person> firstPerson = _source.ContinuousFirstOrDefault();

            Assert.AreEqual(actualFirst, firstPerson.CurrentValue);
        }
Пример #3
0
        public void SumIntegers_RemoveItemFromCollection_SumUpdated()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            _source.Remove(_source[0]);
            Assert.AreEqual(20, sum.CurrentValue);
        }
        public void ContinuousSumWithPausing()
        {
            Random rand = new Random();

            DateTime start = DateTime.Now;

            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            using (PausedAggregation pausedAggregation = new PausedAggregation())
            {
                int updateIndex = 0;
                for (int i = 0; i < 10000; i++)
                {
                    if (updateIndex >= _source.Count)
                    {
                        updateIndex = 0;
                    }

                    _source[updateIndex].Age++;
                    if (sum.CurrentValue <= 0)
                    {
                        throw new Exception();
                    }

                    updateIndex++;
                }
            }

            var duration = DateTime.Now - start;

            Console.WriteLine(duration.ToString());
        }
Пример #5
0
        public void FirstOrDefault_AfterEffect_Test()
        {
            int firstPersonsAge = 0;
            ContinuousValue <Person> firstPerson = _source.ContinuousFirstOrDefault(p => firstPersonsAge = p.Age);

            Assert.AreEqual(_source[0].Age, firstPersonsAge);
            Assert.AreEqual(firstPerson.CurrentValue.Age, firstPersonsAge);
        }
Пример #6
0
        public void SumIntegers_ChangeValueOfMonitoredPropertyCollection_SumUpdated()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            _source[0].Age++;

            Assert.AreEqual(31, sum.CurrentValue);
        }
        public void Count_AddingValueToCollection_CountUpdated()
        {
            ContinuousValue <int> count = _source.ContinuousCount();

            _source.Add(new Person());

            Assert.AreEqual(3, count.CurrentValue);
        }
Пример #8
0
        public void SumIntegers_MoveItemInCollection_SumTheSame()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            _source.Move(0, 1);

            Assert.AreEqual(30, sum.CurrentValue);
        }
        public void Contains_Test()
        {
            Person p = _source[0];
            ContinuousValue <bool> hasPerson = _source.ContinuousContains(p);

            Assert.IsTrue(hasPerson.CurrentValue);
            _source.Remove(p);
            Assert.IsFalse(hasPerson.CurrentValue);
        }
Пример #10
0
        public void FirstOrDefault_Predicate_WithChange()
        {
            ContinuousValue <Person> firstOverThirty = _source.ContinuousFirstOrDefault(p => p.Age > 30);

            Assert.IsNull(firstOverThirty.CurrentValue);
            _source[0].Age = 75;
            Assert.IsNotNull(firstOverThirty.CurrentValue);
            Assert.AreEqual(firstOverThirty.CurrentValue.Age, 75);
        }
Пример #11
0
        public void AddRange_Always_UpdatesContinuousValueCorrectly()
        {
            IEnumerable <Person> people = GetPeople();

            ContinuousValue <int> sum = _target.ContinuousSum(p => p.Age);

            _target.AddRange(people);

            Assert.AreEqual(55, sum.CurrentValue);
        }
        public void Count_AddingValueToCollection_AfterEffect()
        {
            int modCount = 0;
            ContinuousValue <int> count = _source.ContinuousCount(c => modCount = c);

            _source.Add(new Person());

            Assert.AreEqual(3, count.CurrentValue);
            Assert.AreEqual(modCount, count.CurrentValue);
        }
Пример #13
0
        public void SumIntegers_ReplaceItemInCollection_SumUpdated()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            _source[0] = new Person()
            {
                Age = 50
            };
            Assert.AreEqual(70, sum.CurrentValue);
        }
Пример #14
0
        public void SumIntegers_AddItemToCollection_SumUpdated()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            _source.Add(new Person()
            {
                Age = 10
            });
            Assert.AreEqual(40, sum.CurrentValue);
        }
Пример #15
0
    public MyParent()
    {
        _MyChildren = new ObservableCollection <MyChild>();

        // Creat the ContinuousFirstOrDefault to watch the MyChildren collection.
        // This will monitor for newly added instances,
        // as well as changes to the "IsChanged" property on
        // instances already in the collection.
        _ContinuousIsChanged = MyChildren.ContinuousFirstOrDefault(child => child.IsChanged);
        _ContinuousIsChanged.PropertyChanged += (s, e) => RaiseChanged("IsChanged");
    }
        public void Contains_Test_AfterEffect()
        {
            Person p        = _source[0];
            bool   personAE = false;
            ContinuousValue <bool> hasPerson = _source.ContinuousContains(p, val => personAE = val);

            Assert.IsTrue(hasPerson.CurrentValue);
            Assert.IsTrue(personAE);
            _source.Remove(p);
            Assert.IsFalse(hasPerson.CurrentValue);
            Assert.IsFalse(personAE);
        }
Пример #17
0
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         ContinuousValue <double> cv = (ContinuousValue <double>)value;
         double d = cv.CurrentValue;
         return(string.Format("{0:C}", d));
     }
     else
     {
         return(string.Empty);
     }
 }
Пример #18
0
        public void FirstOrDefault_Predicate_AfterEffect()
        {
            string overThirtyName = null;
            ContinuousValue <Person> firstOverThirty = _source.ContinuousFirstOrDefault(
                p => p.Age > 30,
                p => overThirtyName = (p == null) ? "Nobody" : p.Name);

            Assert.IsNull(firstOverThirty.CurrentValue);
            Assert.AreEqual(overThirtyName, "Nobody");
            _source[0].Age = 75;
            Assert.IsNotNull(firstOverThirty.CurrentValue);
            Assert.AreEqual(firstOverThirty.CurrentValue.Name, overThirtyName);
        }
Пример #19
0
        public void FirstOrDefault_GetFirstItemAfterMove()
        {
            Person newFirst = new Person()
            {
                Age = 40, Name = "New"
            };

            ContinuousValue <Person> firstPerson = _source.ContinuousFirstOrDefault();

            _source.Insert(0, newFirst);

            Assert.AreEqual(newFirst, firstPerson.CurrentValue);
        }
Пример #20
0
        public void ReplaceRange_Always_UpdatesContinuousValueCorrectly()
        {
            IEnumerable <Person> people = GetPeople();

            _target.AddRange(people);

            ContinuousValue <int> sum = _target.ContinuousSum(p => p.Age);

            var peopleAgeOne = GetPeopleWithAge(1);

            _target.ReplaceRange(0, peopleAgeOne);

            Assert.AreEqual(10, sum.CurrentValue);
        }
Пример #21
0
        public void SumIntegers_ChangeValueOfMonitoredPropertyCollection_PropertyChangedEventFires()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);
            int callCount             = 0;

            sum.PropertyChanged += (sender, args) =>
            {
                callCount++;
                Assert.AreEqual("CurrentValue", args.PropertyName);
            };

            _source[0].Age++;

            Assert.AreEqual(1, callCount);
        }
Пример #22
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 PauseAggregation_PropertyChangedInCollection_ValueUpdatedAfterUsingBlockExits()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            Assert.AreEqual(30, sum.CurrentValue);

            int callCount = 0;

            sum.PropertyChanged += (sender, args) => callCount++;

            using (PausedAggregation pausedAggregation = new PausedAggregation())
            {
                _source[0].Age = 1000;
                Assert.AreEqual(0, callCount);
            }

            Assert.AreEqual(1, callCount);
        }
Пример #24
0
        public ModelRoot()
        {
            _allTransactions = new ObservableCollection <StockTransaction>();

            // Note that all of these queries are defined against an EMPTY
            // source collection...
            _bids = from tx in _allTransactions
                    where tx.TransactionType == TransactionType.Bid &&
                    tx.Symbol == "AAPL"
                    orderby tx.Price ascending
                    select tx;

            _asks = from tx in _allTransactions
                    where tx.TransactionType == TransactionType.Ask &&
                    tx.Symbol == "AAPL"
                    orderby tx.Price descending
                    select tx;

            _executions = from tx in _allTransactions
                          where tx.TransactionType == TransactionType.Execution &&
                          tx.Symbol == "AAPL"
                          orderby tx.Price descending
                          select tx;

            _graphExecutions = from tx in _executions
                               where tx.TimeStamp >= DateTime.Now.AddMinutes(-5)
                               select tx;

            _minPrice = _executions.ContinuousMin(tx => tx.Price,
                                                  newPrice => this.CurrentMin = newPrice);
            _maxPrice = _executions.ContinuousMax(tx => tx.Price,
                                                  newPrice => this.CurrentMax = newPrice);

            _vwap = _executions.ContinuousVwap(tx => tx.Price, tx => tx.Quantity,
                                               newVwap => this.CurrentVwap = newVwap);

            _simulationTimer          = new Timer(1000);
            _simulationTimer.Elapsed += GenerateBogusData;
            _simulationTimer.Start();
        }
        public void ContinuousMax_IfNullableDecimal_TreatsNullsAsZero()
        {
            ContinuousValue <decimal> value = _target.ContinuousMax(item => item.DecimalTargetValue);

            Assert.AreEqual(23, value.CurrentValue);
        }
        public void Count_ImmediatelyAfterConstruction_SumCompleted()
        {
            ContinuousValue <int> count = _source.ContinuousCount();

            Assert.AreEqual(2, count.CurrentValue);
        }
        public void ContinuousMin_IfNullableDecimal_ReturnsMinValueThatIsNotNull()
        {
            ContinuousValue <decimal> value = _target.ContinuousMin(item => item.DecimalTargetValue);

            Assert.AreEqual(1, value.CurrentValue);
        }
Пример #28
0
        public void SumIntegers_ImmediatelyAfterConstruction_SumCompleted()
        {
            ContinuousValue <int> sum = _source.ContinuousSum(p => p.Age);

            Assert.AreEqual(30, sum.CurrentValue);
        }