private void TestCast <TParam, TReturn>(SingleEntityNode source, IEdmEntityType cast, Expression <Func <TParam, TReturn> > expectedExpression) { var node = new SingleEntityCastNode(source, cast); var result = this.testSubject.TranslateNode(node); CompareExpressions(expectedExpression.Body, result); }
/// <summary> /// Translate a SingleEntityCastNode. /// </summary> /// <param name="nodeIn">The node to be translated.</param> /// <returns>The translated node.</returns> public override QueryNode Visit(SingleEntityCastNode nodeIn) { return(nodeIn.Source == null ? nodeIn : new SingleEntityCastNode( (SingleEntityNode)nodeIn.Source.Accept(this), (IEdmEntityType)nodeIn.TypeReference.Definition)); }
/// <summary> /// Override this method if you want to validate casts on single entities. /// </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="singleEntityCastNode"></param> /// <param name="settings"></param> public virtual void ValidateSingleEntityCastNode(SingleEntityCastNode singleEntityCastNode, ODataValidationSettings settings) { if (singleEntityCastNode == null) { throw Error.ArgumentNull("singleEntityCastNode"); } ValidateQueryNode(singleEntityCastNode.Source, settings); }
public void TranslatorShouldRequireProtocolVersionThreeForSingletonTypeSegment() { ODataProtocolVersion validatedProtocolVersion = ODataProtocolVersion.V4; var withVersionCallbacks = this.CreateTestSubject(verifyProtocolVersion: v => { validatedProtocolVersion = v; }, verifyRequestVersion: v => { throw new Exception("Should not be called."); }); QueryNode node = new SingleEntityCastNode(this.EntityParameter <Customer>("o"), this.customerEdmType); withVersionCallbacks.TranslateNode(node); validatedProtocolVersion.Should().Be(ODataProtocolVersion.V4); }
public void GetNavigationNodeCreatesCollectionNavigationNodeForManyMultiplicityProperty() { IEdmNavigationProperty property = HardCodedTestModel.GetDogMyPeopleNavProp(); SingleEntityNode parent = new SingleEntityCastNode(null, HardCodedTestModel.GetDogType()); BindingState state = new BindingState(configuration); KeyBinder keyBinder = new KeyBinder(FakeBindMethods.BindMethodReturningASingleDog); var result = InnerPathTokenBinder.GetNavigationNode(property, parent, null, state, keyBinder); result.ShouldBeCollectionNavigationNode(property); }
public void TranslatorShouldConvertWeaklyBackedSingleEntityCast() { SingleEntityNode source = EntityParameter <Customer>("c"); QueryNode node = new SingleEntityCastNode(source, this.weaklyBackedCustomerEdmType); var result = this.testSubject.TranslateNode(node); var parameterExpression = Expression.Parameter(typeof(Customer), "c"); var expected = Expression.Call(typeof(DataServiceProviderMethods), "TypeAs", new[] { typeof(object) }, parameterExpression, Expression.Constant(this.weaklyBackedDerivedType)); CompareExpressions(expected, result); }
/// <summary> /// Writes single entity cast node to string. /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToString(SingleEntityCastNode node) { if (node != null) { return(tabHelper.Prefix + "SingleEntityCastNode" + tabHelper.Indent(() => tabHelper.Prefix + "Type Reference = " + node.TypeReference + tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name + tabHelper.Prefix + "Entity Type Reference = " + node.EntityTypeReference + tabHelper.Prefix + "Source = " + ToString(node.Source) )); } return(String.Empty); }
/// <summary> /// Compares single cast query 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(SingleEntityCastNode left, SingleEntityCastNode right) { if (left.NavigationSource != right.NavigationSource) { return(false); } if (left.EntityTypeReference != right.EntityTypeReference) { return(false); } if (left.TypeReference != right.TypeReference) { return(false); } return(this.Compare(left.Source, right.Source)); }
/// <summary> /// Visit a SingleEntityCastNode /// </summary> /// <param name="nodeIn">The node to visit</param> /// <returns>The translated expression</returns> public override Expression Visit(SingleEntityCastNode nodeIn) { this.CheckArgumentNull(nodeIn, "node"); return(this.TranslateSingleValueCastAccess(nodeIn.Source, nodeIn.TypeReference)); }
public void SourceIsSetCorrectly() { SingleEntityCastNode singleEntityCast = new SingleEntityCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType()); singleEntityCast.Source.Should().Be(this.singleEntityNode); }
public void KindIsSingleEntityCastNode() { SingleEntityCastNode singleEntityCast = new SingleEntityCastNode(this.singleEntityNode, HardCodedTestModel.GetDogType()); singleEntityCast.InternalKind.Should().Be(InternalQueryNodeKind.SingleEntityCast); }
public void EntityTypeReferenceIsSameAsTypeReference() { SingleEntityCastNode singleEntityCast = new SingleEntityCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType()); singleEntityCast.EntityTypeReference.Should().BeSameAs(singleEntityCast.TypeReference); }
public void TypeReferenceIsSetCorrectly() { SingleEntityCastNode singleEntityCast = new SingleEntityCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType()); singleEntityCast.TypeReference.FullName().Should().Be(HardCodedTestModel.GetPersonType().FullName()); }
/// <summary> /// Writes single entity cast node to string. /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToString(SingleEntityCastNode node) { if (node != null) { return tabHelper.Prefix + "SingleEntityCastNode" + tabHelper.Indent(() => tabHelper.Prefix + "Type Reference = " + node.TypeReference + tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name + tabHelper.Prefix + "Entity Type Reference = " + node.EntityTypeReference + tabHelper.Prefix + "Source = " + ToString(node.Source) ); } return String.Empty; }
/// <summary> /// Compares single cast query 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(SingleEntityCastNode left, SingleEntityCastNode right) { if (left.NavigationSource != right.NavigationSource) return false; if (left.EntityTypeReference != right.EntityTypeReference) return false; if (left.TypeReference != right.TypeReference) return false; return this.Compare(left.Source, right.Source); }
public override IEnumerable <string> Visit(SingleEntityCastNode nodeIn) { return(nodeIn.Source.Accept(this)); }
/// <summary> /// Translates a <see cref="SingleEntityCastNode"/> into a corresponding <see cref="String"/>. /// </summary> /// <param name="node">The node to translate.</param> /// <returns>The translated String.</returns> public override String Visit(SingleEntityCastNode node) { ExceptionUtils.CheckArgumentNotNull(node, "node"); return(this.TranslatePropertyAccess(node.Source, node.EntityTypeReference.Definition.ToString())); }
/// <summary> /// Visit a SingleEntityCastNode /// </summary> /// <param name="nodeIn">the node to visit</param> /// <returns>Defined by the implementer</returns> public virtual T Visit(SingleEntityCastNode nodeIn) { throw new NotImplementedException(); }
/// <summary> /// Translates a <see cref="SingleEntityCastNode"/> into a corresponding <see cref="string"/>. /// </summary> /// <param name="node">The node to translate.</param> /// <returns>The translated string.</returns> public override string Visit(SingleEntityCastNode node) { return(this.TranslatePropertyAccess(node.Source, node.EntityTypeReference.Definition.ToString())); }