SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessRead.cs 1.7 KB

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