tests/DotNetCommon.Test/ExpressionHelperTests/GetAccessNamesTest.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using DotNetCommon.Extensions;
using DotNetCommon.Test.ExpressionHelperTests.Model;
using NUnit.Framework;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace DotNetCommon.Test.ExpressionHelperTests
{
namespace Model
{
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public object Obj { get; set; }
public int Age { get; set; }
public DateTime? Birth { get; set; }
public TaskStatus Status { get; set; }
public Person InnerPerson { get; set; }
}
}
[TestFixture]
internal class GetAccessNamesTest
{
[Test]
public void OneParamenterTest()
{
Expression<Func<Person, Object>> expression = p => p.Id;
var cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>() { "Id" });
expression = p => new { p.Id, p.Name };
cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>() { "Id", "Name" });
expression = p => new { p.Id, p.Name, p.Obj };
cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>() { "Id", "Name", "Obj" });
expression = p => p.Id + p.Name + p.Obj;
cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>() { "Id", "Name", "Obj" });
expression = p => p.Age + p.InnerPerson.Id;
cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>() { "Age", "InnerPerson" });
expression = p => p.Id > 0 ? p.Name : $"小明{p.Birth}";
cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>() { "Id", "Name", "Birth" });
expression = p => p;
cols = ExpressionHelper.GetAccessNames(expression);
cols.ShouldBe(new List<string>());
}
后面还有 41 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
