PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/Core/Clusters/ReplicaSetConfigTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 94 lines | 68 code | 12 blank | 14 comment | 0 complexity | be77ba1639fff38baa10ff5f578e76b3 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.Collections.Generic;
  17. using System.Linq;
  18. using System.Net;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using FluentAssertions;
  22. using MongoDB.Driver.Core.Clusters;
  23. using MongoDB.Driver.Core.Servers;
  24. using MongoDB.Driver.Core.Helpers;
  25. using Xunit;
  26. namespace MongoDB.Driver.Core.Clusters
  27. {
  28. public class ReplicaSetConfigTests
  29. {
  30. private static readonly EndPoint[] _endPoints =
  31. new[] { new DnsEndPoint("localhost", 27017), new DnsEndPoint("localhost", 27018) };
  32. private static readonly string _name = "rs1";
  33. private static readonly int _version = 10;
  34. [Fact]
  35. public void Constructor_should_throw_if_endpoints_is_null()
  36. {
  37. Action act = () => new ReplicaSetConfig(null, _name, _endPoints[0], _version);
  38. act.ShouldThrow<ArgumentNullException>();
  39. }
  40. [Fact]
  41. public void Constructor_should_assign_properties_correctly()
  42. {
  43. var subject = new ReplicaSetConfig(_endPoints, _name, _endPoints[0], _version);
  44. subject.Members.Should().BeEquivalentTo(_endPoints);
  45. subject.Name.Should().Be(_name);
  46. subject.Primary.Should().Be(_endPoints[0]);
  47. subject.Version.Should().Be(_version);
  48. }
  49. [Fact]
  50. public void Equals_should_ignore_revision()
  51. {
  52. var subject1 = new ReplicaSetConfig(_endPoints, _name, _endPoints[0], _version);
  53. var subject2 = new ReplicaSetConfig(_endPoints, _name, _endPoints[0], _version);
  54. subject1.Equals(subject2).Should().BeTrue();
  55. subject1.Equals((object)subject2).Should().BeTrue();
  56. subject1.GetHashCode().Should().Be(subject2.GetHashCode());
  57. }
  58. [Fact]
  59. public void Equals_should_not_be_the_same_when_a_field_is_different()
  60. {
  61. var subject1 = new ReplicaSetConfig(_endPoints, _name, _endPoints[0], _version);
  62. var subject2 = new ReplicaSetConfig(new[] { _endPoints[0] }, _name, _endPoints[0], _version);
  63. var subject3 = new ReplicaSetConfig(_endPoints, null, _endPoints[0], _version);
  64. var subject4 = new ReplicaSetConfig(_endPoints, _name, _endPoints[1], _version);
  65. var subject5 = new ReplicaSetConfig(_endPoints, _name, null, _version);
  66. var subject6 = new ReplicaSetConfig(_endPoints, _name, _endPoints[0], _version + 1);
  67. var subject7 = new ReplicaSetConfig(_endPoints, _name, _endPoints[0], null);
  68. subject1.Should().NotBe(subject2);
  69. subject1.Should().NotBe(subject3);
  70. subject1.Should().NotBe(subject4);
  71. subject1.Should().NotBe(subject5);
  72. subject1.Should().NotBe(subject6);
  73. subject1.Should().NotBe(subject7);
  74. subject2.Should().NotBe(subject1);
  75. subject3.Should().NotBe(subject1);
  76. subject4.Should().NotBe(subject1);
  77. subject5.Should().NotBe(subject1);
  78. subject6.Should().NotBe(subject1);
  79. subject7.Should().NotBe(subject1);
  80. }
  81. }
  82. }