PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/ExpressionWalker.Tests/ExpressionWalkerSpecs/When_walking_over_a_method_call_expression.cs

https://github.com/CraftyFella/ExpressionWalker
C# | 35 lines | 30 code | 5 blank | 0 comment | 0 complexity | a102a2974b1284359884c6f6cd8db20e MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using FluentAssertions;
  5. using Machine.Specifications;
  6. namespace ExpressionWalker.Tests.ExpressionWalkerSpecs
  7. {
  8. public class When_walking_over_a_method_call_expression
  9. {
  10. Establish context = () =>
  11. {
  12. _methodCallExpression = (x, y) => Console.WriteLine("x {0}, y{1}", x, y);
  13. _sut = new ExpressionWalker();
  14. Action<ExpressionInfo> action = x => Expressions.Add(x);
  15. _sut.Subscribe(action);
  16. };
  17. Because of = () => _sut.Walk(_methodCallExpression);
  18. It should_return_all_expressions = () => Expressions.Should().HaveCount(7);
  19. It should_have_first_expression_as_lambda = () => Expressions[0].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 1, ExpressionType = ExpressionTypes.LambdaExpression }, options => options.Excluding(o => o.Parent));
  20. It should_have_second_expression_as_method_call = () => Expressions[1].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 2, ExpressionType = ExpressionTypes.MethodCallExpression }, options => options.Excluding(o => o.Parent));
  21. It should_have_third_expression_as_constant = () => Expressions[2].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 3, ExpressionType = ExpressionTypes.ConstantExpression, Value = "x {0}, y{1}" }, options => options.Excluding(o => o.Parent));
  22. It should_have_fourth_expression_as_unary = () => Expressions[3].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 3, ExpressionType = ExpressionTypes.UnaryExpression }, options => options.Excluding(o => o.Parent));
  23. It should_have_fifth_expression_as_parameter = () => Expressions[4].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 4, ExpressionType = ExpressionTypes.ParameterExpression, Value = "x" }, options => options.Excluding(o => o.Parent));
  24. It should_have_sixth_expression_as_unary = () => Expressions[5].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 3, ExpressionType = ExpressionTypes.UnaryExpression }, options => options.Excluding(o => o.Parent));
  25. It should_have_seventh_expression_as_parameter = () => Expressions[6].ShouldBeEquivalentTo(new ExpressionInfo { Depth = 4, ExpressionType = ExpressionTypes.ParameterExpression, Value = "y" }, options => options.Excluding(o => o.Parent));
  26. static ExpressionWalker _sut;
  27. static Expression<Action<int, int>> _methodCallExpression;
  28. static readonly List<ExpressionInfo> Expressions = new List<ExpressionInfo>();
  29. }
  30. }