Exemplo n.º 1
0
        //[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
        }
Exemplo n.º 2
0
        //[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
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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]);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }