public FeedsManager(HyenaSqliteConnection connection, DownloadManager downloadManager, string podcast_base_dir) { // Hack to work around Feeds being needy and having to call all our internal methods, instead // of us just listening for their events. Instance = this; this.connection = connection; this.podcast_base_dir = podcast_base_dir; feed_manager = new FeedManager(); enclosure_manager = new EnclosureManager(downloadManager); Feed.Init(); FeedItem.Init(); FeedEnclosure.Init(); command_queue = new AsyncCommandQueue(); }
public void The_queue_should_throw_an_exception_if_there_is_no_room_for_new_commands() { var queue = new AsyncCommandQueue(2, 0); queue.Enqueue(delegate { }); queue.Enqueue(delegate { }); try { queue.Enqueue(delegate { }); Assert.Fail("failed"); } catch (QueueFullException failed) { Assert.AreEqual(2, failed.Depth); Assert.AreEqual("The queue is full and cannot accept new commands (2)", failed.Message); } }
public void Dispose() { if (SetDisposed()) { AutoResetEvent disposeHandle = new AutoResetEvent(false); feed_manager.Dispose(disposeHandle); enclosure_manager.Dispose(disposeHandle); if (command_queue != null) { command_queue.Dispose(); command_queue = null; } disposeHandle.Close(); } }
public void The_queue_should_only_execute_actions_while_enabled() { var first = MockRepository.GenerateMock<Action>(); var second = MockRepository.GenerateMock<Action>(); var third = MockRepository.GenerateMock<Action>(); var queue = new AsyncCommandQueue(100, 100); queue.Enqueue(first); var run = new Thread(queue.Run) {IsBackground = true}; run.Start(); Thread.Sleep(100); queue.Enqueue(second); queue.Disable(); queue.Enqueue(third); Thread.Sleep(100); run.Join(); first.AssertWasCalled(x => x()); second.AssertWasCalled(x => x()); third.AssertWasNotCalled(x => x()); }
public void The_queue_should_not_hide_any_exceptions_from_the_caller() { var action = MockRepository.GenerateMock<Action>(); var exception = new Exception(); action.Expect(x => x()).Throw(exception); var queue = new AsyncCommandQueue(100, 100); queue.Enqueue(action); try { queue.ExecuteAvailableActions(); Assert.Fail("Should throw Exception"); } catch (Exception ex) { Assert.AreSame(exception, ex); } action.VerifyAllExpectations(); }