PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

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