Example #1
0
        public void WhileTyping_SendsTypingEvery4SecondsUntilTaskCompletes()
        {
            var taskSource = new TaskCompletionSource <int>();
            var channelId  = "C123";

            var result = _sut.WhileTyping(channelId, () => taskSource.Task);

            _scheduler.AdvanceBy(TimeSpan.FromSeconds(4).Ticks - 1);
            _rtm.DidNotReceive().SendTyping(channelId);

            _scheduler.AdvanceBy(1);
            _rtm.Received(1).SendTyping(channelId);

            _scheduler.AdvanceBy(TimeSpan.FromSeconds(8).Ticks);
            _rtm.Received(3).SendTyping(channelId);

            taskSource.SetResult(0);
            result.IsCompleted.ShouldBe(true);
            _scheduler.AdvanceBy(TimeSpan.FromSeconds(4).Ticks);
            _rtm.Received(3).SendTyping(channelId);
        }