PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Configuration/ServerSettingsTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 114 lines | 77 code | 23 blank | 14 comment | 0 complexity | d4f492154a73b575d67ff1ba7d3cbade 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 System.Threading;
  17. using FluentAssertions;
  18. using Xunit;
  19. namespace MongoDB.Driver.Core.Configuration
  20. {
  21. public class ServerSettingsTests
  22. {
  23. [Fact]
  24. public void DefaultHeartbeatInterval_should_return_expected_result()
  25. {
  26. var result = ServerSettings.DefaultHeartbeatInterval;
  27. result.Should().Be(TimeSpan.FromSeconds(10));
  28. }
  29. [Fact]
  30. public void DefaultHeartbeatTimeout_should_return_expected_result()
  31. {
  32. var result = ServerSettings.DefaultHeartbeatTimeout;
  33. result.Should().Be(Timeout.InfiniteTimeSpan);
  34. }
  35. [Fact]
  36. public void constructor_should_initialize_instance()
  37. {
  38. var subject = new ServerSettings();
  39. subject.HeartbeatInterval.Should().Be(ServerSettings.DefaultHeartbeatInterval);
  40. subject.HeartbeatTimeout.Should().Be(ServerSettings.DefaultHeartbeatTimeout);
  41. }
  42. [Fact]
  43. public void constructor_should_throw_when_heartbeatInterval_is_negative()
  44. {
  45. Action action = () => new ServerSettings(heartbeatInterval: TimeSpan.FromSeconds(-2));
  46. action.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("heartbeatInterval");
  47. }
  48. [Fact]
  49. public void constructor_should_throw_when_heartbeatTimeout_is_negative()
  50. {
  51. Action action = () => new ServerSettings(heartbeatTimeout: TimeSpan.FromSeconds(-2));
  52. action.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("heartbeatTimeout");
  53. }
  54. [Fact]
  55. public void constructor_with_heartbeatInterval_should_initialize_instance()
  56. {
  57. var heartbeatInterval = TimeSpan.FromSeconds(123);
  58. var subject = new ServerSettings(heartbeatInterval: heartbeatInterval);
  59. subject.HeartbeatInterval.Should().Be(heartbeatInterval);
  60. subject.HeartbeatTimeout.Should().Be(ServerSettings.DefaultHeartbeatTimeout);
  61. }
  62. [Fact]
  63. public void constructor_with_heartbeatTimeout_should_initialize_instance()
  64. {
  65. var heartbeatTimeout = TimeSpan.FromSeconds(123);
  66. var subject = new ServerSettings(heartbeatTimeout: heartbeatTimeout);
  67. subject.HeartbeatInterval.Should().Be(ServerSettings.DefaultHeartbeatInterval);
  68. subject.HeartbeatTimeout.Should().Be(heartbeatTimeout);
  69. }
  70. [Fact]
  71. public void With_heartbeatInterval_should_return_expected_result()
  72. {
  73. var oldHeartbeatInterval = TimeSpan.FromSeconds(1);
  74. var newHeartbeatInterval = TimeSpan.FromSeconds(2);
  75. var subject = new ServerSettings(heartbeatInterval: oldHeartbeatInterval);
  76. var result = subject.With(heartbeatInterval: newHeartbeatInterval);
  77. result.HeartbeatInterval.Should().Be(newHeartbeatInterval);
  78. result.HeartbeatTimeout.Should().Be(subject.HeartbeatTimeout);
  79. }
  80. [Fact]
  81. public void With_heartbeatTimeout_should_return_expected_result()
  82. {
  83. var oldHeartbeatTimeout = TimeSpan.FromSeconds(1);
  84. var newHeartbeatTimeout = TimeSpan.FromSeconds(2);
  85. var subject = new ServerSettings(heartbeatTimeout: oldHeartbeatTimeout);
  86. var result = subject.With(heartbeatTimeout: newHeartbeatTimeout);
  87. result.HeartbeatInterval.Should().Be(subject.HeartbeatInterval);
  88. result.HeartbeatTimeout.Should().Be(newHeartbeatTimeout);
  89. }
  90. }
  91. }