PageRenderTime 107ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/MongoDB.Driver.Tests/Specifications/command-monitoring/CountTest.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 62 lines | 43 code | 5 blank | 14 comment | 2 complexity | 0ef13944f99101e8a01e69c0bf39b922 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2010-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.Threading.Tasks;
  17. using FluentAssertions;
  18. using MongoDB.Bson;
  19. namespace MongoDB.Driver.Tests.Specifications.command_monitoring
  20. {
  21. public class CountTest : CrudOperationTestBase
  22. {
  23. private BsonDocument _filter;
  24. private CountOptions _options = new CountOptions();
  25. protected override void Execute(IMongoCollection<BsonDocument> collection, bool async)
  26. {
  27. if (async)
  28. {
  29. #pragma warning disable 618
  30. collection.CountAsync(_filter, _options).GetAwaiter().GetResult();
  31. #pragma warning restore
  32. }
  33. else
  34. {
  35. #pragma warning disable 618
  36. collection.Count(_filter, _options);
  37. #pragma warning restore
  38. }
  39. }
  40. protected override bool TrySetArgument(string name, BsonValue value)
  41. {
  42. switch (name)
  43. {
  44. case "filter":
  45. _filter = (BsonDocument)value;
  46. return true;
  47. case "skip":
  48. _options.Skip = value.ToInt64();
  49. return true;
  50. case "limit":
  51. _options.Limit = value.ToInt64();
  52. return true;
  53. }
  54. return false;
  55. }
  56. }
  57. }