StatVfsReplyInfoTest.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Sftp;
  5. using Renci.SshNet.Sftp.Responses;
  6. namespace Renci.SshNet.Tests.Classes.Sftp.Responses
  7. {
  8. [TestClass]
  9. public class StatVfsReplyInfoTest
  10. {
  11. private Random _random;
  12. private uint _responseId;
  13. private ulong _bsize;
  14. private ulong _frsize;
  15. private ulong _blocks;
  16. private ulong _bfree;
  17. private ulong _bavail;
  18. private ulong _files;
  19. private ulong _ffree;
  20. private ulong _favail;
  21. private ulong _sid;
  22. private ulong _namemax;
  23. [TestInitialize]
  24. public void Init()
  25. {
  26. _random = new Random();
  27. _responseId = (uint) _random.Next(0, int.MaxValue);
  28. _bsize = (ulong) _random.Next(0, int.MaxValue);
  29. _frsize = (ulong)_random.Next(0, int.MaxValue);
  30. _blocks = (ulong)_random.Next(0, int.MaxValue);
  31. _bfree = (ulong)_random.Next(0, int.MaxValue);
  32. _bavail = (ulong)_random.Next(0, int.MaxValue);
  33. _files = (ulong)_random.Next(0, int.MaxValue);
  34. _ffree = (ulong)_random.Next(0, int.MaxValue);
  35. _favail = (ulong)_random.Next(0, int.MaxValue);
  36. _sid = (ulong)_random.Next(0, int.MaxValue);
  37. _namemax = (ulong)_random.Next(0, int.MaxValue);
  38. }
  39. [TestMethod]
  40. public void Constructor()
  41. {
  42. var target = new StatVfsReplyInfo();
  43. Assert.IsNull(target.Information);
  44. }
  45. [TestMethod]
  46. public void Load()
  47. {
  48. var sshDataStream = new SshDataStream(4 + 1 + 4 + 88);
  49. sshDataStream.Write(_responseId);
  50. sshDataStream.Write(_bsize);
  51. sshDataStream.Write(_frsize);
  52. sshDataStream.Write(_blocks);
  53. sshDataStream.Write(_bfree);
  54. sshDataStream.Write(_bavail);
  55. sshDataStream.Write(_files);
  56. sshDataStream.Write(_ffree);
  57. sshDataStream.Write(_favail);
  58. sshDataStream.Write(_sid);
  59. sshDataStream.Write((ulong) 0x1);
  60. sshDataStream.Write(_namemax);
  61. var extendedReplyResponse = new SftpExtendedReplyResponse(SftpSession.MaximumSupportedVersion);
  62. extendedReplyResponse.Load(sshDataStream.ToArray());
  63. Assert.AreEqual(_responseId, extendedReplyResponse.ResponseId);
  64. var target = extendedReplyResponse.GetReply<StatVfsReplyInfo>();
  65. Assert.IsNotNull(target.Information);
  66. var information = target.Information;
  67. Assert.AreEqual(_bavail, information.AvailableBlocks);
  68. Assert.AreEqual(_favail, information.AvailableNodes);
  69. Assert.AreEqual(_frsize, information.BlockSize);
  70. Assert.AreEqual(_bsize, information.FileSystemBlockSize);
  71. Assert.AreEqual(_bfree, information.FreeBlocks);
  72. Assert.AreEqual(_ffree, information.FreeNodes);
  73. Assert.IsTrue(information.IsReadOnly);
  74. Assert.AreEqual(_namemax, information.MaxNameLenght);
  75. Assert.AreEqual(_sid, information.Sid);
  76. Assert.IsTrue(information.SupportsSetUid);
  77. Assert.AreEqual(_blocks, information.TotalBlocks);
  78. Assert.AreEqual(_files, information.TotalNodes);
  79. }
  80. }
  81. }