PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Servers/ServerFactoryTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 128 lines | 91 code | 23 blank | 14 comment | 0 complexity | 6ca91cd35f6790effc9eca999b6d5bd1 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.Net;
  17. using FluentAssertions;
  18. using MongoDB.Driver.Core.Clusters;
  19. using MongoDB.Driver.Core.Configuration;
  20. using MongoDB.Driver.Core.ConnectionPools;
  21. using MongoDB.Driver.Core.Connections;
  22. using MongoDB.Driver.Core.Events;
  23. using MongoDB.Driver.Core.Servers;
  24. using Moq;
  25. using Xunit;
  26. namespace MongoDB.Driver.Core.Servers
  27. {
  28. public class ServerFactoryTests
  29. {
  30. private ClusterId _clusterId;
  31. private ClusterConnectionMode _clusterConnectionMode;
  32. private IConnectionPoolFactory _connectionPoolFactory;
  33. private EndPoint _endPoint;
  34. private IEventSubscriber _eventSubscriber;
  35. private IServerMonitorFactory _serverMonitorFactory;
  36. private ServerSettings _settings;
  37. public ServerFactoryTests()
  38. {
  39. _clusterId = new ClusterId();
  40. _clusterConnectionMode = ClusterConnectionMode.Standalone;
  41. _connectionPoolFactory = new Mock<IConnectionPoolFactory>().Object;
  42. _endPoint = new DnsEndPoint("localhost", 27017);
  43. _serverMonitorFactory = new Mock<IServerMonitorFactory>().Object;
  44. _eventSubscriber = new Mock<IEventSubscriber>().Object;
  45. _settings = new ServerSettings();
  46. }
  47. [Fact]
  48. public void Constructor_should_throw_when_settings_is_null()
  49. {
  50. Action act = () => new ServerFactory(_clusterConnectionMode, null, _connectionPoolFactory, _serverMonitorFactory, _eventSubscriber);
  51. act.ShouldThrow<ArgumentNullException>();
  52. }
  53. [Fact]
  54. public void Constructor_should_throw_when_connectionPoolFactory_is_null()
  55. {
  56. Action act = () => new ServerFactory(_clusterConnectionMode, _settings, null, _serverMonitorFactory, _eventSubscriber);
  57. act.ShouldThrow<ArgumentNullException>();
  58. }
  59. [Fact]
  60. public void Constructor_should_throw_when_heartbeatConnectionFactory_is_null()
  61. {
  62. Action act = () => new ServerFactory(_clusterConnectionMode, _settings, _connectionPoolFactory, null, _eventSubscriber);
  63. act.ShouldThrow<ArgumentNullException>();
  64. }
  65. [Fact]
  66. public void Constructor_should_throw_when_eventSubscriber_is_null()
  67. {
  68. Action act = () => new ServerFactory(_clusterConnectionMode, _settings, _connectionPoolFactory, _serverMonitorFactory, null);
  69. act.ShouldThrow<ArgumentNullException>();
  70. }
  71. [Fact]
  72. public void CreateServer_should_throw_if_clusterId_is_null()
  73. {
  74. var subject = new ServerFactory(_clusterConnectionMode, _settings, _connectionPoolFactory, _serverMonitorFactory, _eventSubscriber);
  75. var clusterClock = new Mock<IClusterClock>().Object;
  76. Action act = () => subject.CreateServer(null, clusterClock, _endPoint);
  77. act.ShouldThrow<ArgumentNullException>();
  78. }
  79. [Fact]
  80. public void CreateServer_should_throw_if_clusterClock_is_null()
  81. {
  82. var subject = new ServerFactory(_clusterConnectionMode, _settings, _connectionPoolFactory, _serverMonitorFactory, _eventSubscriber);
  83. var clusterId = new ClusterId();
  84. Action act = () => subject.CreateServer(clusterId, null, _endPoint);
  85. act.ShouldThrow<ArgumentNullException>();
  86. }
  87. [Fact]
  88. public void CreateServer_should_throw_if_endPoint_is_null()
  89. {
  90. var subject = new ServerFactory(_clusterConnectionMode, _settings, _connectionPoolFactory, _serverMonitorFactory, _eventSubscriber);
  91. var clusterClock = new Mock<IClusterClock>().Object;
  92. Action act = () => subject.CreateServer(_clusterId, clusterClock, null);
  93. act.ShouldThrow<ArgumentNullException>();
  94. }
  95. [Fact]
  96. public void CreateServer_should_return_Server()
  97. {
  98. var subject = new ServerFactory(_clusterConnectionMode, _settings, _connectionPoolFactory, _serverMonitorFactory, _eventSubscriber);
  99. var clusterClock = new Mock<IClusterClock>().Object;
  100. var result = subject.CreateServer(_clusterId, clusterClock, _endPoint);
  101. result.Should().NotBeNull();
  102. result.Should().BeOfType<Server>();
  103. }
  104. }
  105. }