PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 123 lines | 96 code | 13 blank | 14 comment | 0 complexity | e7d2f21470a4bab3b786692eefd59a18 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.Text;
  19. using System.Threading.Tasks;
  20. using FluentAssertions;
  21. using Xunit;
  22. namespace MongoDB.Driver
  23. {
  24. public class TagSetTests
  25. {
  26. [Fact]
  27. public void Constructor_should_create_new_tag_list()
  28. {
  29. var tags = new[] { new Tag("name", "value") };
  30. var tagSet = new TagSet(tags);
  31. tagSet.Tags.Should().NotBeSameAs(tags);
  32. }
  33. [Fact]
  34. public void Constructor_should_throw_if_tags_is_null()
  35. {
  36. Action action = () => new TagSet(null);
  37. action.ShouldThrow<ArgumentNullException>();
  38. }
  39. [Fact]
  40. public void Constructor_with_no_arguments_should_create_empty_tag_set()
  41. {
  42. var tagSet = new TagSet();
  43. tagSet.Tags.Count.Should().Be(0);
  44. }
  45. [Fact]
  46. public void Constructor_with_no_tags_should_create_empty_tag_set()
  47. {
  48. var tags = new Tag[0];
  49. var tagSet = new TagSet(tags);
  50. tagSet.Tags.Count.Should().Be(0);
  51. }
  52. [Fact]
  53. public void Constructor_with_one_tag_should_create_tag_set_with_one_tag()
  54. {
  55. var tags = new[] { new Tag("name", "value") };
  56. var tagSet = new TagSet(tags);
  57. tagSet.Tags.Should().Equal(tags);
  58. }
  59. [Fact]
  60. public void Constructor_with_two_tag_should_create_tag_set_with_two_tags()
  61. {
  62. var tags = new[] { new Tag("name1", "value1"), new Tag("name2", "value2") };
  63. var tagSet = new TagSet(tags);
  64. tagSet.Tags.Should().Equal(tags);
  65. }
  66. [Fact]
  67. public void ContainsAll_should_return_false_if_any_required_tag_is_missing()
  68. {
  69. var tagSet = new TagSet(new[] { new Tag("name1", "value1"), new Tag("name2", "value2") });
  70. var required = new TagSet(new[] { new Tag("name1", "value1"), new Tag("name3", "value3") });
  71. tagSet.ContainsAll(required).Should().BeFalse();
  72. }
  73. [Fact]
  74. public void ContainsAll_should_return_true_if_all_required_tags_are_present()
  75. {
  76. var tagSet = new TagSet(new[] { new Tag("name1", "value1"), new Tag("name2", "value2") });
  77. var required = new TagSet(new[] { new Tag("name1", "value1") });
  78. tagSet.ContainsAll(required).Should().BeTrue();
  79. }
  80. [Fact]
  81. public void Equals_should_return_false_if_any_field_is_not_the_same()
  82. {
  83. var tagSet1 = new TagSet(new[] { new Tag("name1", "value1") });
  84. var tagSet2 = new TagSet(new[] { new Tag("name2", "value2") });
  85. tagSet1.Equals(tagSet2).Should().BeFalse();
  86. tagSet1.Equals((object)tagSet2).Should().BeFalse();
  87. }
  88. [Fact]
  89. public void Equals_should_return_false_if_rhs_is_null()
  90. {
  91. var tagSet1 = new TagSet(new[] { new Tag("name", "value") });
  92. tagSet1.Equals((TagSet)null).Should().BeFalse();
  93. tagSet1.Equals((object)null).Should().BeFalse();
  94. }
  95. [Fact]
  96. public void Equals_should_return_false_if_rhs_is_not_a_TagSet()
  97. {
  98. var tagSet1 = new TagSet(new[] { new Tag("name", "value") });
  99. tagSet1.Equals((object)"abc").Should().BeFalse();
  100. }
  101. [Fact]
  102. public void Equals_should_return_true_if_all_fields_are_the_same()
  103. {
  104. var tagSet1 = new TagSet(new[] { new Tag("name", "value") });
  105. var tagSet2 = new TagSet(new[] { new Tag("name", "value") });
  106. tagSet1.Equals(tagSet2).Should().BeTrue();
  107. tagSet1.Equals((object)tagSet2).Should().BeTrue();
  108. }
  109. }
  110. }