PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Core.Tests/TagTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 99 lines | 74 code | 10 blank | 15 comment | 0 complexity | e42a71b09b244989c251c3bba55fbbea 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 FluentAssertions;
  17. using Xunit;
  18. namespace MongoDB.Driver
  19. {
  20. public class TagTests
  21. {
  22. [Fact]
  23. public void Constructor_should_initialize_all_fields()
  24. {
  25. var tag = new Tag("name", "value");
  26. tag.Name.Should().Be("name");
  27. tag.Value.Should().Be("value");
  28. }
  29. [Fact]
  30. public void Constructor_should_throw_if_name_is_null()
  31. {
  32. Action action = () => new Tag(null, "value");
  33. action.ShouldThrow<ArgumentNullException>();
  34. }
  35. [Fact]
  36. public void Constructor_should_throw_if_value_is_null()
  37. {
  38. Action action = () => new Tag("name", null);
  39. action.ShouldThrow<ArgumentNullException>();
  40. }
  41. [Theory]
  42. [InlineData("name", "?")]
  43. [InlineData("?", "value")]
  44. public void Equals_should_return_false_if_any_field_is_not_equal(string name, string value)
  45. {
  46. var tag1 = new Tag("name", "value");
  47. var tag2 = new Tag(name, value);
  48. tag1.Equals(tag2).Should().BeFalse();
  49. tag1.Equals((object)tag2).Should().BeFalse();
  50. }
  51. [Fact]
  52. public void Equals_should_return_true_if_all_fields_are_equal()
  53. {
  54. var tag1 = new Tag("name", "value");
  55. var tag2 = new Tag("name", "value");
  56. tag1.Equals(tag2).Should().BeTrue();
  57. tag1.Equals((object)tag2).Should().BeTrue();
  58. }
  59. [Fact]
  60. public void GetHashCode_should_be_equal_if_all_fields_are_equal()
  61. {
  62. var tag1 = new Tag("name", "value");
  63. var tag2 = new Tag("name", "value");
  64. tag1.GetHashCode().Should().Be(tag2.GetHashCode());
  65. }
  66. [Theory]
  67. [InlineData("name", "?")]
  68. [InlineData("?", "value")]
  69. public void GetHashCode_should_not_be_equal_if_any_field_is_not_equal(string name, string value)
  70. {
  71. // note: theoretically hashcodes could collide but it's not likely (and they don't with these values)
  72. var tag1 = new Tag("name", "value");
  73. var tag2 = new Tag(name, value);
  74. tag1.GetHashCode().Should().NotBe(tag2.GetHashCode());
  75. }
  76. [Fact]
  77. public void Name_should_return_the_correct_value()
  78. {
  79. var tag = new Tag("name", "value");
  80. tag.Name.Should().Be("name");
  81. }
  82. [Fact]
  83. public void Value_should_return_the_correct_value()
  84. {
  85. var tag = new Tag("name", "value");
  86. tag.Value.Should().Be("value");
  87. }
  88. }
  89. }