public void TakeWithInsufficientData()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Take(4);

            ProduceAndCheck(subject, result, new[] { 3, 10 }, new[] { 3, 10 });
        }
        public void WhereWithCondition()
        {
            DataProducer <int> subject = new DataProducer <int>();

            ProduceAndCheck(subject, subject.Where((x, index) => x > index),
                            new[] { 0, 3, 1, 4, 5, 2 }, new[] { 3, 4, 5 });
        }
Ejemplo n.º 3
0
        public void GroupByWithElementProjection()
        {
            DataProducer <string> producer = new DataProducer <string>();

            var query = producer.GroupBy(word => word[0], word => word + word.Length)
                        .Select(group => new { group.Key, Words = group.AsFutureEnumerable() })
                        .AsFutureEnumerable();

            producer.ProduceAndEnd("One", "Two", "Three", "Four", "Five", "Six", "Seven", "others");

            var results = query.Value.ToList();

            Assert.AreEqual(5, results.Count);
            Assert.AreEqual('O', results[0].Key);
            Assert.IsTrue(results[0].Words.Value.SequenceEqual(new[] { "One3" }));

            Assert.AreEqual('T', results[1].Key);
            Assert.IsTrue(results[1].Words.Value.SequenceEqual(new[] { "Two3", "Three5" }));

            Assert.AreEqual('F', results[2].Key);
            Assert.IsTrue(results[2].Words.Value.SequenceEqual(new[] { "Four4", "Five4" }));

            Assert.AreEqual('S', results[3].Key);
            Assert.IsTrue(results[3].Words.Value.SequenceEqual(new[] { "Six3", "Seven5" }));

            Assert.AreEqual('o', results[4].Key);
            Assert.IsTrue(results[4].Words.Value.SequenceEqual(new[] { "others6" }));
        }
Ejemplo n.º 4
0
        public void ShouldProduceValuesForIdentityColumns()
        {
            ValueStore    vs       = new ValueStore();
            DataProducer  producer = new DataProducer(vs);
            DataRowEntity row      = producer.ProduceRow(customerTable, 1);

            // check that the value of the identity column have not been generated
            Assert.That(vs.GetByKey(row.Fields[0].KeyValue), Is.Null);

            IDataConsumer consumer = GetImplementedType();

            if (consumer.Init("", options))
            {
                int counter = 0;
                consumer.ReportInsertionCallback = new Action(() =>
                {
                    counter++;
                });
                consumer.Consume(new List <DataRowEntity> {
                    row
                }, vs);

                // now assert that the identity value have been generated by the consumer
                Assert.That(row.Fields[0].FieldName, Is.EqualTo("CustomerId"), "Column should be customerID");
                Assert.That(vs.GetByKey(row.Fields[0].KeyValue), Is.Not.Null, consumer.GetType().ToString());
            }
        }
        public void SkipWithZeroCount()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Skip(0);

            ProduceAndCheck(subject, result, new[] { 3, 10, 5, 7, 2, 8 }, new[] { 3, 10, 5, 7, 2, 8 });
        }
Ejemplo n.º 6
0
        public void GroupByWithElementProjectionAndResultProjection()
        {
            DataProducer <string> producer = new DataProducer <string>();

            var query = producer.GroupBy(word => word[0].ToString(),
                                         word => word + word,
                                         (key, words) => new { Key = key, MaxLength = words.Max(word => word.Length) })
                        .AsFutureEnumerable();

            producer.ProduceAndEnd("One", "Two", "Three", "Four", "Five", "Six", "Seven", "others");

            var results = query.Value.ToList();

            Assert.AreEqual(5, results.Count);
            Assert.AreEqual("O", results[0].Key);
            Assert.AreEqual(6, results[0].MaxLength.Value);

            Assert.AreEqual("T", results[1].Key);
            Assert.AreEqual(10, results[1].MaxLength.Value);

            Assert.AreEqual("F", results[2].Key);
            Assert.AreEqual(8, results[2].MaxLength.Value);

            Assert.AreEqual("S", results[3].Key);
            Assert.AreEqual(10, results[3].MaxLength.Value);

            Assert.AreEqual("o", results[4].Key);
            Assert.AreEqual(12, results[4].MaxLength.Value);
        }
