public void when_overflowing_buffer_capacity_then_sends_only_buffer_capacity()
        {
            const int NumberOfEntries = 1200;

            sink.WaitHandle.Reset();

            for (int i = 0; i < NumberOfEntries; i++)
            {
                sink.OnNext(new CloudEventEntry(EventEntryTestHelper.Create(eventId: 10, payloadNames: new string[] { "arg" }, payload: new object[] { i })));
            }

            sink.WaitHandle.Set();

            Assert.IsTrue(sink.FlushAsync().Wait(TimeSpan.FromSeconds(10)));

            Assert.AreEqual(BufferSize, sink.SentEntriesCount);
        }
        public void when_overflowing_buffer_capacity_then_sends_only_buffer_capacity()
        {
            const int NumberOfEntries = 1200;

            sink.WaitHandle.Reset();

            for (int i = 0; i < NumberOfEntries; i++)
            {
                sink.OnNext(new CloudEventEntry {
                    EventId = 10, Payload = { { "arg", i } }
                });
            }

            sink.WaitHandle.Set();

            Assert.IsTrue(sink.FlushAsync().Wait(TimeSpan.FromSeconds(10)));

            Assert.AreEqual(BufferSize, sink.SentEntriesCount);
        }
        public void when_sending_on_completed_blocks_for_timeout_period_only()
        {
            var timeout = TimeSpan.FromSeconds(1.75);
            var delta   = TimeSpan.FromSeconds(.5);

            using (var sink = new TestableWindowsAzureTableSink("TestName", onCompletedTimeout: timeout))
            {
                sink.WaitHandle.Reset();

                sink.OnNext(new CloudEventEntry(EventEntryTestHelper.Create(eventId: 10)));

                var stopWatch = Stopwatch.StartNew();
                sink.OnCompleted();
                stopWatch.Stop();

                Assert.IsTrue(stopWatch.Elapsed >= timeout - delta, "Elapsed: {0}. Expected at least {1}", stopWatch.Elapsed, timeout - delta);
                Assert.IsTrue(stopWatch.Elapsed <= timeout + delta, "Elapsed: {0}. Expected at most {1}", stopWatch.Elapsed, timeout + delta);

                sink.WaitHandle.Set();
            }
        }
        public void when_sending_on_completed_blocks_for_timeout_period_only()
        {
            var timeout = TimeSpan.FromSeconds(1.75);
            var delta = TimeSpan.FromSeconds(.5);
            using (var sink = new TestableWindowsAzureTableSink("TestName", onCompletedTimeout: timeout))
            {
                sink.WaitHandle.Reset();

                sink.OnNext(new CloudEventEntry(EventEntryTestHelper.Create(eventId: 10)));

                var stopWatch = Stopwatch.StartNew();
                sink.OnCompleted();
                stopWatch.Stop();

                Assert.IsTrue(stopWatch.Elapsed >= timeout - delta, "Elapsed: {0}. Expected at least {1}", stopWatch.Elapsed, timeout - delta);
                Assert.IsTrue(stopWatch.Elapsed <= timeout + delta, "Elapsed: {0}. Expected at most {1}", stopWatch.Elapsed, timeout + delta);

                sink.WaitHandle.Set();
            }
        }