public static void TransferSongs_Test(ISongDownloadTarget downloadTarget)
 {
     //var sourceSong = @"TestSourceSongs";
     var sourceDir = new DirectoryInfo(@"TestSourceSongs");
     var sourceHashes = new List<string>();
     foreach (var songDir in sourceDir.GetDirectories())
     {
         if(songDir.EnumerateFiles("info.dat").Any())
             sourceHashes.Add(SongHashDataProvider.GenerateHash(songDir.FullName));
     }
     
     var cancelSource = new CancellationTokenSource();
     var progressTest = new Action<string, int>((dir, progress) =>
     {
         Console.WriteLine($"{progress}% for {dir}");
         //if (progress == 100)
             //cancelSource.Cancel();
     });
     var sourceSong = new SongDownload() { Hash = "asdf", LocalDirectory = new DirectoryInfo(@"TestSourceSongs\5381-4803 Moon Pluck") };
     var songs = new List<SongDownload>() { sourceSong };
     var transferTask = downloadTarget.TransferSongs(songs, true, progressTest, cancelSource.Token);
     var test = transferTask.Result;
     var hashes = downloadTarget.GetExistingSongHashesAsync().Result;
     foreach (var sourceHash in sourceHashes)
     {
         Assert.IsTrue(hashes.Contains(sourceHash));
     }
     //cancelSource.Cancel();
 }
Beispiel #2
0
 public void DeregisterDownloadTarget(ISongDownloadTarget target)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target), "target cannot be null for DeregisterDownloadTarget");
     }
     DeregisterDownloadTarget(target.ID);
 }
 public static void TransferSong_Test(ISongDownloadTarget downloadTarget)
 {
     Directory.CreateDirectory(@"TestSourceSongs");
     Directory.CreateDirectory(@"TestSourceSongs\5381-4803 Moon Pluck");
     var sourceSong = new SongDownload() { Hash = "asdf", LocalDirectory = new DirectoryInfo(@"TestSourceSongs\5381-4803 Moon Pluck") };
     var cancelSource = new CancellationTokenSource();
     var transferTask = downloadTarget.TransferSong(sourceSong, true, cancelSource.Token);
     var result = transferTask.Result;
     Assert.IsTrue(result);
 }
Beispiel #4
0
 public void RegisterDownloadTarget(ISongDownloadTarget target)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target), "target cannot be null for RegisterDownloadTarget");
     }
     if (string.IsNullOrEmpty(target.ID))
     {
         throw new ArgumentException(nameof(target), "ISongDownloadTarget's ID cannot be null or empty.");
     }
     lock (_downloadTargetsLock)
     {
         if (!DownloadTargets.ContainsKey(target.ID))
         {
             DownloadTargets.Add(target.ID, target);
         }
     }
 }
        public static void TransferSong_Cancelled(ISongDownloadTarget downloadTarget)
        {
            Directory.CreateDirectory(@"TestSourceSongs");
            Directory.CreateDirectory(@"TestSourceSongs\5381-4803 Moon Pluck");
            var sourceSong = new SongDownload() { Hash = "asdf", LocalDirectory = new DirectoryInfo(@"TestSourceSongs\5381-4803 Moon Pluck") };
            var cancelSource = new CancellationTokenSource();
            var transferTask = downloadTarget.TransferSong(sourceSong, true, cancelSource.Token);
            cancelSource.Cancel();
            try
            {
                var result = transferTask.Result;
            } catch(AggregateException ex)
            {
                Assert.IsTrue(ex.InnerExceptions.First().GetType() == typeof(TaskCanceledException));
            }
            

        }
 public static void IsValidTarget_IsNotValid_CreateIfMissing(ISongDownloadTarget downloadTarget)
 {
     var validTarget = downloadTarget.IsValidTarget();
     Assert.IsFalse(validTarget);
 }
 public static void IsValidTarget_IsValid_NoCreate(ISongDownloadTarget downloadTarget)
 {
     var validTarget = downloadTarget.IsValidTarget(false);
     Assert.IsTrue(validTarget);
 }