Ejemplo n.º 7
0
        void ProduceAndCheck <T>(DataProducer <T> source, IDataProducer <T> result, T[] inputData, T[] expectedOutput)
        {
            IEnumerable <T> enumerable = result.AsEnumerable();

            source.ProduceAndEnd(inputData);
            Assert.IsTrue(expectedOutput.SequenceEqual(enumerable));
        }
        public void TakeWhileAndConditionMetInSequenceWithIndex()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.TakeWhile((x, index) => x > index);

            ProduceAndCheck(subject, result, new[] { 3, 4, 10, 2, 3 }, new[] { 3, 4, 10 });
        }
        /// <summary>
        /// Returns a data-producer that will yield a specified number of
        /// contiguous elements from the start of a sequence - i.e.
        /// "the first &lt;x&gt; elements".
        /// </summary>
        /// <param name="source">The source data-producer</param>
        /// <param name="count">The maximum number of elements to return</param>
        public static IDataProducer <TSource> Take <TSource>(this IDataProducer <TSource> source, int count)
        {
            source.ThrowIfNull("source");

            DataProducer <TSource> ret = new DataProducer <TSource>();

            Action           completion = () => ret.End();
            Action <TSource> production = null;

            production = value =>
            {
                if (count > 0)
                {
                    ret.Produce(value);
                    count--;
                }
                if (count <= 0)
                {
                    source.EndOfData    -= completion;
                    source.DataProduced -= production;
                    ret.End();
                }
            };

            source.DataProduced += production;
            source.EndOfData    += completion;
            return(ret);
        }
Ejemplo n.º 10
0
        public void GroupByWithElementProjection()
        {
            DataProducer<string> producer = new DataProducer<string>();

            var query = producer.GroupBy(word => word[0], word => word + word.Length)
                                .Select(group => new { group.Key, Words = group.AsFutureEnumerable() })
                                .AsFutureEnumerable();

            producer.ProduceAndEnd("One", "Two", "Three", "Four", "Five", "Six", "Seven", "others");

            var results = query.Value.ToList();
            Assert.AreEqual(5, results.Count);
            Assert.AreEqual('O', results[0].Key);
            Assert.IsTrue(results[0].Words.Value.SequenceEqual(new[] { "One3" }));

            Assert.AreEqual('T', results[1].Key);
            Assert.IsTrue(results[1].Words.Value.SequenceEqual(new[] { "Two3", "Three5" }));

            Assert.AreEqual('F', results[2].Key);
            Assert.IsTrue(results[2].Words.Value.SequenceEqual(new[] { "Four4", "Five4" }));

            Assert.AreEqual('S', results[3].Key);
            Assert.IsTrue(results[3].Words.Value.SequenceEqual(new[] { "Six3", "Seven5" }));

            Assert.AreEqual('o', results[4].Key);
            Assert.IsTrue(results[4].Words.Value.SequenceEqual(new[] { "others6" }));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns a data-producer that will yield
        /// elements a sequence as long as a condition
        /// (involving the element's index in the sequence)
        /// is satsified; when the condition fails for an element,
        /// that element and all subsequent elements are ignored.
        /// </summary>
        /// <param name="source">The source data-producer</param>
        /// <param name="predicate">The condition to yield elements</param>
        public static IDataProducer <TSource> TakeWhile <TSource>(this IDataProducer <TSource> source, DotNet20.Func <TSource, int, bool> predicate)
        {
            source.ThrowIfNull("source");
            predicate.ThrowIfNull("predicate");

            DataProducer <TSource> ret  = new DataProducer <TSource>();
            Action           completion = () => ret.End();
            Action <TSource> production = null;

            int index = 0;

            production = value =>
            {
                if (!predicate(value, index++))
                {
                    ret.End();
                    source.DataProduced -= production;
                    source.EndOfData    -= completion;
                }
                else
                {
                    ret.Produce(value);
                }
            };

            source.DataProduced += production;
            source.EndOfData    += completion;
            return(ret);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns a data-producer that will ignore the
        /// elements from the start of a sequence while a condition
        /// (involving the elements's index in the sequence)
        /// is satsified; when the condition fails for an element,
        /// that element and all subsequent elements are yielded.
        /// </summary>
        /// <param name="source">The source data-producer</param>
        /// <param name="predicate">The condition to skip elements</param>
        public static IDataProducer <TSource> SkipWhile <TSource>(this IDataProducer <TSource> source, DotNet20.Func <TSource, int, bool> predicate)
        {
            source.ThrowIfNull("source");
            predicate.ThrowIfNull("predicate");

            DataProducer <TSource> ret = new DataProducer <TSource>();
            Action completion          = () => ret.End();

            bool skipping = true;
            int  index    = 0;

            source.DataProduced += value =>
            {
                if (skipping)
                {
                    skipping = predicate(value, index++);
                }
                // Note - not an else clause!
                if (!skipping)
                {
                    ret.Produce(value);
                }
            };
            source.EndOfData += completion;
            return(ret);
        }
 public void LongCount()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<long> count = subject.LongCount();
     subject.ProduceAndEnd("a", "b", "c", "d");
     Assert.AreEqual(4L, count.Value);
 }
        public void DefaultIfEmptyWithoutData()
        {
            DataProducer <string>  subject = new DataProducer <string>();
            IDataProducer <string> result  = subject.DefaultIfEmpty();

            ProduceAndCheck(subject, result, new string[0], new string[] { null });
        }
 public void LongCountWithFilter()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<long> count = subject.LongCount(x => x.Length >= 2);
     subject.ProduceAndEnd("a", "bbb", "cc", "d");
     Assert.AreEqual(2L, count.Value);
 }
