PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 126 lines | 90 code | 22 blank | 14 comment | 0 complexity | 3c712ba091bec0c9443f369953d074e3 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 CollectionNamespaceTests
  21. {
  22. [Theory]
  23. [InlineData("", false)]
  24. [InlineData(" ", false)]
  25. [InlineData(".", true)]
  26. [InlineData(".ab", true)]
  27. [InlineData("ab.", true)]
  28. [InlineData("a.b", true)]
  29. [InlineData("\0sdf", false)]
  30. [InlineData("lkjsf\0", false)]
  31. [InlineData("lkjsf\0d32", false)]
  32. [InlineData("test", true)]
  33. [InlineData("foobar", true)]
  34. public void IsValid_should_return_the_correct_result(string name, bool valid)
  35. {
  36. CollectionNamespace.IsValid(name).Should().Be(valid);
  37. }
  38. [Fact]
  39. public void FromFullName_should_throw_an_argument_null_exception_if_full_name_is_null()
  40. {
  41. Action act = () => CollectionNamespace.FromFullName(null);
  42. act.ShouldThrow<ArgumentNullException>();
  43. }
  44. [Fact]
  45. public void Constructor_should_throw_an_argument_null_exception_if_database_name_is_null()
  46. {
  47. Action act = () => new CollectionNamespace((string)null, "bar\0baz");
  48. act.ShouldThrow<ArgumentNullException>();
  49. }
  50. [Fact]
  51. public void Constructor_should_throw_an_argument_null_exception_if_database_namespace_is_null()
  52. {
  53. Action act = () => new CollectionNamespace((DatabaseNamespace)null, "bar\0baz");
  54. act.ShouldThrow<ArgumentNullException>();
  55. }
  56. [Fact]
  57. public void Constructor_should_throw_an_argument_exception_on_an_invalid_database_name()
  58. {
  59. Action act = () => new CollectionNamespace("foo", "bar\0baz");
  60. act.ShouldThrow<ArgumentException>();
  61. }
  62. [Fact]
  63. public void FromFullName_should_handle_multiple_periods()
  64. {
  65. var subject = CollectionNamespace.FromFullName("test.foo.bar");
  66. subject.DatabaseNamespace.DatabaseName.Should().Be("test");
  67. subject.CollectionName.Should().Be("foo.bar");
  68. subject.FullName.Should().Be("test.foo.bar");
  69. }
  70. [Fact]
  71. public void CollectionName_should_report_the_provided_name()
  72. {
  73. var subject = new CollectionNamespace("test", "foo");
  74. subject.CollectionName.Should().Be("foo");
  75. }
  76. [Fact]
  77. public void DatabaseName_should_report_the_provided_name()
  78. {
  79. var subject = new CollectionNamespace("test", "foo");
  80. subject.DatabaseNamespace.DatabaseName.Should().Be("test");
  81. }
  82. [Fact]
  83. public void FullName_should_report_the_provided_name()
  84. {
  85. var subject = new CollectionNamespace("test", "foo");
  86. subject.FullName.Should().Be("test.foo");
  87. }
  88. [Theory]
  89. [InlineData("foo.bar", "foo.bar", true)]
  90. [InlineData("foo.bar", "foo.baz", false)]
  91. public void Equals_should_be_correct(string a, string b, bool equals)
  92. {
  93. var subject = CollectionNamespace.FromFullName(a);
  94. var compared = CollectionNamespace.FromFullName(b);
  95. subject.Equals(compared).Should().Be(equals);
  96. }
  97. [Fact]
  98. public void ToString_should_return_the_name()
  99. {
  100. var subject = CollectionNamespace.FromFullName("test.foo");
  101. subject.ToString().Should().Be("test.foo");
  102. }
  103. }
  104. }