public async Task Cancellation___OK()
        {
            var sut      = new SwingingDoorCompression(1d);
            var data     = RawDataAsync(RawDataForTrend());
            var expected = ExpectedForTrend().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();

            List <DataPoint> res = null;

            Assert.ThrowsAsync <OperationCanceledException>(async() => res = await dataPointIterator.ToListAsync(cts.Token));

            CollectionAssert.AreEqual(expected, actual);
            Assert.IsNull(res);
        }
Exemple #2
0
        public async Task IEnumerable_iterated_and_ToList___OK()
        {
            var sut      = new DeadBandCompression(0.1);
            var data     = RawDataForTrendAsync();
            var expected = ExpectedForTrend().ToList();

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

            await enumerator.MoveNextAsync();

            await enumerator.MoveNextAsync();

            var actual = await dataPointIterator.ToListAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
        public async Task IEnumerable_iterated_and_ToList___OK(double compressionDeviation, IAsyncEnumerable <DataPoint> rawData, IEnumerable <DataPoint> expectedData)
        {
            var sut      = new SwingingDoorCompression(compressionDeviation);
            var data     = rawData;
            var expected = expectedData.ToList();

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

            await enumerator.MoveNextAsync();

            await enumerator.MoveNextAsync();

            var actual = await dataPointIterator.ToListAsync();

            CollectionAssert.AreEqual(expected, actual);
        }
        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();

            Print(expected, "expected");
            Print(actual, "actual");
            CollectionAssert.AreEqual(expected, actual);
        }