public void EdmActionConstructorShouldHaveSpecifiedConstructorValues()
 {
     var entitySetPath = new EdmPathExpression("Param1/Nav");
     var edmAction = new EdmAction(defaultNamespaceName, checkout, this.boolType, true, entitySetPath);
     edmAction.AddParameter(new EdmOperationParameter(edmAction, "Param1", new EdmEntityTypeReference(personType, false)));
     edmAction.Namespace.Should().Be(defaultNamespaceName);
     edmAction.Name.Should().Be(checkout);
     edmAction.ReturnType.Should().Be(this.boolType);
     edmAction.EntitySetPath.Should().Be(entitySetPath);
     edmAction.IsBound.Should().BeTrue();
     edmAction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Action);
 }
 public void EdmActionImportConstructorShouldHaveSpecifiedConstructorValues()
 {
     var actionEntitySetPath = new EdmPathExpression("Param1/Nav");
     var edmAction = new EdmAction("DefaultNamespace", "Checkout", this.boolType, true, actionEntitySetPath);
     edmAction.AddParameter(new EdmOperationParameter(edmAction, "Param1", new EdmEntityTypeReference(personType, true)));
     
     var actionImportEntitySetPath = new EdmPathExpression("Param1/Nav2");
     var edmActionImport = new EdmActionImport(this.entityContainer, "checkoutImport", edmAction, actionImportEntitySetPath);
     edmActionImport.Name.Should().Be("checkoutImport");
     edmActionImport.Container.Should().Be(this.entityContainer);
     edmActionImport.EntitySet.Should().Be(actionImportEntitySetPath);
     edmActionImport.Action.Should().Be(edmAction);
 }
        private static IEdmEntitySetBase GetTargetEntitySet(EdmPathExpression edmPathExpression, out IEdmEntitySet targetEntitySet, bool addParameters = false, bool isBindable = true)
        {
            var model = new EdmModel();
            var container = new EdmEntityContainer("Fake", "Container");
            model.AddElement(container);
            var edmEntityType = new EdmEntityType("Fake", "EntityType");

            var sourceEntitySet = container.AddEntitySet("SourceEntitySet", edmEntityType);
            var middleEntitySet = container.AddEntitySet("MiddleEntitySet", edmEntityType);
            targetEntitySet = container.AddEntitySet("TargetEntitySet", edmEntityType);

            var nav1 = edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation1", Target = edmEntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
            var nav2 = edmEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation2", Target = edmEntityType, TargetMultiplicity = EdmMultiplicity.Many });

            sourceEntitySet.AddNavigationTarget(nav1, middleEntitySet);
            middleEntitySet.AddNavigationTarget(nav2, targetEntitySet);

            var action = new EdmAction("Fake", "FakeAction", new EdmEntityTypeReference(edmEntityType, false), isBindable, null /*EntitySetPath*/);
            if (addParameters)
            {
                action.AddParameter("p1", new EdmEntityTypeReference(edmEntityType, false));
                action.AddParameter("p2", new EdmEntityTypeReference(edmEntityType, false));
            }

            var actionImport = container.AddActionImport("FakeAction", action, edmPathExpression);
          
            return actionImport.GetTargetEntitySet(sourceEntitySet, model);
        }
 public void GetTargetEntitySetForFunctionWithNoStaticSetOrSourceSetShouldBeNull()
 {
     var model = new EdmModel();
     var container = new EdmEntityContainer("Fake", "Container");
     model.AddElement(container);
     var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(new EdmEntityType("Fake", "EntityType"), false));
     var expression = new EdmPathExpression("p1/Navigation1");
     var operationImport = container.AddFunctionImport("FakeAction", function, expression);
     operationImport.GetTargetEntitySet(null, model).Should().BeNull();
 }
Beispiel #5
0
        public void EvaluatePathOverValueWithManyProperties()
        {
            List<IEdmPropertyValue> contextValues = new List<IEdmPropertyValue>();
            for (int i = 0; i < 10000; i++)
            {
                contextValues.Add(new EdmPropertyValue("P" + i.ToString(), new EdmIntegerConstant(i)));
            }

            EdmStructuredValue context = new EdmStructuredValue(null, contextValues);

            EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(this.builtInFunctions);

            EdmPathExpression path = new EdmPathExpression("P0");
            IEdmValue first = evaluator.Evaluate(path, context);
            Assert.AreEqual(0, ((IEdmIntegerValue)first).Value, "Property value");

            path = new EdmPathExpression("P555");
            IEdmValue middle = evaluator.Evaluate(path, context);
            Assert.AreEqual(555, ((IEdmIntegerValue)middle).Value, "Property value");

            path = new EdmPathExpression("P9999");
            IEdmValue last = evaluator.Evaluate(path, context);
            Assert.AreEqual(9999, ((IEdmIntegerValue)last).Value, "Property value");
        }
