public void EnsureActionImportIsAddedAndWithCorrectEntitySetExpression()
        {
            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction action = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
            var edmEntitySet = new EdmEntitySet(container, "EntitySet", new EdmEntityType("DS", "TestEntity"));
            var entitySetExpression = new EdmEntitySetReferenceExpression(edmEntitySet);
            var actionImport = container.AddActionImport("OtherName", action, entitySetExpression);

            actionImport.Action.Should().Be(action);
            actionImport.Name.Should().Be("OtherName");
            actionImport.EntitySet.Should().Be(entitySetExpression);
            container.Elements.ToArray()[0].Should().Be(actionImport);
        }
        public void CanParse_BoundFunction_AtEntityCollection()
        {
            // Arrange
            var model = new CustomersModelWithInheritance();
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmExpression entitySet = new EdmEntitySetReferenceExpression(model.Customers);
            var function = new EdmFunction(
                model.Container.Namespace,
                "Count",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: true);
            IEdmTypeReference bindingParameterType = new EdmCollectionTypeReference(
                new EdmCollectionType(new EdmEntityTypeReference(model.Customer, isNullable: false)));
            function.AddParameter("customers", bindingParameterType);
            model.Model.AddElement(function);

            // Act
            ODataPath path = _parser.Parse(model.Model, "Customers/NS.Count");

            // Assert
            Assert.NotNull(path);
            Assert.Equal(2, path.Segments.Count);
            var functionSegment = Assert.IsType<BoundFunctionPathSegment>(path.Segments.Last());
            Assert.Same(function, functionSegment.Function);
            Assert.Empty(functionSegment.Values);
        }
 public void ResolveEntitySetFromExpressionCanResolveStaticEntitySets()
 {
     var expression = new EdmEntitySetReferenceExpression(HardCodedTestModel.GetLionSet());
     var result = EntitySetExpressionResolver.ResolveEntitySetFromExpression(expression);
     result.Should().Be(HardCodedTestModel.GetLionSet());
 }
        /// <summary>
        /// Initializes a new <see cref="IEdmOperationImport"/> instance.
        /// </summary>
        /// <param name="name">name of the service operation.</param>
        /// <param name="function">Function imported in.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
        public EdmFunctionImport AddFunctionAndFunctionImport(string name, IEdmTypeReference bindingType, IEdmTypeReference resultType, IEdmEntitySet resultSet, bool isBindable)
        {
            var edmFunction = new EdmFunction(this.Namespace, name, resultType, isBindable, null, false /*isComposable*/);
            if (isBindable)
            {
                edmFunction.AddParameter("bindingparameter", bindingType);
            }

            EdmEntitySetReferenceExpression entitySetExpression = null;
            if (resultSet != null)
            {
                entitySetExpression = new EdmEntitySetReferenceExpression(resultSet);
            }

            this.AddOperation(edmFunction);
            var functionImport = new EdmFunctionImport(this, name, edmFunction, entitySetExpression, false);
            this.AddOperationImport(name, functionImport);
            return functionImport;
        }
        public void EdmEntitySetReferenceExpression()
        {
            var container = new EdmEntityContainer("", "");
            var et = new EdmEntityType("", "");
            var e = new EdmEntitySetReferenceExpression(new EdmEntitySet(container, "qq", et));
            Assert.AreEqual(EdmExpressionKind.EntitySetReference, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual("qq", e.ReferencedEntitySet.Name, "e.ReferencedEntitySet");
            Assert.IsFalse(e.IsBad(), "e good");

            try
            {
                new EdmEntitySetReferenceExpression(null);
                Assert.Fail("exception expected.");
            }
            catch (ArgumentNullException)
            {
            }

            var ee = new MutableEntitySetReferenceExpression();
            Assert.IsNull(ee.ReferencedEntitySet, "e.ReferencedEntitySet");
            Assert.IsTrue(ee.IsBad(), "Expression is bad.");
            Assert.AreEqual(1, ee.Errors().Count(), "Expression has errors");
        }