PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 67 lines | 46 code | 7 blank | 14 comment | 1 complexity | cc2a5754233826ca6f5360d82c029bf6 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 FluentAssertions;
  16. using MongoDB.Bson;
  17. using Xunit;
  18. namespace MongoDB.Driver.Core.Clusters
  19. {
  20. public class ElectionIdTests
  21. {
  22. [Theory]
  23. [InlineData("555925bfb69aa7d5be29126b", "555925bfb69aa7d5be29126b", 0)]
  24. [InlineData("555925bfb69aa7d5be29126b", "555925bfb69aa7d5be29126c", -1)]
  25. [InlineData("000000000000000000000000", "555925bfb69aa7d5be29126b", -1)]
  26. [InlineData("555925bfb69aa7d5be29126c", "555925bfb69aa7d5be29126b", 1)]
  27. [InlineData("555925bfb69aa7d5be29126b", "000000000000000000000000", 1)]
  28. [InlineData("555925bfb69aa7d5be29126b", null, 1)]
  29. public void CompareTo_should_return_the_correct_value(string oidA, string oidB, int result)
  30. {
  31. var subject1 = new ElectionId(ObjectId.Parse(oidA));
  32. ElectionId subject2 = oidB == null ? (ElectionId)null : new ElectionId(ObjectId.Parse(oidB));
  33. subject1.CompareTo(subject2).Should().Be(result);
  34. }
  35. [Fact]
  36. public void Equals_should_return_false_if_any_field_is_not_equal()
  37. {
  38. var subject1 = new ElectionId(ObjectId.Empty);
  39. var subject2 = new ElectionId(ObjectId.GenerateNewId());
  40. subject1.Equals(subject2).Should().BeFalse();
  41. subject1.Equals((object)subject2).Should().BeFalse();
  42. subject1.GetHashCode().Should().NotBe(subject2.GetHashCode());
  43. }
  44. [Fact]
  45. public void Equals_should_return_true_if_all_fiels_are_equal()
  46. {
  47. var subject1 = new ElectionId(ObjectId.Empty);
  48. var subject2 = new ElectionId(ObjectId.Empty);
  49. subject1.Equals(subject2).Should().BeTrue();
  50. subject1.Equals((object)subject2).Should().BeTrue();
  51. subject1.GetHashCode().Should().Be(subject2.GetHashCode());
  52. }
  53. [Fact]
  54. public void ToString_should_return_string_representation()
  55. {
  56. var subject = new ElectionId(ObjectId.Empty);
  57. subject.ToString().Should().Be(ObjectId.Empty.ToString());
  58. }
  59. }
  60. }