PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/mongodb/mongo-csharp-driver
C# | 159 lines | 117 code | 28 blank | 14 comment | 0 complexity | 371c6fecf81a8336c1b1d31a23e2af36 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2015-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 MongoDB.Bson;
  22. using MongoDB.Bson.TestHelpers.XunitExtensions;
  23. using MongoDB.Driver.Core.Misc;
  24. using Xunit;
  25. namespace MongoDB.Driver
  26. {
  27. public class ReadConcernTests
  28. {
  29. [Fact]
  30. public void Available_should_return_expected_result()
  31. {
  32. var result = ReadConcern.Available;
  33. result.Level.Should().Be(ReadConcernLevel.Available);
  34. }
  35. [Fact]
  36. public void Default_should_return_expected_result()
  37. {
  38. var result = ReadConcern.Default;
  39. result.Level.Should().BeNull();
  40. }
  41. [Fact]
  42. public void Linearizable_should_return_expected_result()
  43. {
  44. var result = ReadConcern.Linearizable;
  45. result.Level.Should().Be(ReadConcernLevel.Linearizable);
  46. }
  47. [Fact]
  48. public void Local_should_return_expected_result()
  49. {
  50. var result = ReadConcern.Local;
  51. result.Level.Should().Be(ReadConcernLevel.Local);
  52. }
  53. [Fact]
  54. public void Majority_should_return_expected_result()
  55. {
  56. var result = ReadConcern.Majority;
  57. result.Level.Should().Be(ReadConcernLevel.Majority);
  58. }
  59. [Fact]
  60. public void Snapshot_should_return_expected_result()
  61. {
  62. var result = ReadConcern.Snapshot;
  63. result.Level.Should().Be(ReadConcernLevel.Snapshot);
  64. }
  65. [Theory]
  66. [ParameterAttributeData]
  67. public void Constructor_with_level_should_initialize_instance(
  68. [Values(ReadConcernLevel.Local, ReadConcernLevel.Majority, null)]
  69. ReadConcernLevel? level)
  70. {
  71. var result = new ReadConcern(level);
  72. result.Level.Should().Be(level);
  73. }
  74. [Fact]
  75. public void Equals_should_return_false_when_level_is_not_equal()
  76. {
  77. ReadConcern.Default.Should().NotBe(ReadConcern.Local);
  78. ReadConcern.Default.Should().NotBe(ReadConcern.Majority);
  79. ReadConcern.Local.Should().NotBe(ReadConcern.Majority);
  80. ReadConcern.Linearizable.Should().NotBe(ReadConcern.Local);
  81. ReadConcern.Linearizable.Should().NotBe(ReadConcern.Majority);
  82. }
  83. [Fact]
  84. public void Equals_should_return_true_when_level_is_equal()
  85. {
  86. ReadConcern.Default.Should().Be(ReadConcern.Default);
  87. new ReadConcern().Should().Be(ReadConcern.Default);
  88. ReadConcern.Linearizable.Should().Be(ReadConcern.Linearizable);
  89. new ReadConcern(ReadConcernLevel.Linearizable).Should().Be(ReadConcern.Linearizable);
  90. ReadConcern.Local.Should().Be(ReadConcern.Local);
  91. new ReadConcern(ReadConcernLevel.Local).Should().Be(ReadConcern.Local);
  92. ReadConcern.Majority.Should().Be(ReadConcern.Majority);
  93. new ReadConcern(ReadConcernLevel.Majority).Should().Be(ReadConcern.Majority);
  94. }
  95. [Theory]
  96. [InlineData(ReadConcernLevel.Available, "{ level: 'available' }")]
  97. [InlineData(ReadConcernLevel.Linearizable, "{ level: 'linearizable' }")]
  98. [InlineData(ReadConcernLevel.Local, "{ level: 'local' }")]
  99. [InlineData(ReadConcernLevel.Majority, "{ level: 'majority' }")]
  100. [InlineData(ReadConcernLevel.Snapshot, "{ level: 'snapshot' }")]
  101. [InlineData(null, "{ }")]
  102. public void ToBsonDocument_should_return_expected_result(ReadConcernLevel? level, string json)
  103. {
  104. var subject = new ReadConcern(level);
  105. var result = subject.ToBsonDocument();
  106. result.Should().Be(json);
  107. }
  108. [Fact]
  109. public void With_should_return_new_instance_when_level_is_not_the_same()
  110. {
  111. var subject = new ReadConcern(null);
  112. var result = subject.With(ReadConcernLevel.Majority);
  113. result.Should().NotBeSameAs(subject);
  114. result.Level.Should().Be(ReadConcernLevel.Majority);
  115. }
  116. [Fact]
  117. public void With_should_return_same_instance_when_all_values_are_equal()
  118. {
  119. var subject = new ReadConcern(ReadConcernLevel.Local);
  120. var result = subject.With(ReadConcernLevel.Local);
  121. result.Should().BeSameAs(subject);
  122. }
  123. [Fact]
  124. public void With_should_return_same_instance_when_no_values_are_provided()
  125. {
  126. var subject = new ReadConcern();
  127. var result = subject.With();
  128. result.Should().BeSameAs(subject);
  129. }
  130. }
  131. }