示例#1
0
        public void TopX_Clear_CorrectResult()
        {
            INotifyCollection <Dummy <int> > collection = new NotifyCollection <Dummy <int> >();
            var top1 = new Dummy <int>(43);
            var top2 = new Dummy <int>(42);
            var top3 = new Dummy <int>(30);

            collection.Add(top1);
            collection.Add(top2);
            collection.Add(top3);
            collection.Add(new Dummy <int>(23));
            collection.Add(new Dummy <int>(6));

            var topEx = Observable.Expression(() => collection.TopX(3, d => d.Item));
            var top   = topEx.Value;

            Assert.AreEqual(top1, top[0].Key);
            Assert.AreEqual(top2, top[1].Key);
            Assert.AreEqual(top3, top[2].Key);
            Assert.AreEqual(3, top.Length);

            var changed = false;

            topEx.ValueChanged += (o, e) =>
            {
                Assert.IsNotNull(e.OldValue);
                Assert.IsNotNull(e.NewValue);
                changed = true;
            };

            collection.Clear();

            Assert.IsTrue(changed);
            Assert.AreEqual(0, topEx.Value.Length);
        }
示例#2
0
        public void LambdaNullableIntAverage_ObservableSourceReset_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <Dummy <int?> >()
            {
                1, 2, new Dummy <int?>(), 3
            };

            var test = Observable.Expression(() => coll.Average(d => d.Item));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
示例#3
0
        public void IntAverage_ObservableSourceReset_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                1, 2, 3
            };

            var test = Observable.Expression(() => coll.Average());

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
示例#4
0
        public void CountPredicate_ObservableSourceReset_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                1, 2, 3, -1, -3
            };

            var test = Observable.Expression(() => coll.WithUpdates().Count(i => i > 0));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
示例#5
0
        public void Distinct_ObservableSourceReset_Update()
        {
            var update = false;

            var coll = new NotifyCollection <int>()
            {
                1, 2, 2, 3
            };

            var test = coll.WithUpdates().Distinct();

            test.CollectionChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action);
            };

            coll.Clear();

            Assert.IsTrue(update);
            Assert.AreEqual(0, test.Count());
        }
示例#6
0
        public void GroupBy_ObservableSourceReset_Update()
        {
            var update = false;

            var coll = new NotifyCollection <int>()
            {
                1, 2, 3, 4, 5, 6
            };

            var test = coll.GroupBy(i => i % 3);

            test.CollectionChanged += (o, e) =>
            {
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action);
                update = true;
            };

            coll.Clear();

            Assert.IsTrue(update);
            Assert.AreEqual(0, test.Count());
        }
示例#7
0
        public void Contains_ObservableSourceReset_Update()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.WithUpdates().Contains(2));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