Beispiel #6
0
        public void EvaluatePathUsesFindProperty()
        {
            bool caught = false;

            try
            {
                EdmPathExpression path = new EdmPathExpression("Gronk");
                new EdmExpressionEvaluator(this.builtInFunctions).Evaluate(path, new ThrowingValue());
            }
            catch (FindPropertyValue)
            {
                caught = true;
            }
            catch (EnumeratePropertyValues)
            {
                Assert.Fail("Enumerated property values");
            }

            Assert.IsTrue(caught, "Find property value");
        }
Beispiel #7
0
        public void EvaluateExpressionsDuplicatePropertiesTest()
        {
            var aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueTwo")),
            });
            var evaluator = new EdmExpressionEvaluator(null);
            var pathP1 = new EdmPathExpression("P1");
            Assert.AreEqual("aStringValueOne", ((IEdmStringConstantExpression)evaluator.Evaluate(pathP1, aValue)).Value, "The evaluated value is not correct.");

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("", new EdmStringConstant("aStringValueTwo")),
            });
            var pathEmpty = new EdmPathExpression("");
            Assert.AreEqual("aStringValueOne", ((IEdmStringConstantExpression)evaluator.Evaluate(pathEmpty, aValue)).Value, "The evaluated value is not correct.");
        }
Beispiel #8
0
        //[TestMethod, Variation(Id = 102, SkipReason=@"[EdmLib] EdmExpressionEvaluator throws NullReferenceException when EdmStructureValue has null properties. -- postponed")]
        public void EvaluateExpressionsNullPropertiesTest()
        {
            var aValue = new EdmStructuredValue(null, null);
            EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null);
            var path = new EdmPathExpression();
            this.VerifyThrowsException(typeof(ArgumentNullException), () => evaluator.Evaluate(path, aValue));

            path = new EdmPathExpression("path");
            this.VerifyThrowsException(typeof(ArgumentNullException), () => evaluator.Evaluate(path, aValue)); // System.NullReferenceException
        }
Beispiel #9
0
        public void EvaluateExpressionsInvalidCasesTest()
        {
            Action<IEnumerable<IEdmPropertyValue>, IEnumerable<IEdmPropertyValue>> compareProperties = (expected, actual) =>
                {
                    Assert.IsTrue(expected == null && actual == null || expected.Count() == actual.Count() && !expected.Except(actual).Any(), "Actual property values are different from the expected ones.");
                };
            var pathInvalid = new EdmPathExpression("DoesNotExist.><#!");
            var pathNoSegment = new EdmPathExpression();
            var pathValid = new EdmPathExpression("P1");
            var pathValidInvalid = new EdmPathExpression("P1", "DoesNotExist.><#!");
            EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null);

            IEdmStructuredValue aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValue")),
                new EdmPropertyValue("P3", new EdmIntegerConstant(110))
            });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathNoSegment));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathNoSegment, null));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => evaluator.Evaluate(pathNoSegment, aValue, null));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathValid, aValue, EdmCoreModel.Instance.GetInt32(true)));
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathValidInvalid, aValue));

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[] { });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));


            aValue = new MutableStructuredValue();
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("", new EdmStringConstant("aStringValue")),
                new EdmPropertyValue("", new EdmStringConstant("aStringValue")),
            });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueOne")),
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueTwo")),
            });
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            this.VerifyThrowsException(typeof(InvalidOperationException), () => evaluator.Evaluate(pathInvalid, aValue));

            aValue = new EdmStructuredValue(null, new IEdmPropertyValue[]
            {
                new MutablePropertyValue() { Value = new EdmStringConstant("aStringValueOne") },
                new EdmPropertyValue("P1", new EdmStringConstant("aStringValueTwo")),
            });
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmPathExpression((string)null));
            compareProperties(aValue.PropertyValues, ((IEdmStructuredValue)evaluator.Evaluate(pathNoSegment, aValue)).PropertyValues);
            Assert.AreEqual("aStringValueTwo", ((IEdmStringConstantExpression)evaluator.Evaluate(pathValid, aValue)).Value, "The evaluated value is not correct.");
        }
        public void EdmPathExpression()
        {
            var e = new EdmPathExpression("x", "y");
            Assert.IsFalse(e.IsBad(), "e good");
            Assert.AreEqual(EdmExpressionKind.Path, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual(2, e.Path.Count(), "e.Path.Count()");
            var s1 = e.Path.First();
            Assert.AreEqual("x", s1, "s1");
            Assert.AreEqual("y", e.Path.Last(), "e.Path.Last()");

            try
            {
                new EdmPathExpression((string[])null);
                Assert.Fail("exception expected");
            }
            catch (ArgumentNullException)
            {
            }

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