public void ShouldCompletelyClearPendingActionsBeforeExecutingNewActions() { var msgs = new List<int>(); var sut = new StubFiber { ExecutePendingImmediately = true }; var channel = new Channel<int>(); const int count = 4; channel.Subscribe(sut, delegate(int x) { if (x == count) { return; } channel.Publish(x + 1); msgs.Add(x); }); channel.Publish(0); Assert.AreEqual(count, msgs.Count); for (var i = 0; i < msgs.Count; i++) { Assert.AreEqual(i, msgs[i]); } }
public void SetUp() { fiber = new StubFiber() { ExecutePendingImmediately = true }; simpleChannel = new Channel<SimpleYouTubeClip>(); sink = new SinkChannel<RichYouTubeClip>(); downloader = new YouTubeInfoDownloader(fiber, simpleChannel, sink); }
protected override void SetUp() { var fiber = new StubFiber(); _mock_first = CreateMock<IReceiver<int>>(); _mock_rest = CreateMock<IReceiver<int>>(); _receiver = new FirstReceiver<int>(fiber, _mock_first.Object, _mock_rest.Object); }
public void DisposeShouldClearAllLists() { var sut = new StubFiber(); var channel = new Channel<int>(); channel.Subscribe(sut, x => { }); sut.Schedule(() => { }, 1000); channel.Publish(2); Assert.AreEqual(1, sut.Subscriptions.Count); Assert.AreEqual(1, sut.Scheduled.Count); Assert.AreEqual(1, sut.Pending.Count); sut.Dispose(); Assert.AreEqual(0, sut.Subscriptions.Count); Assert.AreEqual(0, sut.Scheduled.Count); Assert.AreEqual(0, sut.Pending.Count); }
public void ScheduledTasksShouldBeExecutedOnceScheduleIntervalShouldBeExecutedEveryTimeExecuteScheduleAllIsCalled() { var sut = new StubFiber(); var scheduleFired = 0; var scheduleOnIntervalFired = 0; sut.Schedule(() => scheduleFired++, 100); var intervalSub = sut.ScheduleOnInterval(() => scheduleOnIntervalFired++, 100, 100); sut.ExecuteAllScheduled(); Assert.AreEqual(1, scheduleFired); Assert.AreEqual(1, scheduleOnIntervalFired); sut.ExecuteAllScheduled(); Assert.AreEqual(1, scheduleFired); Assert.AreEqual(2, scheduleOnIntervalFired); intervalSub.Dispose(); sut.ExecuteAllScheduled(); Assert.AreEqual(1, scheduleFired); Assert.AreEqual(2, scheduleOnIntervalFired); }
public void ShouldIncreaseStubFiberSubscriberCountByOne() { var fiber = new StubFiber(); fiber.Start(); var channel = new Channel<int>(); Assert.AreEqual(0, fiber.SubscriptionsCount); Assert.AreEqual(0, channel.SubscribersCount); channel.Subscribe(fiber, x => { }); Assert.AreEqual(1, fiber.SubscriptionsCount); Assert.AreEqual(1, channel.SubscribersCount); fiber.Dispose(); Assert.AreEqual(0, fiber.SubscriptionsCount); Assert.AreEqual(0, channel.SubscribersCount); }
protected override void SetUp() { _fiber = new StubFiber(); _fiber.Start(); }
protected override void SetUp() { this.fiber = new StubFiber(); this.mockClient = base.CreateMock<IWebClient>(); this.model = new BurritoDayModel(this.fiber, this.mockClient.Object); this.sequence = new Queue<string>(); this.cache = new Dictionary<Uri, string>(); this.mockClient.Setup(m => m.Download(It.IsAny<Uri>())). Returns((Uri uri) => { string data; if (!this.cache.TryGetValue(uri, out data)) { data = this.cache[uri] = this.sequence.Count > 0 ? this.GetResource(this.sequence.Dequeue()) : null; } return data; }); }
public void SetUp() { fiber = new StubFiber() { ExecutePendingImmediately = true }; input = new Channel<MailMessage>(); sink = new SinkChannel<SimpleYouTubeClip>(); extractor = new LinkExtractor(fiber, input, sink); }
public void StubFiberPendingTasksShouldAllowEnqueueOfCommandsWhenExecutingAllPending() { var sut = new StubFiber { ExecutePendingImmediately = false }; var fired1 = new object(); var fired2 = new object(); var fired3 = new object(); var actionMarkers = new List<object>(); Action command1 = delegate { actionMarkers.Add(fired1); sut.Enqueue(() => actionMarkers.Add(fired3)); }; Action command2 = () => actionMarkers.Add(fired2); sut.Enqueue(command1); sut.Enqueue(command2); sut.ExecuteAllPendingUntilEmpty(); Assert.AreEqual(new[] { fired1, fired2, fired3 }, actionMarkers.ToArray()); }