Пример #1
0
        public void Should_Return_True_For_Delay_Withing_Interval()
        {
            var sample = new DebouncingSample();

            Assert.False(sample.DebounceDuring100ms());
            Assert.True(sample.DebounceDuring100ms());
        }
Пример #2
0
        public async Task Should_Return_False_For_Delay_Over_Interval()
        {
            var sample = new DebouncingSample();

            Assert.False(sample.DebounceDuring100ms());

            await Task.Delay(110).ConfigureAwait(false);

            Assert.False(sample.DebounceDuring100ms());
        }
Пример #3
0
        public async Task Interval_Should_Not_Slide_With_Each_Call()
        {
            var sample = new DebouncingSample();

            Assert.False(sample.DebounceDuring100ms());

            await Task.Delay(50).ConfigureAwait(false);

            Assert.True(sample.DebounceDuring100ms());

            await Task.Delay(60).ConfigureAwait(false);

            Assert.False(sample.DebounceDuring100ms());

            await Task.Delay(50).ConfigureAwait(false);

            Assert.True(sample.DebounceDuring100ms());

            await Task.Delay(60).ConfigureAwait(false);

            Assert.False(sample.DebounceDuring100ms());
        }
Пример #4
0
        public void Should_Hold_Debounce_References_Weakly()
        {
            WeakReference?sampleRef  = null;
            WeakReference?sampleRef2 = null;

            new Action(() =>
            {
                var sample  = new DebouncingSample();
                var sample2 = new DebouncingSample();

                sampleRef  = new WeakReference(sample);
                sampleRef2 = new WeakReference(sample2);

                sample.DebounceHere();
                sample2.DebounceHere();
            }).Invoke();

            GC.Collect();

            Assert.False(sampleRef !.IsAlive);
            Assert.False(sampleRef2 !.IsAlive);
        }
Пример #5
0
 static bool LocalDebounce(DebouncingSample sample) => sample.DebounceHere();
Пример #6
0
        public void Should_Work_From_Local_Functions()
        {
            var sample = new DebouncingSample();

            Assert.False(LocalDebounce(sample));
            Assert.True(LocalDebounce(sample));