Esempio n. 1
0
            public void LessThanExprPropertyValueShouldBeComparable()
            {
                // Prepare
                var viewModelProperty  = new FakeViewModelProperty(new object());
                var lessThanExpression = ExpressionNode.LessThanValue(viewModelProperty, 2);

                // Act
                var taskResult = lessThanExpression.Evaluate(new CancellationToken());

                taskResult.Start();
                try
                {
                    // to throw eventual exceptions
                    taskResult.Wait();
                }
                catch (AggregateException ae)
                {
                    ae.Flatten().Handle(ex =>
                    {
                        if (ex is InvalidOperationException)
                        {
                            throw ex;
                        }
                        return(false);
                    });
                }
            }
Esempio n. 2
0
            public void GreaterThanExprShouldNotAllowComparingDifferentTypes()
            {
                // Prepare
                var viewModelProperty     = new FakeViewModelProperty(10);
                var greaterThanExpression = ExpressionNode.GreaterThanValue(viewModelProperty, "NotAllowedValue");

                // Act
                var taskResult = greaterThanExpression.Evaluate(new CancellationToken());

                taskResult.Start();
                try
                {
                    // to throw eventual exceptions
                    taskResult.Wait();
                }
                catch (AggregateException ae)
                {
                    ae.Flatten().Handle(ex =>
                    {
                        if (ex is ArgumentException)
                        {
                            throw ex;
                        }
                        return(false);
                    });
                }

                // Verify
            }
Esempio n. 3
0
            public void GreaterThanExprShouldNotAllowNullOperands()
            {
                // Prepare
                var viewModelProperty     = new FakeViewModelProperty(null);
                var greaterThanExpression = ExpressionNode.GreaterThanValue(viewModelProperty, null);

                // Act
                var taskResult = greaterThanExpression.Evaluate(new CancellationToken());

                taskResult.Start();
                try
                {
                    // to throw eventual exceptions
                    taskResult.Wait();
                }
                catch (AggregateException ae)
                {
                    ae.Flatten().Handle(ex =>
                    {
                        if (ex is InvalidOperationException)
                        {
                            throw ex;
                        }
                        return(false);
                    });
                }
            }
Esempio n. 4
0
            public void EqualToNullExprCanEvaluate()
            {
                // Prepare
                var viewModelProperty  = new FakeViewModelProperty(new object());
                var equalsToExpression = ExpressionNode.EqualToValue(viewModelProperty, null);

                // Act
                var taskResult = equalsToExpression.Evaluate(new CancellationToken());

                taskResult.RunSynchronously();

                // Verify
                Assert.IsFalse(taskResult.Result);
            }
Esempio n. 5
0
        public void CanEvaluateCustomValidationExpression()
        {
            // Prepare
            var viewModelProperty          = new FakeViewModelProperty(string.Empty);
            var customValidationExpression = ExpressionNode.CustomValidation(viewModelProperty, (value, token) => String.IsNullOrEmpty(value as string));

            // Act
            var taskResult = customValidationExpression.Evaluate(new CancellationToken());

            taskResult.RunSynchronously();

            // Verify
            Assert.IsTrue(taskResult.Result);
        }
Esempio n. 6
0
        public void CanEvaluateMatchingExpression()
        {
            // Prepare
            var viewModelProperty  = new FakeViewModelProperty("Chuck Norris");
            var matchingExpression = ExpressionNode.MatchingProperty(viewModelProperty, "^(Ch)");    // expressions that starts with 'Ch'

            // Act
            var taskResult = matchingExpression.Evaluate(new CancellationToken());

            taskResult.RunSynchronously();

            // Verify
            Assert.IsTrue(taskResult.Result);
        }
Esempio n. 7
0
            public void LessThanExprCanEvaluate()
            {
                // Prepare
                var viewModelProperty  = new FakeViewModelProperty(10);
                var lessThanExpression = ExpressionNode.LessThanValue(viewModelProperty, 5);

                // Act
                var taskResult = lessThanExpression.Evaluate(new CancellationToken());

                taskResult.RunSynchronously();

                // Verify
                Assert.IsFalse(taskResult.Result);
            }
Esempio n. 8
0
            public void EqualToNullOrEmptyExprCanEvaluate()
            {
                // Prepare
                var viewModelProperty  = new FakeViewModelProperty(string.Empty);
                var equalsToExpression = ExpressionNode.EqualToValue(viewModelProperty, "");

                // Act
                var taskResult = equalsToExpression.Evaluate(new CancellationToken());

                taskResult.RunSynchronously();

                // Verify
                Assert.IsTrue(taskResult.Result);
            }
Esempio n. 9
0
            public void EqualToLateValueExprCanEvaluate()
            {
                // Prepare
                int[] dynamicValue       = { 5 };
                var   viewModelProperty  = new FakeViewModelProperty(10);
                var   equalsToExpression = ExpressionNode.EqualToLateValue(viewModelProperty, () => dynamicValue[0]);

                // Act
                dynamicValue[0] = 10;
                var taskResult = equalsToExpression.Evaluate(new CancellationToken());

                taskResult.RunSynchronously();

                // Verify
                Assert.IsTrue(taskResult.Result);
            }