public void Validate_Throws_DollarCountAppliedOnNotCountableCollection(string uri, string message)
        {
            // Arrange
            IEdmModel model = GetEdmModel();
            var pathHandler = new DefaultODataPathHandler();
            string serviceRoot = "http://localhost/";
            ODataPath path = pathHandler.Parse(model, serviceRoot, uri);
            var context = new ODataQueryContext(
                model,
                EdmCoreModel.Instance.GetInt32(false).Definition,
                path);
            var option = new CountQueryOption("true", context);
            var settings = new ODataValidationSettings();

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => _validator.Validate(option, settings), message);
        }
Ejemplo n.º 2
0
        public void GetSingleEntityEntityType_ReturnsEntityTypeForSingleEntityResources(string odataPath, string typeName)
        {
            // Arrange
            IEdmModel model = SetupModel();
            IODataPathHandler pathHandler = new DefaultODataPathHandler();
            ODataPath path = pathHandler.Parse(model, "http://localhost/any", odataPath);
            // Guard
            Assert.NotNull(path);

            // Act
            IEdmEntityType entityType = ETagMessageHandler.GetSingleEntityEntityType(path);

            // Assert
            Assert.NotNull(entityType);
            Assert.Equal(typeName, entityType.FullName());
        }
        public void CanParseKeyAsSegmentUrl()
        {
            // Arrange
            string odataPath = "RoutingCustomers/112";
            string expectedText = "112";
            IEdmEntitySet expectedSet = _model.EntityContainer.EntitySets().SingleOrDefault(s => s.Name == "RoutingCustomers");
            var simplifiedParser = new DefaultODataPathHandler();
            simplifiedParser.ResolverSetttings.UrlConventions = ODataUrlConventions.ODataSimplified;

            // Act
            ODataPath path = simplifiedParser.Parse(_model, _serviceRoot, odataPath);
            ODataPathSegment segment = path.Segments.Last();

            // Assert
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.IsType<KeyValuePathSegment>(segment);
            Assert.Same(expectedSet, path.NavigationSource);
            Assert.Same(expectedSet.EntityType(), path.EdmType);
        }
            internal static IDictionary<string, string> GetKeys(DefaultODataPathHandler pathHandler, IEdmModel edmModel, string serviceRoot, Uri uri)
            {
                ODataPath odataPath = pathHandler.Parse(edmModel, serviceRoot, uri.ToString());
                KeyValuePathSegment segment = odataPath.Segments.OfType<KeyValuePathSegment>().Last();
                if (segment == null)
                {
                    throw Error.InvalidOperation(SRResources.EntityReferenceMustHasKeySegment, uri);
                }

                return segment.Values;
            }
        public void PrefixFreeEnumValue_Works_PrefixFreeResolver(string path, string template, string expect)
        {
            // Arrange & Act
            // Arrange
            DefaultODataPathHandler pathHandler = new DefaultODataPathHandler
            {
                ResolverSetttings = new ODataUriResolverSetttings
                {
                    EnumPrefixFree = true
                }
            };

            // Act
            ODataPath odataPath = pathHandler.Parse(_model, _serviceRoot, path);

            // Assert
            Assert.NotNull(odataPath);
            Assert.Equal(template, odataPath.PathTemplate);
            Assert.Equal(expect, odataPath.ToString());
        }
        public void Unqualified_Works_CustomUriResolverHandler(string path, string template, string expect)
        {
            // Arrange
            DefaultODataPathHandler pathHandler = new DefaultODataPathHandler
            {
                ResolverSetttings = new ODataUriResolverSetttings
                {
                    CaseInsensitive = true,
                    UnqualifiedNameCall = true
                }
            };

            // Act
            ODataPath odataPath = pathHandler.Parse(_model, _serviceRoot, path);

            // Assert
            Assert.NotNull(odataPath);
            Assert.Equal(template, odataPath.PathTemplate);
            Assert.Equal(expect, odataPath.ToString());
        }
        public void DefaultUriResolverHandler_Works_CaseInsensitive(string path, string template, string expect)
        {
            // Arrange & Act
            DefaultODataPathHandler pathHandler = new DefaultODataPathHandler
            {
                ResolverSetttings = new ODataUriResolverSetttings
                {
                    CaseInsensitive = true,
                }
            };

            ODataPath odataPath = pathHandler.Parse(_model, _serviceRoot, path);

            // Assert
            Assert.NotNull(odataPath);
            Assert.Equal(template, odataPath.PathTemplate);
            Assert.Equal(expect, odataPath.ToString());
        }
        public void GetODataPayloadSerializer_ReturnsRawValueSerializer_ForDollarCountRequests(string uri, Type elementType)
        {
            // Arrange
            IEdmModel model = ODataCountTest.GetEdmModel();
            Type type = typeof(ICollection<>).MakeGenericType(elementType);
            var request = new HttpRequestMessage();
            var pathHandler = new DefaultODataPathHandler();
            var path = pathHandler.Parse(model, "http://localhost/", uri);
            request.ODataProperties().Path = path;
            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider();

            // Act
            var serializer = serializerProvider.GetODataPayloadSerializer(model, type, request);

            // Assert
            Assert.NotNull(serializer);
            var rawValueSerializer = Assert.IsType<ODataRawValueSerializer>(serializer);
            Assert.Equal(ODataPayloadKind.Value, rawValueSerializer.ODataPayloadKind);
        }
        public void GetResponseStatusCode_ReturnsNoContentForProperties_AndNotFoundForEntities(string odataPath,
            HttpStatusCode? expected)
        {
            // Arrange
            IEdmModel model = BuildModel();
            IODataPathHandler pathHandler = new DefaultODataPathHandler();
            ODataPath path = pathHandler.Parse(model, "http://localhost/any", odataPath);
            // Guard
            Assert.NotNull(path);

            // Act
            HttpStatusCode? statusCode = ODataNullValueMessageHandler.GetUpdatedResponseStatusCodeOrNull(path);

            // Assert
            Assert.Equal(expected, statusCode);
        }