Пример #1
0
        private void TestCast <TParam, TReturn>(EntityCollectionNode source, IEdmEntityType cast, Expression <Func <TParam, TReturn> > expectedExpression)
        {
            var node   = new EntityCollectionCastNode(source, cast);
            var result = this.testSubject.TranslateNode(node);

            CompareExpressions(expectedExpression.Body, result);
        }
Пример #2
0
        public void EntityItemTypeIsSameAsItemType()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.EntityItemType.Should().BeSameAs(entityCollectionCastNode.ItemType);
        }
Пример #3
0
        public void ItemTypeReturnsEdmEntityTypeReference()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.ItemType.Should().BeOfType <EdmEntityTypeReference>();
        }
Пример #4
0
        public void EntitySetComesFromSource()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
Пример #5
0
        public void KindIsEntityCollectionCastNode()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityCollectionCast);
        }
Пример #6
0
        public void ItemTypeReferenceShouldBeCreatedFromConstructorParameter()
        {
            var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.ItemType.Definition.Should().BeSameAs(HardCodedTestModel.GetEmployeeType());
            node.ItemType.IsNullable.Should().BeFalse();
        }
Пример #7
0
        public void SourceIsSetCorrectly()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet());
        }
Пример #8
0
        /// <summary>
        /// Override this method if you want to validate casts on entity collections.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="entityCollectionCastNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateEntityCollectionCastNode(EntityCollectionCastNode entityCollectionCastNode, ODataValidationSettings settings)
        {
            if (entityCollectionCastNode == null)
            {
                throw Error.ArgumentNull("entityCollectionCastNode");
            }

            ValidateQueryNode(entityCollectionCastNode.Source, settings);
        }
Пример #9
0
        public void TranslatorShouldRequireProtocolVersionThreeForCollectionTypeSegment()
        {
            ODataProtocolVersion validatedProtocolVersion = ODataProtocolVersion.V4;
            var withVersionCallbacks = this.CreateTestSubject(verifyProtocolVersion: v => { validatedProtocolVersion = v; }, verifyRequestVersion: v => { throw new Exception("Should not be called."); });

            QueryNode node = new EntityCollectionCastNode(this.CollectionNavigationFromParameter("o"), this.customerEdmType);

            withVersionCallbacks.TranslateNode(node);
            validatedProtocolVersion.Should().Be(ODataProtocolVersion.V4);
        }
Пример #10
0
        public void TranslatorShouldConvertWeaklyBackedEntityCollectionCast()
        {
            EntityCollectionNode source = this.CollectionNavigationFromParameter("c");
            QueryNode            node   = new EntityCollectionCastNode(source, this.weaklyBackedCustomerEdmType);
            var result = this.testSubject.TranslateNode(node);

            var parameterExpression = Expression.Parameter(typeof(Customer), "c");
            var propertyExpression  = Expression.Property(parameterExpression, "OtherFriends");
            var expected            = Expression.Call(typeof(DataServiceProviderMethods), "OfType", new[] { typeof(Customer), typeof(object) }, propertyExpression, Expression.Constant(this.weaklyBackedDerivedType));

            expected = Expression.Call(typeof(Enumerable), "Cast", new[] { typeof(object) }, expected);
            CompareExpressions(expected, result);
        }
Пример #11
0
        /// <summary>
        /// Writes entity collection cast node to string.
        /// </summary>
        /// <param name="node">Node to write to string</param>
        /// <returns>String representation of node.</returns>
        private static string ToString(EntityCollectionCastNode node)
        {
            if (node != null)
            {
                return(tabHelper.Prefix + "EntityCollectionCastNode" +
                       tabHelper.Indent(() =>
                                        tabHelper.Prefix + "Entity Item Type = " + node.EntityItemType +
                                        tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
                                        tabHelper.Prefix + "Item Type = " + node.ItemType +
                                        tabHelper.Prefix + "Source = " + ToString(node.Source)
                                        ));
            }

            return(String.Empty);
        }
Пример #12
0
 /// <summary>
 /// Compares collection cast nodes.
 /// </summary>
 /// <param name="left">Left side of comparison</param>
 /// <param name="right">Right side of comparison</param>
 /// <returns>True if equal, otherwise false</returns>
 private bool Compare(EntityCollectionCastNode left, EntityCollectionCastNode right)
 {
     if (left.EntityItemType != right.EntityItemType)
     {
         return(false);
     }
     if (left.NavigationSource != right.NavigationSource)
     {
         return(false);
     }
     if (left.ItemType != right.ItemType)
     {
         return(false);
     }
     return(this.Compare(left.Source, right.Source));
 }
Пример #13
0
 /// <summary>
 /// Compares collection cast nodes.
 /// </summary>
 /// <param name="left">Left side of comparison</param>
 /// <param name="right">Right side of comparison</param>
 /// <returns>True if equal, otherwise false</returns>
 private bool Compare(EntityCollectionCastNode left, EntityCollectionCastNode right)
 {
     if (left.EntityItemType != right.EntityItemType) return false;
     if (left.NavigationSource != right.NavigationSource) return false;
     if (left.ItemType != right.ItemType) return false;
     return this.Compare(left.Source, right.Source);
 }
