SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #if FEATURE_TAP
  2. using System;
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using Renci.SshNet.Sftp;
  7. namespace Renci.SshNet.Tests.Classes.Sftp
  8. {
  9. [TestClass]
  10. public class SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead : SftpFileStreamAsyncTestBase
  11. {
  12. private Random _random;
  13. private string _path;
  14. private FileMode _fileMode;
  15. private FileAccess _fileAccess;
  16. private int _bufferSize;
  17. private ArgumentException _actualException;
  18. protected override void SetupData()
  19. {
  20. base.SetupData();
  21. _random = new Random();
  22. _path = _random.Next().ToString();
  23. _fileMode = FileMode.Append;
  24. _fileAccess = FileAccess.Read;
  25. _bufferSize = _random.Next(5, 1000);
  26. }
  27. protected override void SetupMocks()
  28. {
  29. }
  30. protected override async Task ActAsync()
  31. {
  32. try
  33. {
  34. await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
  35. Assert.Fail();
  36. }
  37. catch (ArgumentException ex)
  38. {
  39. _actualException = ex;
  40. }
  41. }
  42. [TestMethod]
  43. public void CtorShouldHaveThrownArgumentException()
  44. {
  45. Assert.IsNotNull(_actualException);
  46. Assert.IsNull(_actualException.InnerException);
  47. Assert.AreEqual(string.Format("{0} mode can be requested only when combined with write-only access.", _fileMode), _actualException.Message);
  48. Assert.IsNull(_actualException.ParamName);
  49. }
  50. }
  51. }
  52. #endif