PageRenderTime 65ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Misc/TimeSpanParserTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 52 lines | 33 code | 5 blank | 14 comment | 0 complexity | a9b8bdcee3c63bb140c892536a4d62d3 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using FluentAssertions;
  17. using MongoDB.Driver.Core.Misc;
  18. using Xunit;
  19. namespace MongoDB.Driver.Core.Misc
  20. {
  21. public class TimeSpanParserTests
  22. {
  23. [Theory]
  24. [InlineData("2", 2 * 1000)]
  25. [InlineData("2ms", 2)]
  26. [InlineData("2s", 2 * 1000)]
  27. [InlineData("2m", 2 * 1000 * 60)]
  28. [InlineData("2h", 2 * 1000 * 60 * 60)]
  29. public void Parse_should_return_the_correct_TimeSpan(string value, long expectedMilliseconds)
  30. {
  31. TimeSpan result;
  32. var success = TimeSpanParser.TryParse(value, out result);
  33. success.Should().BeTrue();
  34. result.TotalMilliseconds.Should().Be(expectedMilliseconds);
  35. }
  36. [Theory]
  37. [InlineData(2, "2ms")]
  38. [InlineData(2 * 1000, "2s")]
  39. [InlineData(2 * 1000 * 60, "2m")]
  40. [InlineData(2 * 1000 * 60 * 60, "2h")]
  41. public void ToString_should_return_the_correct_string(int milliseconds, string expectedString)
  42. {
  43. var result = TimeSpanParser.ToString(TimeSpan.FromMilliseconds(milliseconds));
  44. result.Should().Be(expectedString);
  45. }
  46. }
  47. }