SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs 1.8 KB

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