public MeerkatWindowViewModel(IOpenFileService openFileService, IFolderBrowerService folderBrowerService, IBitTorrentManager bitTorrentManager) { // store the current dispatcher ref currentDispatcher = Dispatcher.CurrentDispatcher; this.bitTorrentManager = bitTorrentManager; this.openFileService = openFileService; this.folderBrowerService = folderBrowerService; this.AddTorrentCommand = new AddTorrentCommand(this); this.RemoveTorrentCommand = new RemoveTorrentCommand(this); this.RemoveAndDeleteTorrentCommand = new RemoveAndDeleteTorrentCommand(this); this.OpenContainingFolderCommand = new OpenContainingFolderCommand(this); this.TorrentRecheckCommand = new TorrentRecheckCommand(this); this.AllowUnencryptedConnectionsCommand = new AllowUnencryptedConnectionsCommand(this); this.StartTorrentCommand = new StartTorrentCommand(this); this.StopTorrentCommand = new StopTorrentCommand(this); this.PauseTorrentCommand = new PauseTorrentCommand(this); Torrents = new ObservableCollection <Torrent>(); Peers = new ObservableCollection <Peer>(); bitTorrentManager.TorrentAdded += OnTorrentAdded; bitTorrentManager.TorrentRemoved += OnTorrentRemoved; }
public void AddTorrentTest() { // Create our mocks for the torrent manager and the open dialog services var btmMock = new Mock <IBitTorrentManager>(); btmMock.Setup(mock => mock.AddTorrent("my.torrent", @"c:\downloads")).Returns(true); IBitTorrentManager bitTorrentManager = btmMock.Object; var openFileServiceMock = new Mock <IOpenFileService>(); openFileServiceMock.Setup(mock => mock.OpenFileDialog()).Returns(true); openFileServiceMock.SetupProperty(f => f.FileName, "my.torrent"); IOpenFileService openFileService = openFileServiceMock.Object; var folderBrowserServiceMock = new Mock <IFolderBrowerService>(); folderBrowserServiceMock.Setup(mock => mock.OpenFolderBrowserDialog()).Returns(true); folderBrowserServiceMock.SetupProperty(f => f.FolderName, @"c:\downloads"); IFolderBrowerService folderBrowserService = folderBrowserServiceMock.Object; // Create the vm (not mocked!) and call the function we are testing MeerkatWindowViewModel vm = new MeerkatWindowViewModel(openFileService, folderBrowserService, bitTorrentManager); bool ret = vm.AddTorrent(); Assert.AreEqual(true, ret); // Verify the BitTorrentManager->AddTorrent & dialog show functions were called & called with the correct values openFileServiceMock.Verify(framework => framework.OpenFileDialog()); folderBrowserServiceMock.Verify(framework => framework.OpenFolderBrowserDialog()); btmMock.Verify(framework => framework.AddTorrent("my.torrent", @"c:\downloads")); }
public void RemoveTorrentTest() { UInt32 handle = 50; // Create our mocks var btmMock = new Mock <IBitTorrentManager>(); btmMock.Setup(mock => mock.RemoveTorrent(handle)).Returns(true); IBitTorrentManager bitTorrentManager = btmMock.Object; // Create the vm (not mocked!) and call the function we are testing MeerkatWindowViewModel vm = new MeerkatWindowViewModel(null, null, bitTorrentManager); vm.SelectedTorrent = new Torrent(handle); bool ret = vm.RemoveTorrent(); Assert.AreEqual(true, ret); // Verify the BitTorrentManager.RemoveTorrent is called with the correct values btmMock.Verify(framework => framework.RemoveTorrent(handle)); }
public AnnounceController(IHttpContextAccessor httpContextAccessor, IBitTorrentManager bitTorrentManager) { _httpContextAccessor = httpContextAccessor; _bitTorrentManager = bitTorrentManager; }