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); }
public void EntityItemTypeIsSameAsItemType() { EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet()); EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType()); entityCollectionCastNode.EntityItemType.Should().BeSameAs(entityCollectionCastNode.ItemType); }
public void ItemTypeReturnsEdmEntityTypeReference() { EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet()); EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType()); entityCollectionCastNode.ItemType.Should().BeOfType <EdmEntityTypeReference>(); }
public void EntitySetComesFromSource() { EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet()); EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType()); entityCollectionCastNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet()); }
public void KindIsEntityCollectionCastNode() { EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet()); EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType()); entityCollectionCastNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityCollectionCast); }
public void ItemTypeReferenceShouldBeCreatedFromConstructorParameter() { var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType()); node.ItemType.Definition.Should().BeSameAs(HardCodedTestModel.GetEmployeeType()); node.ItemType.IsNullable.Should().BeFalse(); }
public void SourceIsSetCorrectly() { EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet()); EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType()); entityCollectionCastNode.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet()); }
/// <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); }
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); }
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); }
/// <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); }
/// <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)); }
/// <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); }
public void EntityItemTypeShouldBeSameAsItemType() { var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType()); node.EntityItemType.Should().BeSameAs(node.ItemType); }
public void CollectionTypeShouldBeCreatedFromItemType() { var node = new EntityCollectionCastNode(fakeSource, HardCodedTestModel.GetEmployeeType()); node.CollectionType.FullName().Should().Be("Collection(Fully.Qualified.Namespace.Employee)"); }
public override IEnumerable <string> Visit(EntityCollectionCastNode nodeIn) { return(nodeIn.Source.Accept(this)); }
/// <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())); }
/// <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 ItemTypeReturnsEdmEntityTypeReference() { EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet()); EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType()); entityCollectionCastNode.ItemType.Should().BeOfType<EdmEntityTypeReference>(); }
/// <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(); }
/// <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)); }
/// <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(); }
/// <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())); }