public void EdmApplyExpression()
        {
            var arguments         = new IEdmExpression[] { new EdmIntegerConstant(1) };
            var appliedExpression = new EdmStringConstant("foo");
            var e = new EdmApplyExpression(appliedExpression, arguments);

            Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(appliedExpression, e.AppliedOperation, "e.AppliedFunction");
            Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction");
            Assert.IsFalse(e.IsBad(), "e good");

            var operation          = new EdmFunction("NS", "function", new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true));
            var operationReference = new EdmOperationReferenceExpression(operation);

            e = new EdmApplyExpression(operationReference, arguments);
            Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(operationReference, e.AppliedOperation, "e.AppliedFunction");
            Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction");
            Assert.IsFalse(e.IsBad(), "e good");

            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmExpression)null, arguments));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments.AsEnumerable()));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(new EdmStringConstant("foo"), null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, (IEnumerable <IEdmExpression>)null));

            var ee = new MutableEdmApplyExpression();

            Assert.IsNull(ee.AppliedOperation, "ee.AppliedFunction");
            Assert.IsNull(ee.Arguments, "ee.Arguments");
            Assert.IsTrue(ee.IsBad(), "Expression is bad.");
            Assert.AreEqual(2, ee.Errors().Count(), "Expression has no errors");
        }
        public void ValueTerm_FunctionApplication_OnEntityContainer()
        {
            this.SetupModels();

            var container = new EdmEntityContainer("NS1", "myContainer");

            (this.baseModel as EdmModel).AddElement(container);

            IEdmValueTerm termStringValue = this.longDefinitionModel.FindValueTerm("bar.StringValue");
            var           apply           = new EdmApplyExpression(
                this.functionsModel.FindOperations("Functions.StringConcat").First(),
                new EdmStringConstant("s1"),
                new EdmStringConstant("s2"));

            this.CreateAndAttachValueAnnotation(container, termStringValue, apply);

            string expectedCsdl =
                @"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <EntityType Name=""Person"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" />
        <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" />
    </EntityType>
    <EntityContainer Name=""myContainer"" />
    <Annotations Target=""NS1.myContainer"">
        <Annotation Term=""bar.StringValue"">
            <Apply Function=""Functions.StringConcat"">
                <String>s1</String>
                <String>s2</String>
            </Apply>
        </Annotation>
    </Annotations>
</Schema>";

            this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl);
        }
        public void ValueTerm_FunctionApplication_OnEntityContainer()
        {
            this.SetupModels();

            var container = new EdmEntityContainer("NS1", "myContainer");
            (this.baseModel as EdmModel).AddElement(container);

            IEdmValueTerm termStringValue = this.longDefinitionModel.FindValueTerm("bar.StringValue");
            var apply = new EdmApplyExpression(
                this.functionsModel.FindOperations("Functions.StringConcat").First(),
                new EdmStringConstant("s1"),
                new EdmStringConstant("s2"));
            this.CreateAndAttachValueAnnotation(container, termStringValue, apply);

            string expectedCsdl =
@"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <EntityType Name=""Person"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" />
        <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" />
    </EntityType>
    <EntityContainer Name=""myContainer"" />
    <Annotations Target=""NS1.myContainer"">
        <Annotation Term=""bar.StringValue"">
            <Apply Function=""Functions.StringConcat"">
                <String>s1</String>
                <String>s2</String>
            </Apply>
        </Annotation>
    </Annotations>
</Schema>";
            this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl);
        }
        public void EdmApplyExpression()
        {
            var arguments = new IEdmExpression[] { new EdmIntegerConstant(1) };
            var appliedExpression = new EdmStringConstant("foo");
            var e = new EdmApplyExpression(appliedExpression, arguments);
            Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(appliedExpression, e.AppliedOperation, "e.AppliedFunction");
            Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction");
            Assert.IsFalse(e.IsBad(), "e good");

            var operation = new EdmFunction("NS", "function", new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true));
            var operationReference = new EdmOperationReferenceExpression(operation);
            e = new EdmApplyExpression(operationReference, arguments);
            Assert.AreEqual(EdmExpressionKind.OperationApplication, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(operationReference, e.AppliedOperation, "e.AppliedFunction");
            Assert.AreEqual(arguments, e.Arguments, "e.AppliedFunction");
            Assert.IsFalse(e.IsBad(), "e good");

            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmExpression)null, arguments));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression((IEdmOperation)null, arguments.AsEnumerable()));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(new EdmStringConstant("foo"), null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmApplyExpression(operation, (IEnumerable<IEdmExpression>)null));

            var ee = new MutableEdmApplyExpression();
            Assert.IsNull(ee.AppliedOperation, "ee.AppliedFunction");
            Assert.IsNull(ee.Arguments, "ee.Arguments");
            Assert.IsTrue(ee.IsBad(), "Expression is bad.");
            Assert.AreEqual(2, ee.Errors().Count(), "Expression has no errors");
        }