public void Completed_Transfer_Should_Unlock_File() { //get stream and write to file using (Stream stream = Downloads.ReadFile(SourceFileInfo.FullName)) { stream.WriteTo(TargetFilePath); } Assert.IsTrue(SourceFile.Exists); SourceFile.Delete(); }
public void Read_Data_Should_Match_Source_File() { //get stream and write to file using (Stream stream = Downloads.ReadFile(SourceFileInfo.FullName)) { stream.WriteTo(TargetFilePath); } //calculate hashes of source and target and compare string sourceHash = GetFileHash(SourceFileInfo); string targetHash = new FileInfo(TargetFilePath).CalculateMd5Hash(); Assert.AreEqual(sourceHash, targetHash); }
public void Closing_Stream_Should_Unlock_File() { string resourceId = SourceFileInfo.FullName.ToLowerInvariant(); using (Stream stream = Downloads.ReadFile(resourceId)) { byte[] buffer = new byte[6000]; stream.Read(buffer, 0, buffer.Length); //close the stream stream.Close(); } //attempting to delete the file should work now Thread.CurrentThread.Join(1000); SourceFile.Delete(); }
public void Stream_Read_Should_Fail_As_Soon_As_Expiration_Date_Is_Reached() { try { using (var stream = Downloads.ReadFile(SourceFileInfo.FullName)) { byte[] buffer = new byte[20000]; stream.Read(buffer, 0, buffer.Length); //expire SystemTime.Now = () => Token.ExpirationTime.Value.AddSeconds(1); Thread.CurrentThread.Join(500); stream.Read(buffer, 0, buffer.Length); } } catch (TransferStatusException expected) { Console.Out.WriteLine(expected.Message); } }