Ejemplo n.º 16
0
        public void ShouldUseSameValueWhenUsingIdentityFromOtherColumn()
        {
            ValueStore valuestore = new ValueStore();
            var        dp         = new DataProducer(valuestore);

            var tables = new List <ExecutionTable>();

            tables.Add(new ExecutionTable(customerTable, 1));
            tables.Add(new ExecutionTable(orderTable, 2));

            List <DataRowEntity> rows = new List <DataRowEntity>();
            long n = 1L;

            rows.AddRange(dp.ProduceRows(tables));
            Assert.That(rows.Count, Is.EqualTo(2));
            var customerRow = rows[0];
            var orderRow    = rows[1];

            Assert.That(customerRow.Fields.Count, Is.EqualTo(4));
            Assert.That(orderRow.Fields.Count, Is.EqualTo(4));

            Assert.That(orderRow.Fields[1].FieldName, Is.EqualTo("CustomerId"));
            Assert.That(customerRow.Fields[0].FieldName, Is.EqualTo("CustomerId"));

            // Check key is the same as it is for the CustomerId column in CustomerRow
            Assert.That(orderRow.Fields[1].KeyValue, Is.EqualTo(customerRow.Fields[0].KeyValue));
        }
        public void SelectWithIndex()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Select((x, index) => x * 5 + index);

            ProduceAndCheck(subject, result, new[] { 3, 10, 5 }, new[] { 15, 51, 27 });
        }
        public void TakeWhileAndConditionMetInSequence()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.TakeWhile(x => x < 5);

            ProduceAndCheck(subject, result, new[] { 3, 4, 10, 2, 3 }, new[] { 3, 4 });
        }
        public void Select()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Select(x => x * 5);

            ProduceAndCheck(subject, result, new[] { 3, 10, 5 }, new[] { 15, 50, 25 });
        }
        public void TakeWithZeroCount()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Take(0);

            ProduceAndCheck(subject, result, new[] { 3, 10 }, new int[0]);
        }
        public void DefaultIfEmptyWithoutDataButWithDefaultReplacement()
        {
            DataProducer <string>  subject = new DataProducer <string>();
            IDataProducer <string> result  = subject.DefaultIfEmpty("foo");

            ProduceAndCheck(subject, result, new string[0], new string[] { "foo" });
        }
Ejemplo n.º 22
0
        public void GroupByWithResultProjectionAndElementProjectionAndComparer()
        {
            DataProducer <string> producer = new DataProducer <string>();

            var query = producer.GroupBy(word => word[0].ToString(),
                                         word => word + word,
                                         (key, words) => new { Key = key, MaxLength = words.Max(word => word.Length) },
                                         StringComparer.OrdinalIgnoreCase)
                        .AsFutureEnumerable();

            producer.ProduceAndEnd("one", "Two", "three", "Four", "Five", "six", "seven", "Others");

            var results = query.Value.ToList();

            Assert.AreEqual(4, results.Count);
            Assert.AreEqual("o", results[0].Key);
            Assert.AreEqual(12, results[0].MaxLength.Value);

            Assert.AreEqual("T", results[1].Key);
            Assert.AreEqual(10, results[1].MaxLength.Value);

            Assert.AreEqual("F", results[2].Key);
            Assert.AreEqual(8, results[2].MaxLength.Value);

            Assert.AreEqual("s", results[3].Key);
            Assert.AreEqual(10, results[3].MaxLength.Value);
        }
        public void DefaultIfEmptyWithDataAndDefaultReplacement()
        {
            DataProducer <string>  subject = new DataProducer <string>();
            IDataProducer <string> result  = subject.DefaultIfEmpty("foo");

            ProduceAndCheck(subject, result, new[] { "a", "b", "c" }, new[] { "a", "b", "c" });
        }
Ejemplo n.º 24
0
        public void GroupByWithComparerAndElementProjection()
        {
            DataProducer <string> producer = new DataProducer <string>();

            var query = producer.GroupBy(word => word[0].ToString(), word => word + word.Length, StringComparer.OrdinalIgnoreCase)
                        .Select(group => new { group.Key, Words = group.AsFutureEnumerable() })
                        .AsFutureEnumerable();

            producer.ProduceAndEnd("one", "Two", "three", "Four", "Five", "six", "seven", "Others");

            var results = query.Value.ToList();

            Assert.AreEqual(4, results.Count);
            Assert.AreEqual("o", results[0].Key);
            Assert.IsTrue(results[0].Words.Value.SequenceEqual(new[] { "one3", "Others6" }));

            Assert.AreEqual("T", results[1].Key);
            Assert.IsTrue(results[1].Words.Value.SequenceEqual(new[] { "Two3", "three5" }));

            Assert.AreEqual("F", results[2].Key);
            Assert.IsTrue(results[2].Words.Value.SequenceEqual(new[] { "Four4", "Five4" }));

            Assert.AreEqual("s", results[3].Key);
            Assert.IsTrue(results[3].Words.Value.SequenceEqual(new[] { "six3", "seven5" }));
        }
        public void PumpWithBufferingRequired()
        {
            // This will keep track of how many we've consumed already
            int consumed = 0;

            DataProducer <int>  producer = new DataProducer <int>();
            IDataProducer <int> ordered  = producer.OrderBy(x => x);
            var selected = ordered.Select(x => new { X = x, Consumed = consumed });

            int[] data = new int[] { 1, 0, 4, 2, 3, 5 };

            var results = producer.PumpProduceAndEnd(data, selected);
            int count   = 0;

            foreach (var result in results)
            {
                Assert.AreEqual(count, result.X);
                count++;
                // Nothing will be yielded until we end everything, at which point
                // everything will have been buffered internally before we can increment Consumed
                Assert.AreEqual(0, result.Consumed);
                consumed++;
            }
            Assert.AreEqual(count, 6);
        }
        public void SkipWithInsufficientData()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Skip(4);

            ProduceAndCheck(subject, result, new[] { 3, 10 }, new int[0]);
        }
        public void TakeWhileAndConditionAlwaysMet()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.TakeWhile(x => x < 100);

            ProduceAndCheck(subject, result, new[] { 3, 4, 10, 2, 3 }, new[] { 3, 4, 10, 2, 3 });
        }
        public void SkipWithEnoughData()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.Skip(4);

            ProduceAndCheck(subject, result, new[] { 3, 10, 5, 7, 2, 8 }, new[] { 2, 8 });
        }
        public void TakeWhileAndConditionNeverMet()
        {
            DataProducer <int>  subject = new DataProducer <int>();
            IDataProducer <int> result  = subject.TakeWhile(x => x > 10);

            ProduceAndCheck(subject, result, new[] { 3, 4, 10, 2, 3 }, new int[0]);
        }
