using System; using System.Linq.Expressions; using System.Reflection; using Kyoo.Models; using Xunit; using Utils = Kyoo.Utility; namespace Kyoo.Tests.Utility { public class UtilityTests { [Fact] public void IsPropertyExpression_Tests() { Expression> member = x => x.ID; Expression> memberCast = x => x.ID; Assert.False(Utils.IsPropertyExpression(null)); Assert.True(Utils.IsPropertyExpression(member)); Assert.True(Utils.IsPropertyExpression(memberCast)); Expression> call = x => x.GetID("test"); Assert.False(Utils.IsPropertyExpression(call)); } [Fact] public void GetPropertyName_Test() { Expression> member = x => x.ID; Expression> memberCast = x => x.ID; Assert.Equal("ID", Utils.GetPropertyName(member)); Assert.Equal("ID", Utils.GetPropertyName(memberCast)); Assert.Throws(() => Utils.GetPropertyName(null)); } [Fact] public void GetMethodTest() { MethodInfo method = Utils.GetMethod(typeof(UtilityTests), BindingFlags.Instance | BindingFlags.Public, nameof(GetMethodTest), Array.Empty(), Array.Empty()); Assert.Equal(MethodBase.GetCurrentMethod(), method); } [Fact] public void GetMethodInvalidGenericsTest() { Assert.Throws(() => Utils.GetMethod(typeof(UtilityTests), BindingFlags.Instance | BindingFlags.Public, nameof(GetMethodTest), new [] { typeof(Utils) }, Array.Empty())); } [Fact] public void GetMethodInvalidParamsTest() { Assert.Throws(() => Utils.GetMethod(typeof(UtilityTests), BindingFlags.Instance | BindingFlags.Public, nameof(GetMethodTest), Array.Empty(), new object[] { this })); } [Fact] public void GetMethodTest2() { MethodInfo method = Utils.GetMethod(typeof(Merger), BindingFlags.Static | BindingFlags.Public, nameof(Merger.MergeLists), new [] { typeof(string) }, new object[] { "string", "string2", null }); Assert.Equal(nameof(Merger.MergeLists), method.Name); } } }