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

/WebEssentialsTests/Tests/IntellisenseGeneration/TestHelper/IntellisenseObjectsAssertions.cs

https://github.com/systembugtj/WebEssentials2013
C# | 56 lines | 48 code | 8 blank | 0 comment | 3 complexity | f5567a4e2ff77fe18e19fe91f66e33ff MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System.Diagnostics;
  2. using System.Linq;
  3. using FluentAssertions;
  4. using FluentAssertions.Execution;
  5. using FluentAssertions.Primitives;
  6. using MadsKristensen.EditorExtensions;
  7. namespace WebEssentialsTests.Tests.IntellisenseGeneration.TestHelper
  8. {
  9. [DebuggerNonUserCode]
  10. public class IntellisenseObjectsAssertions :
  11. ReferenceTypeAssertions<IntellisenseObject, IntellisenseObjectsAssertions>
  12. {
  13. protected internal IntellisenseObjectsAssertions(IntellisenseObject @object)
  14. {
  15. Subject = @object;
  16. }
  17. protected override string Context
  18. {
  19. get { return "WebEssentials IntellisenseObject"; }
  20. }
  21. public AndConstraint<IntellisensePropertyAssertions> HasProperty(string propertyName)
  22. {
  23. return HasProperty(propertyName, string.Empty);
  24. }
  25. public AndConstraint<IntellisensePropertyAssertions> HasProperty(string propertyName, string reason,
  26. params object[] reasonArgs)
  27. {
  28. var property = Subject.Properties.SingleOrDefault(p => p.Name == propertyName);
  29. Execute.Assertion
  30. .ForCondition(property != null)
  31. .BecauseOf(reason, reasonArgs)
  32. .FailWith("Expected IntellisenseObject to have property {0}{reason}", propertyName);
  33. return new AndConstraint<IntellisensePropertyAssertions>(new IntellisensePropertyAssertions(property));
  34. }
  35. public AndConstraint<IntellisenseObjectsAssertions> NameIs(string expected)
  36. {
  37. return NameIs(expected, string.Empty);
  38. }
  39. public AndConstraint<IntellisenseObjectsAssertions> NameIs(string expected, string reason,
  40. params object[] reasonArgs)
  41. {
  42. Execute.Assertion.ForCondition(Subject.Name == expected)
  43. .BecauseOf(reason, reasonArgs)
  44. .FailWith("Expected IntellisenseObject to be named {0} but found {1}{reason}", expected, Subject.Name);
  45. return new AndConstraint<IntellisenseObjectsAssertions>(this);
  46. }
  47. }
  48. }