SftpFileStreamTest_Ctor_FileAccessInvalid.cs 1.5 KB

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