PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/MongoDB.Bson.TestHelpers/BsonDocumentAssertions.cs

http://github.com/mongodb/mongo-csharp-driver
C# | 68 lines | 43 code | 9 blank | 16 comment | 0 complexity | 9c35e2b308fe5f88c6c4a1f37cfb6543 MD5 | raw file
Possible License(s): Apache-2.0
  1. /* Copyright 2010-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 FluentAssertions.Common;
  17. using FluentAssertions.Execution;
  18. using FluentAssertions.Primitives;
  19. namespace MongoDB.Bson.TestHelpers
  20. {
  21. public class BsonDocumentAssertions : ReferenceTypeAssertions<BsonDocument, BsonDocumentAssertions>
  22. {
  23. // constructors
  24. public BsonDocumentAssertions(BsonDocument value)
  25. {
  26. Subject = value;
  27. }
  28. // methods
  29. public AndConstraint<BsonDocumentAssertions> Be(BsonDocument expected, string because = "", params object[] reasonArgs)
  30. {
  31. Execute.Assertion
  32. .BecauseOf(because, reasonArgs)
  33. .ForCondition(Subject.IsSameOrEqualTo(expected))
  34. .FailWith("Expected {context:object} to be {0}{reason}, but found {1}.", expected,
  35. Subject);
  36. return new AndConstraint<BsonDocumentAssertions>(this);
  37. }
  38. public AndConstraint<BsonDocumentAssertions> Be(string json, string because = "", params object[] reasonArgs)
  39. {
  40. return Be(BsonDocument.Parse(json), because, reasonArgs);
  41. }
  42. public AndConstraint<BsonDocumentAssertions> NotBe(BsonDocument unexpected, string because = "", params object[] reasonArgs)
  43. {
  44. Execute.Assertion
  45. .BecauseOf(because, reasonArgs)
  46. .ForCondition(!Subject.IsSameOrEqualTo(unexpected))
  47. .FailWith("Did not expect {context:object} to be equal to {0}{reason}.", unexpected);
  48. return new AndConstraint<BsonDocumentAssertions>(this);
  49. }
  50. public AndConstraint<BsonDocumentAssertions> NotBe(string json, string because = "", params object[] reasonArgs)
  51. {
  52. return NotBe(BsonDocument.Parse(json), because, reasonArgs);
  53. }
  54. protected override string Context
  55. {
  56. get { return "BsonDocument"; }
  57. }
  58. }
  59. }