示例#8
0
        static void Main(string[] args)
        {
            Console.InputEncoding = Encoding.Unicode;
            Console.OutputEncoding = Encoding.Unicode;
            AverageAggregator averageAgg = new AverageAggregator
                (delegate (object sender, decimal oldAverage, decimal newAverage)
                {
                    Console.Write("--->Handler: ");
                    Console.WriteLine("Average changed from {0} to {1}.", oldAverage, newAverage);
                });

            Console.WriteLine("---AverageAggregator---");
            Console.WriteLine();

            Console.WriteLine("Adding number to aggregator: 2");
            averageAgg.AddNumber(2);
            Console.WriteLine("Adding number to aggregator: 2");
            averageAgg.AddNumber(2);
            Console.WriteLine("Adding number to aggregator: 8");
            averageAgg.AddNumber(8);
            Console.WriteLine("Adding number to aggregator: 4");
            averageAgg.AddNumber(4);
            Console.WriteLine("Adding number to aggregator: 4");
            averageAgg.AddNumber(4);
            Console.WriteLine("Adding number to aggregator: 4");
            averageAgg.AddNumber(4);
            Console.WriteLine("Adding number to aggregator: -24");
            averageAgg.AddNumber(-24);
            Console.WriteLine("Adding number to aggregator: 0");
            averageAgg.AddNumber(0);
            Console.WriteLine("Adding number to aggregator: 0");
            averageAgg.AddNumber(0);
            Console.WriteLine("Adding number to aggregator: 10");
            averageAgg.AddNumber(10);
            Console.WriteLine("Adding number to aggregator: 1");
            averageAgg.AddNumber(1);
            Console.WriteLine("Adding number to aggregator: 1");
            averageAgg.AddNumber(1);
            Console.WriteLine("Adding number to aggregator: 2");
            averageAgg.AddNumber(2);

            Console.WriteLine();
            Console.WriteLine("---NotifyCollection---");
            Console.WriteLine();

            NotifyCollection<Book> notCol = new NotifyCollection<Book>
                ((sender, changeType, changedItemIndex, changedItemInfo) =>
                {
                    Console.Write("--->Handler: ");
                    switch (changeType)
                    {
                        case ItemChangeType.Add:
                            Console.WriteLine("Added item to collection on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.Insert:
                            Console.WriteLine("Inserted item in collection on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.Remove:
                            if (changedItemIndex == -1) Console.WriteLine("Collection items cleared!");
                            else Console.WriteLine("Removed item from collection being on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.Replace:
                            Console.WriteLine("Replaced item in collection being on {0} index!", changedItemIndex);
                            break;
                        case ItemChangeType.ChangedProperty:
                            Console.WriteLine("Item on {0} index property {1} changed!", changedItemIndex, changedItemInfo);
                            break;
                        default:
                            break;
                    }
                });

            Book book1 = new Book("author1", "book1", 2000);
            Book book2 = new Book("author2", "book2", 2001);
            Book book3 = new Book("author3", "book3", 2002);
            Console.WriteLine("Adding {0}!", book1);
            notCol.Add(book1);
            Console.WriteLine("Adding {0}!", book2);
            notCol.Add(book2);
            Console.WriteLine("Inserting {0} on index 1!", book3);
            notCol.Insert(1, book3);
            Console.WriteLine("Changing {0} year to 2011!", book1);
            book1.Year = 2011;
            Console.WriteLine("Changing {0} year to 2005!", book3);
            book3.Year = 2005;
            Console.WriteLine("Removing {0}!", book2);
            notCol.Remove(book2);
            Console.WriteLine("Changing removed book year to 1995!");
            book2.Year = 1995;
            Console.WriteLine("Clearing all items!");
            notCol.Clear();
            Console.WriteLine("Adding {0}!", book1);
            notCol.Add(book1);
            Console.WriteLine("Adding {0}!", book2);
            notCol.Add(book2);
            Console.WriteLine("Replacing book on 0 index with {0}", book3);
            notCol[0] = book3;
            Console.WriteLine("Changing old book year to 1895!");
            book1.Year = 1895;
            Console.WriteLine("Changing new book year to 2003!");
            book3.Year = 2003;

            Console.WriteLine();
            Console.WriteLine("---Network Buffer---");

            ReceiveBuffer rec = new ReceiveBuffer(MessageReceivedHandle);
            PacketGenerator pg = new PacketGenerator(rec);
            Console.WriteLine("Write messages. Write exit for exit.");
            Console.Write("Message to send: ");
            string inputMessage = Console.ReadLine();
            while(!inputMessage.Equals("exit"))
            {
                pg.SendMessage(inputMessage);
                Console.Write("Message to send: ");
                inputMessage = Console.ReadLine();
            }
        }
示例#9
0
        public void Distinct_ObservableSourceReset_Update()
        {
            var update = false;

            var coll = new NotifyCollection<int>() { 1, 2, 2, 3 };

            var test = coll.WithUpdates().Distinct();

            test.CollectionChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action);
            };

            coll.Clear();

            Assert.IsTrue(update);
            Assert.AreEqual(0, test.Count());
        }
示例#10
0
文件: AvgTests.cs 项目: FrederikP/NMF
        public void LambdaNullableIntAverage_ObservableSourceReset_Update()
        {
            var update = false;
            var coll = new NotifyCollection<Dummy<int?>>() { 1, 2, new Dummy<int?>(), 3 };

            var test = Observable.Expression(() => coll.Average(d => d.Item));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
示例#11
0
        public void GroupBy_ObservableSourceReset_Update()
        {
            var update = false;

            var coll = new NotifyCollection<int>() { 1, 2, 3, 4, 5, 6 };

            var test = coll.GroupBy(i => i % 3);

            test.CollectionChanged += (o, e) =>
            {
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action);
                update = true;
            };

            coll.Clear();

            Assert.IsTrue(update);
            Assert.AreEqual(0, test.Count());
        }
示例#12
0
文件: AnyTest.cs 项目: FrederikP/NMF
        public void LambdaAny_ObservableSourceReset_Update()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.Any(i => i > 0));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }