Exemplo n.º 1
0
        public async Task Cancellation___OK()
        {
            var sut      = new NoCompression();
            var data     = RawDataForTrendAsync();
            var expected = RawDataForTrend().Take(2).ToList();

            DataPointIterator dataPointIterator = sut.ProcessAsync(data);
            var cts        = new CancellationTokenSource();
            var enumerator = dataPointIterator.GetAsyncEnumerator(cts.Token);

            var actual = new List <DataPoint>();
            await enumerator.MoveNextAsync();

            actual.Add(enumerator.Current);
            await enumerator.MoveNextAsync();

            actual.Add(enumerator.Current);
            cts.Cancel();

            DataPoint[] res = null;
            Assert.ThrowsAsync <OperationCanceledException>(async() => res = await dataPointIterator.ToArrayAsync(cts.Token));

            CollectionAssert.AreEqual(expected, actual);
            Assert.IsNull(res);
        }
Exemplo n.º 2
0
        public void Cancellation_after_two_items___OK()
        {
            var sut      = new NoCompression();
            var data     = RawDataForTrendAsync();
            var expected = RawDataForTrend().Take(2).ToList();
            var cts      = new CancellationTokenSource();

            var actual = new List <DataPoint>();
            int idx    = 0;

            Assert.ThrowsAsync <OperationCanceledException>(async() =>
            {
                await foreach (DataPoint dp in sut.ProcessAsync(data).WithCancellation(cts.Token))
                {
                    actual.Add(dp);
                    idx++;

                    if (idx == 2)
                    {
                        cts.Cancel();
                    }
                }
            });

            CollectionAssert.AreEqual(actual, expected);
        }
Exemplo n.º 3
0
        public async Task Empty_IAsyncEnumerable___empty_result()
        {
            var sut      = new NoCompression();
            var data     = EmptyAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();

            Assert.IsFalse(await iterator.MoveNextAsync());
        }
Exemplo n.º 4
0
        public async Task Data_IAsyncEnumerable_with_maxDeltaX___OK()
        {
            var sut      = new NoCompression();
            var data     = RawDataForMaxDeltaAsync();
            var expected = RawDataForMaxDelta().ToList();

            var actual = await sut.ProcessAsync(data).ToArrayAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 5
0
        public async Task Data_given_as_IAsyncEnumerable___OK()
        {
            var sut      = new NoCompression();
            var data     = RawDataForTrendAsync();
            var expected = RawDataForTrend().ToList();

            var actual = await sut.ProcessAsync(data).ToArrayAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public async Task Empty_IAsyncEnumerable_foreach___empty_result()
        {
            var sut  = new NoCompression();
            var data = EmptyAsync();

            int count = 0;

            await foreach (DataPoint db in sut.ProcessAsync(data))
            {
                count++;
            }

            Assert.AreEqual(0, count);
        }
Exemplo n.º 7
0
        public async Task Data_IAsyncEnumerable_with_maxDeltaX___OK()
        {
            var sut      = new NoCompression();
            var data     = RawDataForMaxDeltaAsync();
            var expected = RawDataForMaxDelta().ToList();

            var actual = new List <DataPoint>();

            await foreach (DataPoint dp in sut.ProcessAsync(data))
            {
                actual.Add(dp);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public async Task IAsyncEnumerable_iterated_and_ToArray___OK()
        {
            var sut      = new NoCompression();
            var data     = RawDataForTrendAsync();
            var expected = RawDataForTrend().ToList();

            DataPointIterator dataPointIterator = sut.ProcessAsync(data);
            var enumerator = dataPointIterator.GetAsyncEnumerator();

            await enumerator.MoveNextAsync();

            await enumerator.MoveNextAsync();

            var actual = await dataPointIterator.ToArrayAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public async Task Known_sequence_foreach___correct_result()
        {
            var sut      = new NoCompression();
            var data     = KnownSequenceAsync();
            var result   = sut.ProcessAsync(data);
            var expected = new List <DataPoint>();
            var actual   = new List <DataPoint>();

            await foreach (DataPoint dp in KnownSequenceAsync())
            {
                expected.Add(dp);
            }

            await foreach (DataPoint dp in result)
            {
                actual.Add(dp);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public async Task Known_sequence___correct_result()
        {
            var sut      = new NoCompression();
            var data     = KnownSequenceAsync();
            var iterator = sut.ProcessAsync(data).GetAsyncEnumerator();
            var expected = new List <DataPoint>();

            await foreach (DataPoint dp in KnownSequenceAsync())
            {
                expected.Add(dp);
            }

            Assert.Multiple(async() =>
            {
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[0], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[1], iterator.Current);
                await iterator.MoveNextAsync();
                Assert.AreEqual(expected[2], iterator.Current);
            });
        }