Exemplo n.º 1
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Cast)
            {
                CastPathSegment castSegment = (CastPathSegment)pathSegment;
                return(castSegment.CastType == CastType &&
                       castSegment.CastTypeName == CastTypeName);
            }

            return(false);
        }
Exemplo n.º 2
0
        public void GetEntitySet_Returns_PreviousEntitySet()
        {
            // Arrange
            EdmEntityType castType = new EdmEntityType("NS", "Entity");
            CastPathSegment castSegment = new CastPathSegment(castType);
            IEdmEntitySet previousEntitySet = new Mock<IEdmEntitySet>().Object;

            // Act
            var result = castSegment.GetEntitySet(previousEntitySet);

            // Assert
            Assert.Same(previousEntitySet, result);
        }
Exemplo n.º 3
0
        public void GetEdmType_ReturnsCastType_IfPreviousTypeIsNotCollection()
        {
            // Arrange
            EdmEntityType castType = new EdmEntityType("NS", "Entity");
            EdmEntityType previousEdmType = new EdmEntityType("NS", "PreviousType");
            CastPathSegment castSegment = new CastPathSegment(castType);

            // Act
            var result = castSegment.GetEdmType(previousEdmType);

            // Assert
            Assert.Equal(castType, result);
        }
Exemplo n.º 4
0
        public void GetNavigationSource_Returns_PreviousEntitySet()
        {
            // Arrange
            EdmEntityType        castType    = new EdmEntityType("NS", "Entity");
            CastPathSegment      castSegment = new CastPathSegment(castType);
            IEdmNavigationSource previousNavigationSource = new Mock <IEdmNavigationSource>().Object;

            // Act
            var result = castSegment.GetNavigationSource(previousNavigationSource);

            // Assert
            Assert.Same(previousNavigationSource, result);
        }
Exemplo n.º 5
0
        public void GetEdmType_ReturnsCastType_IfPreviousTypeIsNotCollection()
        {
            // Arrange
            EdmEntityType   castType        = new EdmEntityType("NS", "Entity");
            EdmEntityType   previousEdmType = new EdmEntityType("NS", "PreviousType");
            CastPathSegment castSegment     = new CastPathSegment(castType);

            // Act
            var result = castSegment.GetEdmType(previousEdmType);

            // Assert
            Assert.Equal(castType, result);
        }
        public void GetNavigationSource_Returns_PreviousEntitySet()
        {
            // Arrange
            EdmEntityType castType = new EdmEntityType("NS", "Entity");
            CastPathSegment castSegment = new CastPathSegment(castType);
            IEdmNavigationSource previousNavigationSource = new Mock<IEdmNavigationSource>().Object;

            // Act
            var result = castSegment.GetNavigationSource(previousNavigationSource);

            // Assert
            Assert.Same(previousNavigationSource, result);
        }
Exemplo n.º 7
0
        public void GetEdmType_ReturnsCollectionCastType_IfPreviousTypeIsCollection()
        {
            // Arrange
            EdmEntityType castType = new EdmEntityType("NS", "Entity");
            EdmCollectionType previousEdmType = new EdmCollectionType(new EdmEntityType("NS", "PreviousType").AsReference());
            CastPathSegment castSegment = new CastPathSegment(castType);

            // Act
            var result = castSegment.GetEdmType(previousEdmType);

            // Assert
            Assert.Equal(EdmTypeKind.Collection, result.TypeKind);
            Assert.Equal(castType, (result as IEdmCollectionType).ElementType.Definition);
        }
Exemplo n.º 8
0
        public void GetEdmType_ReturnsCollectionCastType_IfPreviousTypeIsCollection()
        {
            // Arrange
            EdmEntityType     castType        = new EdmEntityType("NS", "Entity");
            EdmCollectionType previousEdmType = new EdmCollectionType(new EdmEntityType("NS", "PreviousType").AsReference());
            CastPathSegment   castSegment     = new CastPathSegment(castType);

            // Act
            var result = castSegment.GetEdmType(previousEdmType);

            // Assert
            Assert.Equal(EdmTypeKind.Collection, result.TypeKind);
            Assert.Equal(castType, (result as IEdmCollectionType).ElementType.Definition);
        }
Exemplo n.º 9
0
        public void TryMatch_ReturnsTrue_IfCastTypeMatch()
        {
            // Arrange
            EdmEntityType castType = new EdmEntityType("NS", "Entity");
            CastPathSegment castSegment = new CastPathSegment(castType);
            CastPathSegment pathSegment = new CastPathSegment(castType);
            Dictionary<string, object> values = new Dictionary<string,object>();

            // Act
            var result = castSegment.TryMatch(pathSegment, values);

            // Assert
            Assert.True(result);
            Assert.Empty(values);
        }
Exemplo n.º 10
0
        public void TryMatch_ReturnsTrue_IfCastTypeMatch()
        {
            // Arrange
            EdmEntityType               castType    = new EdmEntityType("NS", "Entity");
            CastPathSegment             castSegment = new CastPathSegment(castType);
            CastPathSegment             pathSegment = new CastPathSegment(castType);
            Dictionary <string, object> values      = new Dictionary <string, object>();

            // Act
            var result = castSegment.TryMatch(pathSegment, values);

            // Assert
            Assert.True(result);
            Assert.Empty(values);
        }
Exemplo n.º 11
0
        public void Translate_TypeSegment_To_CastPathSegment_Works()
        {
            // Arrange
            IEdmEntitySet  entityset  = _model.FindDeclaredEntitySet("RoutingCustomers");
            IEdmEntityType entityType = _model.FindDeclaredType("System.Web.OData.Routing.RoutingCustomer") as IEdmEntityType;
            TypeSegment    segment    = new TypeSegment(entityType, entityset);

            // Act
            IEnumerable <ODataPathSegment> segments = _translator.Translate(segment);

            // Assert
            ODataPathSegment pathSegment     = Assert.Single(segments);
            CastPathSegment  castPathSegment = Assert.IsType <CastPathSegment>(pathSegment);

            Assert.Same(entityType, castPathSegment.CastType);
        }