PageRenderTime 140ms CodeModel.GetById 20ms RepoModel.GetById 4ms app.codeStats 0ms

/tests/MongoDB.Bson.TestHelpers/BsonArrayAssertions.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 73 lines | 48 code | 9 blank | 16 comment | 2 complexity | 87eaa5c509957aad07d9309113f0f1a0 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.Diagnostics;
  16. using FluentAssertions;
  17. using FluentAssertions.Common;
  18. using FluentAssertions.Execution;
  19. using FluentAssertions.Primitives;
  20. using MongoDB.Bson.Serialization;
  21. namespace MongoDB.Bson.TestHelpers
  22. {
  23. [DebuggerStepThrough]
  24. public class BsonArrayAssertions : ReferenceTypeAssertions<BsonArray, BsonArrayAssertions>
  25. {
  26. // constructors
  27. public BsonArrayAssertions(BsonArray value)
  28. {
  29. Subject = value;
  30. }
  31. // methods
  32. public AndConstraint<BsonArrayAssertions> Be(BsonArray expected, string because = "", params object[] reasonArgs)
  33. {
  34. Execute.Assertion
  35. .BecauseOf(because, reasonArgs)
  36. .ForCondition(Subject.IsSameOrEqualTo(expected))
  37. .FailWith("Expected {context:object} to be {0}{reason}, but found {1}.", expected,
  38. Subject);
  39. return new AndConstraint<BsonArrayAssertions>(this);
  40. }
  41. public AndConstraint<BsonArrayAssertions> Be(string json, string because = "", params object[] reasonArgs)
  42. {
  43. var expected = json == null ? null : BsonSerializer.Deserialize<BsonArray>(json);
  44. return Be(expected, because, reasonArgs);
  45. }
  46. public AndConstraint<BsonArrayAssertions> NotBe(BsonArray unexpected, string because = "", params object[] reasonArgs)
  47. {
  48. Execute.Assertion
  49. .BecauseOf(because, reasonArgs)
  50. .ForCondition(!Subject.IsSameOrEqualTo(unexpected))
  51. .FailWith("Did not expect {context:object} to be equal to {0}{reason}.", unexpected);
  52. return new AndConstraint<BsonArrayAssertions>(this);
  53. }
  54. public AndConstraint<BsonArrayAssertions> NotBe(string json, string because = "", params object[] reasonArgs)
  55. {
  56. var expected = json == null ? null : BsonSerializer.Deserialize<BsonArray>(json);
  57. return NotBe(expected, because, reasonArgs);
  58. }
  59. protected override string Context
  60. {
  61. get { return "BsonArray"; }
  62. }
  63. }
  64. }