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

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

http://github.com/mongodb/mongo-csharp-driver
C# | 111 lines | 79 code | 18 blank | 14 comment | 0 complexity | 7d64f20d8c7bb56972071258dc8d1475 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 DatabaseNamespaceTests
  21. {
  22. [Theory]
  23. [InlineData("", false)]
  24. [InlineData(" ", false)]
  25. [InlineData(".", false)]
  26. [InlineData(".ab", false)]
  27. [InlineData("ab.", false)]
  28. [InlineData("a.b", false)]
  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. DatabaseNamespace.IsValid(name).Should().Be(valid);
  37. }
  38. [Fact]
  39. public void Constructor_should_throw_an_argument_exception_on_an_invalid_database_name()
  40. {
  41. Action act = () => new DatabaseNamespace("foo.bar");
  42. act.ShouldThrow<ArgumentException>();
  43. }
  44. [Fact]
  45. public void Admin_should_be_the_admin_database()
  46. {
  47. var subject = DatabaseNamespace.Admin;
  48. subject.DatabaseName.Should().Be("admin");
  49. }
  50. [Fact]
  51. public void CommandCollection_should_return_the_command_collection()
  52. {
  53. var subject = new DatabaseNamespace("test");
  54. var commandCollection = subject.CommandCollection;
  55. commandCollection.FullName.Should().Be("test.$cmd");
  56. }
  57. [Fact]
  58. public void DatabaseName_should_report_the_provided_database_name()
  59. {
  60. var subject = new DatabaseNamespace("test");
  61. subject.DatabaseName.Should().Be("test");
  62. }
  63. [Fact]
  64. public void SystemIndexesCollection_should_return_the_system_indexes_collection()
  65. {
  66. var subject = new DatabaseNamespace("test");
  67. var commandCollection = subject.SystemIndexesCollection;
  68. commandCollection.FullName.Should().Be("test.system.indexes");
  69. }
  70. [Fact]
  71. public void SystemNamespacesCollection_should_return_the_system_namespaces_collection()
  72. {
  73. var subject = new DatabaseNamespace("test");
  74. var commandCollection = subject.SystemNamespacesCollection;
  75. commandCollection.FullName.Should().Be("test.system.namespaces");
  76. }
  77. [Theory]
  78. [InlineData("one", "one", true)]
  79. [InlineData("one", "two", false)]
  80. public void Equals_should_be_correct(string a, string b, bool equals)
  81. {
  82. var subject = new DatabaseNamespace(a);
  83. var compared = new DatabaseNamespace(b);
  84. subject.Equals(compared).Should().Be(equals);
  85. }
  86. [Fact]
  87. public void ToString_should_return_the_name()
  88. {
  89. var subject = new DatabaseNamespace("test");
  90. subject.ToString().Should().Be("test");
  91. }
  92. }
  93. }