2
0

SftpFileStreamTest_OpenAsync_FileModeInvalid.cs 1.5 KB

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