SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  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_FileModeTruncate_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.Truncate;
  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("Combining {0}: {1} with {2}: {3} is invalid.", typeof(FileMode).Name, _fileMode, typeof(FileAccess).Name, _fileAccess), _actualException.Message);
  48. Assert.IsNull(_actualException.ParamName);
  49. }
  50. }
  51. }