//[Theory] //[MemberData(nameof(EquivalentExpressions))] private void GetExpressionText_CacheEquivalentExpressionsn_Theory(LambdaExpression expression1, LambdaExpression expression2) { // Act - 1 var text1 = ExpressionHelper.GetExpressionText(expression1, _expressionTextCache); // Act - 2 var text2 = ExpressionHelper.GetExpressionText(expression2, _expressionTextCache); // Assert Assert2.Same(text1, text2); // cached }
//[Theory] //[MemberData(nameof(CachedExpressions))] private void GetExpressionText_CachesExpression_Theory(LambdaExpression expression) { // Act - 1 var text1 = ExpressionHelper.GetExpressionText(expression, _expressionTextCache); // Act - 2 var text2 = ExpressionHelper.GetExpressionText(expression, _expressionTextCache); // Assert Assert2.Same(text1, text2); // cached }
public async Task TargetMethodReturningCustomAwaitableOfValueType_CanInvokeViaExecute() { // Arrange var executor = GetExecutorForMethod(nameof(TestObject.CustomAwaitableOfValueTypeAsync)); // Act var result = await(TestAwaitable <int>) executor.Execute(_targetObject, new object[] { 123, 456 }); // Assert Assert2.True(executor.IsMethodAsync); Assert2.Same(typeof(int), executor.AsyncResultType); Assert2.Equal(579, result); }
public async Task TargetMethodReturningAwaitableWithoutICriticalNotifyCompletion_UsesOnCompleted() { // Arrange var executor = GetExecutorForMethod(nameof(TestObject.CustomAwaitableWithoutICriticalNotifyCompletion)); // Act var result = await executor.ExecuteAsync(_targetObject, new object[0]); // Assert Assert2.True(executor.IsMethodAsync); Assert2.Same(typeof(string), executor.AsyncResultType); Assert2.Equal("Used OnCompleted", (string)result); }
public async Task TargetMethodReturningAwaitableOfVoidType_CanInvokeViaExecuteAsync() { // Arrange var executor = GetExecutorForMethod(nameof(TestObject.VoidValueMethodAsync)); // Act var result = await executor.ExecuteAsync(_targetObject, new object[] { 123 }); // Assert Assert2.True(executor.IsMethodAsync); Assert2.Same(typeof(void), executor.AsyncResultType); Assert2.Null(result); }
public async Task TargetMethodReturningValueTaskOfValueType_CanBeInvokedViaExecute() { // Arrange var executor = GetExecutorForMethod(nameof(TestObject.ValueTaskOfValueType)); // Act var result = await(ValueTask <int>) executor.Execute(_targetObject, new object[] { 123 }); // Assert Assert2.True(executor.IsMethodAsync); Assert2.Same(typeof(int), executor.AsyncResultType); Assert2.Equal(123, result); }
public async Task TargetMethodReturningValueTaskOfReferenceType_CanBeInvokedViaExecuteAsync() { // Arrange var executor = GetExecutorForMethod(nameof(TestObject.ValueTaskOfReferenceType)); // Act var result = await executor.ExecuteAsync(_targetObject, new object[] { "test result" }); // Assert Assert2.True(executor.IsMethodAsync); Assert2.Same(typeof(string), executor.AsyncResultType); Assert2.Equal("test result", result); }
public void Process_CachesChainedMemberAccess_ToValueType() { // Arrange var expression1 = GetTestModelExpression(m => m.Date.Year); var expression2 = GetTestModelExpression(m => m.Date.Year); // Act var func1 = CachedExpressionCompiler.Process(expression1); var func2 = CachedExpressionCompiler.Process(expression2); // Assert Assert2.NotNull(func1); Assert2.Same(func1, func2); }
public void Process_CachesIdentityExpression() { // Arrange var expression1 = GetTestModelExpression(m => m); var expression2 = GetTestModelExpression(m => m); // Act var func1 = CachedExpressionCompiler.Process(expression1); var func2 = CachedExpressionCompiler.Process(expression2); // Assert Assert2.NotNull(func1); Assert2.Same(func1, func2); }
public void Process_CachesSimpleMemberAccess() { // Arrange var expression1 = GetTestModelExpression(m => m.Name); var expression2 = GetTestModelExpression(m => m.Name); // Act var func1 = CachedExpressionCompiler.Process(expression1); var func2 = CachedExpressionCompiler.Process(expression2); // Assert Assert2.NotNull(func1); Assert2.Same(func1, func2); }
public void Process_CachesStaticPropertyAccess() { // Arrange var expression1 = GetTestModelExpression(m => TestModel.StaticProperty); var expression2 = GetTestModelExpression(m => TestModel.StaticProperty); // Act var func1 = CachedExpressionCompiler.Process(expression1); var func2 = CachedExpressionCompiler.Process(expression2); // Assert Assert2.NotNull(func1); Assert2.Same(func1, func2); }
public async Task TargetMethodReturningCustomAwaitableOfReferenceType_CanInvokeViaExecute() { // Arrange var executor = GetExecutorForMethod(nameof(TestObject.CustomAwaitableOfReferenceTypeAsync)); // Act var result = await(TestAwaitable <TestObject>) executor.Execute(_targetObject, new object[] { "Hello", 123 }); // Assert Assert2.True(executor.IsMethodAsync); Assert2.Same(typeof(TestObject), executor.AsyncResultType); Assert2.NotNull(result); Assert2.Equal("Hello 123", result.value); }
public void PropertyHelper_ReturnsCachedPropertyHelper() { // Arrange var anonymous = new { foo = "bar" }; // Act var helpers1 = PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo()); var helpers2 = PropertyHelper.GetPropertyAccessors(anonymous.GetType().GetTypeInfo()); // Assert Assert2.Single(helpers1); Assert2.Same(helpers1, helpers2); Assert2.Same(helpers1[0], helpers2[0]); }
public void Process_IdentityExpression() { // Arrange var model = new TestModel(); var expression = GetTestModelExpression(m => m); // Act var func = CachedExpressionCompiler.Process(expression); // Assert Assert2.NotNull(func); var result = func(model); Assert2.Same(model, result); }
public void Process_ConstLookup_WithNullModel() { // Arrange var differentModel = new DifferentModel(); var expression = GetTestModelExpression(m => differentModel); // Act var func = CachedExpressionCompiler.Process(expression); // Assert Assert2.NotNull(func); var result = func(null); Assert2.Same(differentModel, result); }
public void Process_CapturedVariable_WithNullModel() { // Arrange var differentModel = new DifferentModel(); var model = (TestModel)null; var expression = GetTestModelExpression(m => differentModel); // Act var func = CachedExpressionCompiler.Process(expression); // Assert Assert2.NotNull(func); var result = func(model); Assert2.Same(differentModel, result); }
public void Process_ConstLookup_UsingCachedValue() { // Arrange var model = new TestModel(); var differentModel = new DifferentModel(); var expression1 = GetTestModelExpression(m => differentModel); var expression2 = GetTestModelExpression(m => differentModel); // Act - 1 var func1 = CachedExpressionCompiler.Process(expression1); // Assert - 1 var result1 = func1(null); Assert2.Same(differentModel, result1); // Act - 2 var func2 = CachedExpressionCompiler.Process(expression2); // Assert - 2 var result2 = func1(null); Assert2.Same(differentModel, result2); }
public void Process_ConstLookup_WhenCapturedLocalChanges() { // Arrange var model = new TestModel(); var differentModel = new DifferentModel(); var expression = GetTestModelExpression(m => differentModel); // Act var func = CachedExpressionCompiler.Process(expression); // Assert - 1 var result1 = func(null); Assert2.Same(differentModel, result1); // Act - 2 differentModel = new DifferentModel(); // Assert - 2 var result2 = func(null); Assert2.NotSame(differentModel, result1); Assert2.Same(differentModel, result2); }