예제 #1
0
        public void QueryTree_Update()
        {
            var customType        = typeof(int);
            var customType2       = typeof(int);
            var monadMember       = (MonadMember) new MonadAbstraction(customType, inner: null);
            var lambdaAbstraction = new LambdaAbstraction(body: null, parameters: null);

            var updatedCustomType        = typeof(int);
            var updatedMonadMember       = (MonadMember) new MonadAbstraction(updatedCustomType, inner: null);
            var updatedLambdaAbstraction = new LambdaAbstraction(body: null, parameters: null);

            {
                var op        = new FirstOperator(customType, monadMember);
                var unchanged = op.Update(monadMember);

                Assert.AreSame(op, unchanged);

                var op2 = op.Update(updatedMonadMember);

                Assert.AreNotSame(op, op2);
                Assert.AreSame(updatedMonadMember, op2.Source);
            }

            {
                var op        = new FirstPredicateOperator(customType, monadMember, lambdaAbstraction);
                var unchanged = op.Update(monadMember, lambdaAbstraction);

                Assert.AreSame(op, unchanged);

                var op2 = op.Update(updatedMonadMember, lambdaAbstraction);

                Assert.AreNotSame(op, op2);
                Assert.AreSame(updatedMonadMember, op2.Source);
                Assert.AreSame(lambdaAbstraction, op2.Predicate);

                var op3 = op.Update(monadMember, updatedLambdaAbstraction);

                Assert.AreNotSame(op, op3);
                Assert.AreSame(monadMember, op3.Source);
                Assert.AreSame(updatedLambdaAbstraction, op3.Predicate);
            }

            {
                var op        = new SelectOperator(customType, customType2, monadMember, lambdaAbstraction);
                var unchanged = op.Update(monadMember, lambdaAbstraction);

                Assert.AreSame(op, unchanged);

                var op2 = op.Update(updatedMonadMember, lambdaAbstraction);

                Assert.AreNotSame(op, op2);
                Assert.AreSame(updatedMonadMember, op2.Source);
                Assert.AreSame(lambdaAbstraction, op2.Selector);

                var op3 = op.Update(monadMember, updatedLambdaAbstraction);

                Assert.AreNotSame(op, op3);
                Assert.AreSame(monadMember, op3.Source);
                Assert.AreSame(updatedLambdaAbstraction, op3.Selector);
            }

            {
                var op        = new TakeOperator(customType, monadMember, lambdaAbstraction);
                var unchanged = op.Update(monadMember, lambdaAbstraction);

                Assert.AreSame(op, unchanged);

                var op2 = op.Update(updatedMonadMember, lambdaAbstraction);

                Assert.AreNotSame(op, op2);
                Assert.AreSame(updatedMonadMember, op2.Source);
                Assert.AreSame(lambdaAbstraction, op2.Count);

                var op3 = op.Update(monadMember, updatedLambdaAbstraction);

                Assert.AreNotSame(op, op3);
                Assert.AreSame(monadMember, op3.Source);
                Assert.AreSame(updatedLambdaAbstraction, op3.Count);
            }

            {
                var op        = new WhereOperator(customType, monadMember, lambdaAbstraction);
                var unchanged = op.Update(monadMember, lambdaAbstraction);

                Assert.AreSame(op, unchanged);

                var op2 = op.Update(updatedMonadMember, lambdaAbstraction);

                Assert.AreNotSame(op, op2);
                Assert.AreSame(updatedMonadMember, op2.Source);
                Assert.AreSame(lambdaAbstraction, op2.Predicate);

                var op3 = op.Update(monadMember, updatedLambdaAbstraction);

                Assert.AreNotSame(op, op3);
                Assert.AreSame(monadMember, op3.Source);
                Assert.AreSame(updatedLambdaAbstraction, op3.Predicate);
            }

            {
                var ma        = new MonadAbstraction(customType, lambdaAbstraction);
                var unchanged = ma.Update(lambdaAbstraction);

                Assert.AreSame(ma, unchanged);

                var ma2 = ma.Update(updatedLambdaAbstraction);

                Assert.AreNotSame(ma, ma2);
                Assert.AreSame(updatedLambdaAbstraction, ma2.Inner);
            }

            {
                var lambda = Expression.Lambda(Expression.Empty(), Expression.Parameter(typeof(int)));
                var parameters = new QueryTree[] { monadMember }.ToReadOnly();
                var updatedLambda = Expression.Lambda(Expression.Empty(), Expression.Parameter(typeof(int)));
                var updatedParameters = new QueryTree[] { monadMember }.ToReadOnly();

                var la = new LambdaAbstraction(lambda, parameters);
                var unchanged = la.Update(lambda, parameters);

                Assert.AreSame(la, unchanged);

                var la2 = la.Update(updatedLambda, parameters);

                Assert.AreNotSame(la, la2);
                Assert.AreSame(updatedLambda, la2.Body);
                CollectionAssert.AreEqual(parameters, la2.Parameters);  // A ToReadOnly is called on the IE<QT>

                var la3 = la.Update(lambda, updatedParameters);

                Assert.AreNotSame(la, la3);
                Assert.AreSame(lambda, la3.Body);
                CollectionAssert.AreEqual(updatedParameters, la3.Parameters);
            }
        }