PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 85 lines | 61 code | 10 blank | 14 comment | 1 complexity | 87457d65b64ed96fd6c598c9ab7261e8 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.Bson;
  19. using MongoDB.Driver.Core.Clusters;
  20. using MongoDB.Driver.Core.Connections;
  21. using MongoDB.Driver.Core.Misc;
  22. using MongoDB.Driver.Core.Servers;
  23. using Xunit;
  24. namespace MongoDB.Driver.Core.Servers
  25. {
  26. public class ServerIdTests
  27. {
  28. private static readonly ClusterId __clusterId = new ClusterId(1);
  29. private static readonly DnsEndPoint __endPoint = new DnsEndPoint("localhost", 27017);
  30. [Fact]
  31. public void Constructor_should_properly_initializes_instance()
  32. {
  33. var subject = new ServerId(__clusterId, __endPoint);
  34. subject.ClusterId.Should().Be(__clusterId);
  35. subject.EndPoint.Should().Be(__endPoint);
  36. }
  37. private ServerId CreateSubject(string notEqualField = null)
  38. {
  39. var clusterId = new ClusterId(1);
  40. var endPoint = new DnsEndPoint("localhost", 27017);
  41. switch (notEqualField)
  42. {
  43. case "ClusterId": clusterId = new ClusterId(2); break;
  44. case "EndPoint": endPoint = new DnsEndPoint("localhost", 27018); break;
  45. }
  46. return new ServerId(clusterId, endPoint);
  47. }
  48. [Theory]
  49. [InlineData("ClusterId")]
  50. [InlineData("EndPoint")]
  51. public void Equals_should_return_false_if_any_field_is_not_equal(string notEqualField)
  52. {
  53. var subject1 = CreateSubject();
  54. var subject2 = CreateSubject(notEqualField);
  55. subject1.Equals(subject2).Should().BeFalse();
  56. subject1.Equals((object)subject2).Should().BeFalse();
  57. subject1.GetHashCode().Should().NotBe(subject2.GetHashCode());
  58. }
  59. [Fact]
  60. public void Equals_should_return_true_if_all_fiels_are_equal()
  61. {
  62. var subject1 = CreateSubject();
  63. var subject2 = CreateSubject();
  64. subject1.Equals(subject2).Should().BeTrue();
  65. subject1.Equals((object)subject2).Should().BeTrue();
  66. subject1.GetHashCode().Should().Be(subject2.GetHashCode());
  67. }
  68. [Fact]
  69. public void ToString_should_return_string_representation()
  70. {
  71. var subject = new ServerId(__clusterId, __endPoint);
  72. subject.ToString().Should().Be("{ ClusterId : 1, EndPoint : \"Unspecified/localhost:27017\" }");
  73. }
  74. }
  75. }