2
0

TimeSpanExtensionsTest.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Common;
  4. namespace Renci.SshNet.Tests.Classes.Common
  5. {
  6. [TestClass]
  7. public class TimeSpanExtensionsTest
  8. {
  9. [TestMethod]
  10. public void AsTimeout_ValidTimeSpan_ReturnsExpectedMilliseconds()
  11. {
  12. var timeSpan = TimeSpan.FromSeconds(10);
  13. var timeout = timeSpan.AsTimeout();
  14. Assert.AreEqual(10000, timeout);
  15. }
  16. [TestMethod]
  17. [DataRow(-2)]
  18. [DataRow((double)int.MaxValue + 1)]
  19. public void AsTimeout_InvalidTimeSpan_ThrowsArgumentOutOfRangeException(double milliseconds)
  20. {
  21. var timeSpan = TimeSpan.FromMilliseconds(milliseconds);
  22. var ex = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => timeSpan.AsTimeout());
  23. Assert.Contains("The timeout must represent a value between -1 and Int32.MaxValue milliseconds, inclusive.", ex.Message, StringComparison.Ordinal);
  24. Assert.AreEqual(nameof(timeSpan), ex.ParamName);
  25. }
  26. [TestMethod]
  27. public void EnsureValidTimeout_ValidTimeSpan_DoesNotThrow()
  28. {
  29. var timeSpan = TimeSpan.FromSeconds(5);
  30. timeSpan.EnsureValidTimeout();
  31. }
  32. [TestMethod]
  33. [DataRow(-2)]
  34. [DataRow((double)int.MaxValue + 1)]
  35. public void EnsureValidTimeout_InvalidTimeSpan_ThrowsArgumentOutOfRangeException(double milliseconds)
  36. {
  37. var timeSpan = TimeSpan.FromMilliseconds(milliseconds);
  38. var ex = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => timeSpan.EnsureValidTimeout());
  39. Assert.Contains("The timeout must represent a value between -1 and Int32.MaxValue milliseconds, inclusive.", ex.Message, StringComparison.Ordinal);
  40. Assert.AreEqual(nameof(timeSpan), ex.ParamName);
  41. }
  42. }
  43. }