PageRenderTime 27ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/src/MongoDB.Driver.Core.Tests/Core/Operations/QueryHelperTests.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 81 lines | 53 code | 14 blank | 14 comment | 0 complexity | 8a3e707c3684baf66e26a20b30bf599f MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2013-2014 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.Driver.Core.Servers;
  17. using NUnit.Framework;
  18. namespace MongoDB.Driver.Core.Operations
  19. {
  20. [TestFixture]
  21. public class QueryHelperTests
  22. {
  23. [Test]
  24. [TestCase(null, null, 0)]
  25. [TestCase(null, 20, 20)]
  26. [TestCase(20, null, 20)]
  27. [TestCase(10, 20, 10)]
  28. [TestCase(20, 10, 10)]
  29. [TestCase(-20, 10, -20)]
  30. public void CalculateFirstBatchSize_should_return_the_correct_result(int? limit, int? batchSize, int expectedResult)
  31. {
  32. var result = QueryHelper.CalculateFirstBatchSize(limit, batchSize);
  33. result.Should().Be(expectedResult);
  34. }
  35. [Test]
  36. public void CreateReadPreferenceDocument_should_return_null_when_the_serverType_is_not_a_shard_router()
  37. {
  38. var result = QueryHelper.CreateReadPreferenceDocument(ServerType.ReplicaSetSecondary, ReadPreference.PrimaryPreferred);
  39. result.Should().BeNull();
  40. }
  41. [Test]
  42. public void CreateReadPreferenceDocument_should_return_null_when_the_readPreference_is_Primary_with_no_tag_sets()
  43. {
  44. var result = QueryHelper.CreateReadPreferenceDocument(ServerType.ShardRouter, ReadPreference.Primary);
  45. result.Should().BeNull();
  46. }
  47. [Test]
  48. public void CreateReadPreferenceDocument_should_return_null_when_the_readPreference_is_SecondaryPreferred_with_no_tag_sets()
  49. {
  50. var result = QueryHelper.CreateReadPreferenceDocument(ServerType.ShardRouter, ReadPreference.SecondaryPreferred);
  51. result.Should().BeNull();
  52. }
  53. [Test]
  54. public void CreateReadPreferenceDocument_should_return_a_document_when_their_are_tag_sets()
  55. {
  56. var rp = ReadPreference.Secondary.With(tagSets: new[] { new TagSet(new[] { new Tag("dc", "tx") }) });
  57. var result = QueryHelper.CreateReadPreferenceDocument(ServerType.ShardRouter, rp);
  58. result.Should().Be("{mode: \"secondary\", tags: [{dc: \"tx\"}]}");
  59. }
  60. [Test]
  61. public void CreateReadPreferenceDocument_should_return_a_document_when_the_mode_is_not_Primary_or_SecondaryPreferred()
  62. {
  63. var result = QueryHelper.CreateReadPreferenceDocument(ServerType.ShardRouter, ReadPreference.PrimaryPreferred);
  64. result.Should().Be("{mode: \"primaryPreferred\"}");
  65. }
  66. }
  67. }