|
| 1 | +namespace AgileObjects.ReadableExpressions.UnitTests.Extensions |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using System.Collections.Generic; |
| 5 | + using System.Linq; |
| 6 | + using System.Linq.Expressions; |
| 7 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 8 | + using ReadableExpressions.Extensions; |
| 9 | + |
| 10 | + public class WhenGettingAParentExpressionNode |
| 11 | + { |
| 12 | + [TestMethod] |
| 13 | + public void ShouldReturnAMemberAccessParent() |
| 14 | + { |
| 15 | + Expression<Func<Type, string>> personViewModelName = t => t.Name; |
| 16 | + |
| 17 | + var namePropertyParent = personViewModelName.Body.GetParentOrNull() as ParameterExpression; |
| 18 | + |
| 19 | + Assert.IsNotNull(namePropertyParent); |
| 20 | + Assert.AreEqual("t", namePropertyParent.Name); |
| 21 | + } |
| 22 | + |
| 23 | + [TestMethod] |
| 24 | + public void ShouldReturnANestedMemberAccessParent() |
| 25 | + { |
| 26 | + Expression<Func<Type, string>> typeAssemblyImageVersion = t => t.Assembly.ImageRuntimeVersion; |
| 27 | + |
| 28 | + var typeAssemblyImageVersionParent = typeAssemblyImageVersion.Body.GetParentOrNull() as MemberExpression; |
| 29 | + |
| 30 | + Assert.IsNotNull(typeAssemblyImageVersionParent); |
| 31 | + Assert.AreEqual("Assembly", typeAssemblyImageVersionParent.Member.Name); |
| 32 | + } |
| 33 | + |
| 34 | + [TestMethod] |
| 35 | + public void ShouldReturnAMemberMethodCallParent() |
| 36 | + { |
| 37 | + Expression<Func<Type, string>> typeAssemblyToString = p => p.Assembly.ToString(); |
| 38 | + |
| 39 | + var assemblyToStringPropertyParent = typeAssemblyToString.Body.GetParentOrNull() as MemberExpression; |
| 40 | + |
| 41 | + Assert.IsNotNull(assemblyToStringPropertyParent); |
| 42 | + Assert.AreEqual("Assembly", assemblyToStringPropertyParent.Member.Name); |
| 43 | + } |
| 44 | + |
| 45 | + [TestMethod] |
| 46 | + public void ShouldReturnAnExtensionMethodCallParent() |
| 47 | + { |
| 48 | + Expression<Func<IEnumerable<Type>, Type[]>> typesToArray = ts => ts.ToArray(); |
| 49 | + |
| 50 | + var typesToArrayPropertyParent = typesToArray.Body.GetParentOrNull() as ParameterExpression; |
| 51 | + |
| 52 | + Assert.IsNotNull(typesToArrayPropertyParent); |
| 53 | + Assert.AreEqual("ts", typesToArrayPropertyParent.Name); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments