PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 100 lines | 66 code | 20 blank | 14 comment | 0 complexity | c7ea07bcee5389c941f7dfab4f01b08f MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-2014 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 NUnit.Framework;
  18. namespace MongoDB.Driver.Core.Configuration
  19. {
  20. [TestFixture]
  21. public class ServerSettingsTests
  22. {
  23. private static readonly ServerSettings __defaults = new ServerSettings();
  24. [Test]
  25. public void constructor_should_initialize_instance()
  26. {
  27. var subject = new ServerSettings();
  28. subject.HeartbeatInterval.Should().Be(TimeSpan.FromSeconds(10));
  29. subject.HeartbeatTimeout.Should().Be(TimeSpan.FromSeconds(10));
  30. }
  31. [Test]
  32. public void constructor_should_throw_when_heartbeatInterval_is_negative()
  33. {
  34. Action action = () => new ServerSettings(heartbeatInterval: TimeSpan.FromSeconds(-1));
  35. action.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("heartbeatInterval");
  36. }
  37. [Test]
  38. public void constructor_should_throw_when_heartbeatTimeout_is_negative()
  39. {
  40. Action action = () => new ServerSettings(heartbeatTimeout: TimeSpan.FromSeconds(-1));
  41. action.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("heartbeatTimeout");
  42. }
  43. [Test]
  44. public void constructor_with_heartbeatInterval_should_initialize_instance()
  45. {
  46. var heartbeatInterval = TimeSpan.FromSeconds(123);
  47. var subject = new ServerSettings(heartbeatInterval: heartbeatInterval);
  48. subject.HeartbeatInterval.Should().Be(heartbeatInterval);
  49. subject.HeartbeatTimeout.Should().Be(__defaults.HeartbeatTimeout);
  50. }
  51. [Test]
  52. public void constructor_with_heartbeatTimeout_should_initialize_instance()
  53. {
  54. var heartbeatTimeout = TimeSpan.FromSeconds(123);
  55. var subject = new ServerSettings(heartbeatTimeout: heartbeatTimeout);
  56. subject.HeartbeatInterval.Should().Be(subject.HeartbeatInterval);
  57. subject.HeartbeatTimeout.Should().Be(heartbeatTimeout);
  58. }
  59. [Test]
  60. public void With_heartbeatInterval_should_return_expected_result()
  61. {
  62. var oldHeartbeatInterval = TimeSpan.FromSeconds(1);
  63. var newHeartbeatInterval = TimeSpan.FromSeconds(2);
  64. var subject = new ServerSettings(heartbeatInterval: oldHeartbeatInterval);
  65. var result = subject.With(heartbeatInterval: newHeartbeatInterval);
  66. result.HeartbeatInterval.Should().Be(newHeartbeatInterval);
  67. result.HeartbeatTimeout.Should().Be(subject.HeartbeatTimeout);
  68. }
  69. [Test]
  70. public void With_heartbeatTimeout_should_return_expected_result()
  71. {
  72. var oldHeartbeatTimeout = TimeSpan.FromSeconds(1);
  73. var newHeartbeatTimeout = TimeSpan.FromSeconds(2);
  74. var subject = new ServerSettings(heartbeatTimeout: oldHeartbeatTimeout);
  75. var result = subject.With(heartbeatTimeout: newHeartbeatTimeout);
  76. result.HeartbeatInterval.Should().Be(subject.HeartbeatInterval);
  77. result.HeartbeatTimeout.Should().Be(newHeartbeatTimeout);
  78. }
  79. }
  80. }