Ejemplo n.º 30
0
        public void ShouldProduceDataForAllTables()
        {
            ValueStore valuestore = new ValueStore();
            var        dp         = new DataProducer(valuestore);

            var tables = new List <ExecutionTable>();

            tables.Add(new ExecutionTable(customerTable, 1));
            tables.Add(new ExecutionTable(orderTable, 2));

            List <DataRowEntity> rows = new List <DataRowEntity>();

            rows.AddRange(dp.ProduceRows(tables));
            Assert.That(rows.Count, Is.EqualTo(2));

            Assert.That(rows[0].Fields.Count, Is.EqualTo(4));
            AssertFieldsInRowHaveSomeValues(valuestore, rows[0], 2);

            // simulate consuming and producing the identity value of CustomerId
            // this will cause the Order table to have a value for its CustomerId column
            valuestore.Put(rows[0].Fields[0].KeyValue, 1);

            Assert.That(rows[1].Fields.Count, Is.EqualTo(4));

            AssertFieldsInRowHaveSomeValues(valuestore, rows[1], 0);
        }
Ejemplo n.º 31
0
        public void ShouldInsertLotsOfRows()
        {
            prepareTables();

            using (SQLDataProducer.DataConsumers.DataToMSSSQLInsertionConsumer.InsertConsumer consumer = new DataConsumers.DataToMSSSQLInsertionConsumer.InsertConsumer())
            {
                var          valueStore = new ValueStore();
                DataProducer producer   = new DataProducer(valueStore);

                consumer.Init(connectionString, new Dictionary <string, string>());
                int rowCount = 0;
                consumer.ReportInsertionCallback = new Action(() =>
                {
                    rowCount++;
                });

                for (int i = 0; i < 150; i++)
                {
                    consumer.Consume(producer.ProduceRows(new List <ExecutionTable> {
                        new ExecutionTable(customerTable, 1), new ExecutionTable(orderTable, 2)
                    }), valueStore);
                }

                Assert.That(rowCount, Is.EqualTo(300));
            }

            verifyRowCount("Customer", 150);
            verifyRowCount("Orders", 150);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Groups and executes a pipeline for two results per group
        /// </summary>
        public static IEnumerable <KeyValueTuple <TKey, TResult1, TResult2> > GroupWithPipeline <TElement, TKey, TResult1, TResult2>
            (this IEnumerable <TElement> source,
            Func <TElement, TKey> keySelector,
            IEqualityComparer <TKey> comparer,
            Func <IDataProducer <TElement>, IFuture <TResult1> > pipeline1,
            Func <IDataProducer <TElement>, IFuture <TResult2> > pipeline2)
        {
            var keyMap  = new Dictionary <TKey, DataProducer <TElement> >(comparer);
            var results = new List <KeyValueTuple <TKey, IFuture <TResult1>, IFuture <TResult2> > >();

            foreach (TElement element in source)
            {
                TKey key = keySelector(element);
                DataProducer <TElement> producer;
                if (!keyMap.TryGetValue(key, out producer))
                {
                    producer    = new DataProducer <TElement>();
                    keyMap[key] = producer;
                    results.Add(new KeyValueTuple <TKey, IFuture <TResult1>, IFuture <TResult2> >(key, pipeline1(producer), pipeline2(producer)));
                }
                producer.Produce(element);
            }

            foreach (var producer in keyMap.Values)
            {
                producer.End();
            }

            foreach (var result in results)
            {
                yield return(new KeyValueTuple <TKey, TResult1, TResult2>(result.Key, result.Value1.Value, result.Value2.Value));
            }
        }
Ejemplo n.º 33
0
        public void MaxNullableInt32WithProjectionNoElements()
        {
            DataProducer <int?> subject = new DataProducer <int?>();
            IFuture <int?>      result  = subject.Max(x => - x);

            subject.End();
            Assert.IsNull(result.Value);
        }
 public void CountWithNulls()
 {
     int?[] data = { 1, null, 4, null, 3, null, 2 };
     DataProducer<int?> subject = new DataProducer<int?>();
     IFuture<int> count = subject.Count();
     subject.ProduceAndEnd(data);
     Assert.AreEqual(data.Length, count.Value);
     Assert.AreEqual(7, count.Value); // to be sure...
 }
Ejemplo n.º 35
0
        public void JustEnd()
        {
            DataProducer<string> subject = new DataProducer<string>();
            bool endReached = false;

            subject.DataProduced += val => { throw new Exception(); };
            subject.EndOfData += () => endReached = true;

            subject.End();
            Assert.IsTrue(endReached);
        }
Ejemplo n.º 36
0
        public void EndWithinEnd()
        {
            DataProducer<string> subject = new DataProducer<string>();
            subject.EndOfData += () => { subject.End(); };

            try
            {
                subject.End();
            }
            catch (InvalidOperationException)
            {
                // Expected
            }
        }
Ejemplo n.º 37
0
        public void EndTwice()
        {
            DataProducer<string> subject = new DataProducer<string>();
            subject.End();

            try
            {
                subject.End();
                Assert.Fail("Expected exception");
            }
            catch (InvalidOperationException)
            {
                // Expected
            }
        }
Ejemplo n.º 38
0
        public void EventHooks()
        {
            var producer = new DataProducer<int>();
            var grp = new ProducerGrouping<int, int>(5, producer);
            Action<int> act = x => { };
            Action end = () => { };
            IFuture<int> sum = grp.Sum();
            grp.DataProduced += act;
            grp.EndOfData += end;
            producer.ProduceAndEnd(1, 2, 3);
            grp.DataProduced -= act;
            grp.EndOfData -= end;
            Assert.AreEqual(6, sum.Value);

        }
        public void AggregateNoSeed()
        {
            string sentence = "the quick brown fox jumps over the lazy dog";

            // Split the string into individual words.
            string[] words = sentence.Split(' ');

            DataProducer<string> subject = new DataProducer<string>();

            // Prepend each word to the beginning of the 
            // new sentence to reverse the word order.
            IFuture<string> reversed = subject.Aggregate((workingSentence, next) => next + " " + workingSentence);

            subject.ProduceAndEnd(words);

            Assert.AreEqual("dog lazy the over jumps fox brown quick the", reversed.Value);
        }
Ejemplo n.º 40
0
        public void ValueThenEnd()
        {
            DataProducer<string> subject = new DataProducer<string>();
            string pushed = null;
            bool endReached = false;

            subject.DataProduced += val => pushed = val;
            subject.EndOfData += () => endReached = true;

            Assert.IsFalse(endReached);
            Assert.IsNull(pushed);

            subject.Produce("foo");
            Assert.IsFalse(endReached);
            Assert.AreEqual("foo", pushed);

            subject.End();
            Assert.IsTrue(endReached);
        }
Ejemplo n.º 41
0
        public void GroupByWithComparer()
        {
            DataProducer<string> producer = new DataProducer<string>();

            var query = producer.GroupBy(word => word[0].ToString(), StringComparer.OrdinalIgnoreCase)
                                .Select(group => new { group.Key, Words = group.AsFutureEnumerable() })
                                .AsFutureEnumerable();

            producer.ProduceAndEnd("one", "Two", "three", "Four", "Five", "six", "seven", "Others");

            var results = query.Value.ToList();
            Assert.AreEqual(4, results.Count);
            Assert.AreEqual("o", results[0].Key);
            Assert.IsTrue(results[0].Words.Value.SequenceEqual(new[] { "one", "Others" }));

            Assert.AreEqual("T", results[1].Key);
            Assert.IsTrue(results[1].Words.Value.SequenceEqual(new[] { "Two", "three" }));

            Assert.AreEqual("F", results[2].Key);
            Assert.IsTrue(results[2].Words.Value.SequenceEqual(new[] { "Four", "Five" }));

            Assert.AreEqual("s", results[3].Key);
            Assert.IsTrue(results[3].Words.Value.SequenceEqual(new[] { "six", "seven" }));
        }
 public void ElementAtOrDefaultOutsideRange()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<string> result = subject.ElementAtOrDefault(5);
     subject.ProduceAndEnd("zero", "one", "two", "three", "four");
     Assert.IsNull(result.Value);
 }
 public void AllNoData()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.All(x => x.Length < 5);
     subject.End();
     Assert.IsTrue(result.Value);
 }
 public void SingleOrDefaultNoMatchingData()
 {
     DataProducer<int> subject = new DataProducer<int>();
     IFuture<int> single = subject.SingleOrDefault(x => x > 5);
     subject.ProduceAndEnd(1, 2, 3);
     Assert.AreEqual(0, single.Value);
 }
 public void SingleOrDefaultWithSingleMatchingElement()
 {
     DataProducer<int> subject = new DataProducer<int>();
     IFuture<int> single = subject.SingleOrDefault(x => x % 10 == 0);
     subject.ProduceAndEnd(5, 10, 15);
     Assert.AreEqual(10, single.Value);
 }
Ejemplo n.º 46
0
        public void GroupByWithElementProjectionAndResultProjection()
        {
            DataProducer<string> producer = new DataProducer<string>();

            var query = producer.GroupBy(word => word[0].ToString(),
                                         word => word + word,
                                         (key, words) => new { Key = key, MaxLength = words.Max(word => word.Length) })
                                .AsFutureEnumerable();

            producer.ProduceAndEnd("One", "Two", "Three", "Four", "Five", "Six", "Seven", "others");

            var results = query.Value.ToList();
            Assert.AreEqual(5, results.Count);
            Assert.AreEqual("O", results[0].Key);
            Assert.AreEqual(6, results[0].MaxLength.Value);

            Assert.AreEqual("T", results[1].Key);
            Assert.AreEqual(10, results[1].MaxLength.Value);

            Assert.AreEqual("F", results[2].Key);
            Assert.AreEqual(8, results[2].MaxLength.Value);

            Assert.AreEqual("S", results[3].Key);
            Assert.AreEqual(10, results[3].MaxLength.Value);

            Assert.AreEqual("o", results[4].Key);
            Assert.AreEqual(12, results[4].MaxLength.Value);
        }
 public void ContainsWithComparerWithMatch()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.Contains("FOUR", StringComparer.OrdinalIgnoreCase);
     subject.ProduceAndEnd("zero", "one", "two", "three", "four");
     Assert.IsTrue(result.Value);
 }
        public void AggregateWithSeed()
        {
            int[] ints = { 4, 8, 8, 3, 9, 0, 7, 8, 2 };

            DataProducer<int> subject = new DataProducer<int>();

            // Count the even numbers in the array, using a seed value of 0.
            IFuture<int> result = subject.Aggregate
                (0,
                 (total, next) => next % 2 == 0 ? total + 1 : total);

            subject.ProduceAndEnd(ints);
            Assert.AreEqual(6, result.Value);
        }
 public void ElementAtOrDefaultWithinRange()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<string> result = subject.ElementAtOrDefault(2);
     subject.ProduceAndEnd("zero", "one", "two", "three", "four");
     Assert.AreEqual("two", result.Value);
 }
 public void ContainsNoComparerNoMatch()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.Contains("FOUR");
     subject.ProduceAndEnd("zero", "one", "two", "three", "four");
     Assert.IsFalse(result.Value);
 }
 public void ElementAtOutsideRange()
 {
     DataProducer<string> subject = new DataProducer<string>();
     subject.ElementAt(5);
     subject.Produce("zero");
     subject.Produce("one");
     subject.Produce("two");
     subject.Produce("three");
     try
     {
         subject.End();
         Assert.Fail("Expected exception");
     }
     catch (ArgumentOutOfRangeException)
     {
         // Expected
     }
 }
 public void AnyWithPredicateNoMatch()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.Any(x => x.Length == 6);
     subject.ProduceAndEnd("zero", "one", "two", "three", "four");
     Assert.IsFalse(result.Value);
 }
Ejemplo n.º 53
0
        public void GroupByWithResultProjectionAndElementProjectionAndComparer()
        {
            DataProducer<string> producer = new DataProducer<string>();

            var query = producer.GroupBy(word => word[0].ToString(),
                                         word => word + word,
                                         (key, words) => new { Key = key, MaxLength = words.Max(word => word.Length) },
                                         StringComparer.OrdinalIgnoreCase)
                                .AsFutureEnumerable();

            producer.ProduceAndEnd("one", "Two", "three", "Four", "Five", "six", "seven", "Others");

            var results = query.Value.ToList();
            Assert.AreEqual(4, results.Count);
            Assert.AreEqual("o", results[0].Key);
            Assert.AreEqual(12, results[0].MaxLength.Value);

            Assert.AreEqual("T", results[1].Key);
            Assert.AreEqual(10, results[1].MaxLength.Value);

            Assert.AreEqual("F", results[2].Key);
            Assert.AreEqual(8, results[2].MaxLength.Value);

            Assert.AreEqual("s", results[3].Key);
            Assert.AreEqual(10, results[3].MaxLength.Value);
        }
 public void AnyWithPredicateNoData()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.Any(x => x.Length < 5);
     subject.End();
     Assert.IsFalse(result.Value);
 }
 public void SingleOrDefaultWithMultipleElements()
 {
     DataProducer<string> subject = new DataProducer<string>();
     subject.SingleOrDefault();
     subject.Produce("foo");
     try
     {
         subject.Produce("bar");
         Assert.Fail("Expected exception");
     }
     catch (InvalidOperationException)
     {
         // Expected
     }
 }
 public void AnyNoPredicateWithData()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.Any();
     subject.ProduceAndEnd("zero", "one");
     Assert.IsTrue(result.Value);
 }
 public void SingleOrDefaultWithSingleElement()
 {
     DataProducer<int> subject = new DataProducer<int>();
     IFuture<int> single = subject.SingleOrDefault();
     subject.ProduceAndEnd(5);
     Assert.AreEqual(5, single.Value);
 }
 public void AllReturningFalse()
 {
     DataProducer<string> subject = new DataProducer<string>();
     IFuture<bool> result = subject.All(x => x.Length < 5);
     subject.ProduceAndEnd("zero", "one", "two", "three", "four");
     Assert.IsFalse(result.Value);
 }
Ejemplo n.º 59
0
        public void ProduceAndEnd()
        {
            DataProducer<string> subject = new DataProducer<string>();
            List<string> pushed = new List<string>();
            bool endReached = false;

            subject.DataProduced += val => pushed.Add(val);
            subject.EndOfData += () => endReached = true;

            subject.ProduceAndEnd("foo", "bar");

            Assert.IsTrue(endReached);
            Assert.AreEqual(2, pushed.Count);
            Assert.AreEqual("foo", pushed[0]);
            Assert.AreEqual("bar", pushed[1]);
        }
 public void SingleOrDefaultNoData()
 {
     DataProducer<int> subject = new DataProducer<int>();
     IFuture<int> single = subject.SingleOrDefault();
     subject.End();
     Assert.AreEqual(0, single.Value);
 }