Пример #14
0
        public void EntityItemTypeShouldBeSameAsItemType()
        {
            var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.EntityItemType.Should().BeSameAs(node.ItemType);
        }
Пример #15
0
        public void CollectionTypeShouldBeCreatedFromItemType()
        {
            var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());

            node.CollectionType.FullName().Should().Be("Collection(Fully.Qualified.Namespace.Employee)");
        }
Пример #16
0
 public override IEnumerable <string> Visit(EntityCollectionCastNode nodeIn)
 {
     return(nodeIn.Source.Accept(this));
 }
 public void CollectionTypeShouldBeCreatedFromItemType()
 {
     var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());
     node.CollectionType.FullName().Should().Be("Collection(Fully.Qualified.Namespace.Employee)");
 }
 public void ItemTypeReferenceShouldBeCreatedFromConstructorParameter()
 {
     var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());
     node.ItemType.Definition.Should().BeSameAs(HardCodedTestModel.GetEmployeeType());
     node.ItemType.IsNullable.Should().BeFalse();
 }
        /// <summary>
        /// Override this method if you want to validate casts on entity collections.
        /// </summary>
        /// <remarks>
        /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
        /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
        /// </remarks>
        /// <param name="entityCollectionCastNode"></param>
        /// <param name="settings"></param>
        public virtual void ValidateEntityCollectionCastNode(EntityCollectionCastNode entityCollectionCastNode, ODataValidationSettings settings)
        {
            if (entityCollectionCastNode == null)
            {
                throw Error.ArgumentNull("entityCollectionCastNode");
            }

            ValidateQueryNode(entityCollectionCastNode.Source, settings);
        }
 /// <summary>
 /// Translates a <see cref="EntityCollectionCastNode"/> into a corresponding <see cref="string"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated string of EntityCollectionCastNode.</returns>
 public override string Visit(EntityCollectionCastNode node)
 {
     return(this.TranslatePropertyAccess(node.Source, node.EntityItemType.Definition.ToString()));
 }
Пример #21
0
        /// <summary>
        /// Writes entity collection cast node to string.
        /// </summary>
        /// <param name="node">Node to write to string</param>
        /// <returns>String representation of node.</returns>
        private static string ToString(EntityCollectionCastNode node)
        {
            if (node != null)
            {
                return tabHelper.Prefix + "EntityCollectionCastNode" +
                 tabHelper.Indent(() =>
                    tabHelper.Prefix + "Entity Item Type = " + node.EntityItemType +
                    tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
                    tabHelper.Prefix + "Item Type = " + node.ItemType +
                    tabHelper.Prefix + "Source = " + ToString(node.Source)
                );
            }

            return String.Empty;
        }
 public void EntitySetComesFromSource()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
 public void ItemTypeReturnsEdmEntityTypeReference()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.ItemType.Should().BeOfType<EdmEntityTypeReference>();
 }
 public void EntityItemTypeShouldBeSameAsItemType()
 {
     var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType());
     node.EntityItemType.Should().BeSameAs(node.ItemType);
 }
 /// <summary>
 /// Visit an EntityCollectionCastNode
 /// </summary>
 /// <param name="nodeIn">the node to visit</param>
 /// <returns>Defined by the implementer</returns>
 public virtual T Visit(EntityCollectionCastNode nodeIn)
 {
     throw new NotImplementedException();
 }
 public void SourceIsSetCorrectly()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet());
 }
 /// <summary>
 /// Translate an EntityCollectionCastNode.
 /// </summary>
 /// <param name="nodeIn">The node to be translated.</param>
 /// <returns>The translated node.</returns>
 public override QueryNode Visit(EntityCollectionCastNode nodeIn)
 {
     return(new EntityCollectionCastNode(
                (EntityCollectionNode)nodeIn.Source.Accept(this),
                (IEdmEntityType)nodeIn.ItemType.Definition));
 }
 public void EntityItemTypeIsSameAsItemType()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.EntityItemType.Should().BeSameAs(entityCollectionCastNode.ItemType);
 }
Пример #29
0
 /// <summary>
 /// Visit an EntityCollectionCastNode
 /// </summary>
 /// <param name="nodeIn">The node to visit</param>
 /// <returns>The translated expression</returns>
 public override Expression Visit(EntityCollectionCastNode nodeIn)
 {
     throw new NotImplementedException();
 }
 public void KindIsEntityCollectionCastNode()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityCollectionCast);
 }
Пример #31
0
 /// <summary>
 /// Translates a <see cref="EntityCollectionCastNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String of EntityCollectionCastNode.</returns>
 public override String Visit(EntityCollectionCastNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.EntityItemType.Definition.ToString()));
 }