123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System;
- using System.Linq;
- using System.Linq.Expressions;
- using Luticate2.Auth.Utils.Business.Utils;
- using Xunit;
-
- namespace Luticate2.Auth.Tests.Business.Utils
- {
- public class TestDbo1
- {
- public string MyString { get; set; }
-
- public TestDbo2 TestDbo2 { get; set; }
- }
-
- public class TestDbo2
- {
- public string MyOtherString { get; set; }
-
- public int MyInt { get; set; }
-
- public TestDbo2 RecursiveObject { get; set; }
- }
-
- public class LuExpressionUtilsTests
- {
- [Fact]
- public void GetSingleMemberFromExpression1()
- {
- var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression((Expression<Func<TestDbo1, string>>)(x => x.MyString));
- Assert.NotNull(memberInfo);
- Assert.Equal("MyString", memberInfo.Name);
- }
-
- [Fact]
- public void GetSingleMemberFromExpression2()
- {
- var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression((Expression<Func<TestDbo1, TestDbo2>>)(x => x.TestDbo2));
- Assert.NotNull(memberInfo);
- Assert.Equal("TestDbo2", memberInfo.Name);
- }
-
- [Fact]
- public void GetSingleMemberFromExpression3()
- {
- var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression((Expression<Func<TestDbo1, TestDbo1>>)(x => x));
- Assert.Null(memberInfo);
- }
-
- [Fact]
- public void GetSingleMemberFromExpression4()
- {
- var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression((Expression<Func<TestDbo1, int>>)(x => 42));
- Assert.Null(memberInfo);
- }
-
- [Fact]
- public void GetSingleMemberFromExpression5()
- {
- var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression((Expression<Func<TestDbo1, int>>)(x => x.TestDbo2.MyInt));
- Assert.Null(memberInfo);
- }
-
- [Fact]
- public void GetSingleMemberFromExpression6()
- {
- var memberInfo = LuExpressionUtils.GetSingleMemberFromExpression((Expression<Func<TestDbo1, int>>)(x => x.TestDbo2.RecursiveObject.MyInt));
- Assert.Null(memberInfo);
- }
-
- [Fact]
- public void GetMembersFromExpression1()
- {
- var memberInfo = LuExpressionUtils.GetMembersFromExpression<TestDbo1, string>(x => x.MyString);
- Assert.NotNull(memberInfo);
- var memberInfosString = string.Join(".", memberInfo.Select(x => x.Name));
- Assert.Equal("MyString", memberInfosString);
- }
-
- [Fact]
- public void GetMembersFromExpression2()
- {
- var memberInfo = LuExpressionUtils.GetMembersFromExpression<TestDbo1, TestDbo2>(x => x.TestDbo2);
- Assert.NotNull(memberInfo);
- var memberInfosString = string.Join(".", memberInfo.Select(x => x.Name));
- Assert.Equal("TestDbo2", memberInfosString);
- }
-
- [Fact]
- public void GetMembersFromExpression3()
- {
- var memberInfo = LuExpressionUtils.GetMembersFromExpression<TestDbo1, TestDbo1>(x => x);
- Assert.Null(memberInfo);
- }
-
- [Fact]
- public void GetMembersFromExpression4()
- {
- var memberInfo = LuExpressionUtils.GetMembersFromExpression<TestDbo1, int>(x => 42);
- Assert.Null(memberInfo);
- }
-
- [Fact]
- public void GetMembersFromExpression5()
- {
- var memberInfo = LuExpressionUtils.GetMembersFromExpression<TestDbo1, int>(x => x.TestDbo2.MyInt);
- Assert.NotNull(memberInfo);
- var memberInfosString = string.Join(".", memberInfo.Select(x => x.Name));
- Assert.Equal("TestDbo2.MyInt", memberInfosString);
- }
-
- [Fact]
- public void GetMembersFromExpression6()
- {
- var memberInfo = LuExpressionUtils.GetMembersFromExpression<TestDbo1, int>(x => x.TestDbo2.RecursiveObject.MyInt);
- Assert.NotNull(memberInfo);
- var memberInfosString = string.Join(".", memberInfo.Select(x => x.Name));
- Assert.Equal("TestDbo2.RecursiveObject.MyInt", memberInfosString);
- }
- }
- }
|