PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

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