2
0

SftpAttrsResponseTest.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 SftpAttrsResponseTest
  10. {
  11. private Random _random;
  12. private uint _protocolVersion;
  13. private uint _responseId;
  14. [TestInitialize]
  15. public void Init()
  16. {
  17. _random = new Random();
  18. _protocolVersion = (uint)_random.Next(0, int.MaxValue);
  19. _responseId = (uint)_random.Next(0, int.MaxValue);
  20. }
  21. [TestMethod]
  22. public void Constructor()
  23. {
  24. var target = new SftpAttrsResponse(_protocolVersion);
  25. Assert.IsNull(target.Attributes);
  26. Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
  27. Assert.AreEqual((uint)0, target.ResponseId);
  28. Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType);
  29. }
  30. [TestMethod]
  31. public void Load()
  32. {
  33. var target = new SftpAttrsResponse(_protocolVersion);
  34. var attributes = CreateSftpFileAttributes();
  35. var attributesBytes = attributes.GetBytes();
  36. var sshDataStream = new SshDataStream(4 + attributesBytes.Length);
  37. sshDataStream.Write(_responseId);
  38. sshDataStream.Write(attributesBytes, 0, attributesBytes.Length);
  39. target.Load(sshDataStream.ToArray());
  40. Assert.IsNotNull(target.Attributes);
  41. Assert.AreEqual(_protocolVersion, target.ProtocolVersion);
  42. Assert.AreEqual(_responseId, target.ResponseId);
  43. Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType);
  44. // check attributes in detail
  45. Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId);
  46. Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime);
  47. Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime);
  48. Assert.AreEqual(attributes.UserId, target.Attributes.UserId);
  49. }
  50. private SftpFileAttributes CreateSftpFileAttributes()
  51. {
  52. var attributes = SftpFileAttributes.Empty;
  53. attributes.GroupId = _random.Next();
  54. attributes.LastAccessTime = new DateTime(2014, 8, 23, 17, 43, 50, DateTimeKind.Local);
  55. attributes.LastWriteTime = new DateTime(2013, 7, 22, 16, 40, 42, DateTimeKind.Local);
  56. attributes.UserId = _random.Next();
  57. return attributes;
  58. }
  59. }
  60. }