PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Clusters/ServerSelectors/EndPointServerSelectorTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 75 lines | 49 code | 12 blank | 14 comment | 0 complexity | 43378c6b6b12d196beceb78f7db9f9af 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.Linq;
  16. using System.Net;
  17. using FluentAssertions;
  18. using MongoDB.Driver.Core.Helpers;
  19. using MongoDB.Driver.Core.Servers;
  20. using Xunit;
  21. namespace MongoDB.Driver.Core.Clusters.ServerSelectors
  22. {
  23. public class EndPointServerSelectorTests
  24. {
  25. private ClusterDescription _description;
  26. public EndPointServerSelectorTests()
  27. {
  28. var clusterId = new ClusterId();
  29. _description = new ClusterDescription(
  30. clusterId,
  31. ClusterConnectionMode.Automatic,
  32. ClusterType.Unknown,
  33. new[]
  34. {
  35. ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)),
  36. ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)),
  37. ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)),
  38. });
  39. }
  40. [Fact]
  41. public void Should_select_the_server_if_it_exists()
  42. {
  43. var subject = new EndPointServerSelector(new DnsEndPoint("localhost", 27017));
  44. var result = subject.SelectServers(_description, _description.Servers).ToList();
  45. result.Count.Should().Be(1);
  46. result.Should().BeEquivalentTo(_description.Servers[0]);
  47. }
  48. [Fact]
  49. public void Should_return_empty_if_the_server_does_not_exist()
  50. {
  51. var subject = new EndPointServerSelector(new DnsEndPoint("blargh", 27017));
  52. var result = subject.SelectServers(_description, _description.Servers).ToList();
  53. result.Should().BeEmpty();
  54. }
  55. [Fact]
  56. public void Should_select_no_servers_when_none_exist()
  57. {
  58. var subject = new EndPointServerSelector(new DnsEndPoint("blargh", 27017));
  59. var result = subject.SelectServers(_description, Enumerable.Empty<ServerDescription>()).ToList();
  60. result.Should().BeEmpty();
  61. }
  62. }
  63. }