public void UriParserExceptionDataTest() { Action parsePath = () => this.testSubject.ParsePath(new[] { "Dogs(1)", "UNKNOW", "$ref" }); ODataUnrecognizedPathException ex = parsePath.ShouldThrow <ODataUnrecognizedPathException>().And; ex.ParsedSegments.As <IEnumerable <ODataPathSegment> >().Count().Should().Be(2); ex.CurrentSegment.Should().Be("UNKNOW"); ex.UnparsedSegments.As <IEnumerable <string> >().Count().Should().Be(1); }
public void UriParserExceptionDataTest() { Action parsePath = () => this.testSubject.ParsePath(new[] { "Dogs(1)", "UNKNOW", "$ref" }); ODataUnrecognizedPathException ex = Assert.Throws <ODataUnrecognizedPathException>(parsePath); Assert.Equal(2, ex.ParsedSegments.Count()); Assert.Equal("UNKNOW", ex.CurrentSegment); Assert.Equal("$ref", Assert.Single(ex.UnparsedSegments)); }
public void ParsePathExceptionDataTestWithInvalidContainedNavigationProperty() { Action action = () => new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People(1)/MyDog1/Color", UriKind.Relative)).ParsePath(); ODataUnrecognizedPathException ex = action.ShouldThrow <ODataUnrecognizedPathException>().And; ex.ParsedSegments.As <IEnumerable <ODataPathSegment> >().Count().Should().Be(2); ex.CurrentSegment.Should().Be("MyDog1"); ex.UnparsedSegments.As <IEnumerable <string> >().Count().Should().Be(1); }
public void ParsePathExceptionDataTestInvalidNavigationProperty() { var parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People(1)/MyDog/Color1", UriKind.Relative)); Action action = () => parser.ParsePath(); ODataUnrecognizedPathException ex = action.ShouldThrow <ODataUnrecognizedPathException>().And; ex.ParsedSegments.As <IEnumerable <ODataPathSegment> >().Count().Should().Be(3); ex.CurrentSegment.Should().Be("Color1"); ex.UnparsedSegments.As <IEnumerable <string> >().Count().Should().Be(0); parser.ParameterAliasNodes.Count.Should().Be(0); }
private void BuildODataError(out ODataError error, out HttpStatusCode statusCode) { // Default to 500 (InternalServerError), it will be overried below if necessary. statusCode = HttpStatusCode.InternalServerError; ODataServiceException ose = this.HandledException as ODataServiceException; if (ose != null) { statusCode = ose.StatusCode; } ODataContentTypeException octe = this.HandledException as ODataContentTypeException; if (octe != null) { statusCode = HttpStatusCode.UnsupportedMediaType; } ODataUnrecognizedPathException oupe = this.HandledException as ODataUnrecognizedPathException; if (oupe != null) { statusCode = HttpStatusCode.NotFound; } ODataErrorException oee = this.HandledException as ODataErrorException; if (oee != null) { error = this.BuildODataError(statusCode, this.HandledException); if (!string.IsNullOrEmpty(oee.Error.ErrorCode)) { error.ErrorCode = oee.Error.ErrorCode; } if (!string.IsNullOrEmpty(oee.Error.Message)) { error.Message = oee.Error.Message; } if (oee.Error.InnerError != null) { error.InnerError = oee.Error.InnerError; } } else { // All the other exception will go here. error = this.BuildODataError(statusCode, this.HandledException); } }
public void ParsePathExceptionDataTestWithAlias() { var parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("GetCoolestPersonWithStyle(styleID=@p1)/UndeclaredProperty?@p1=32", UriKind.Relative)); Action action = () => parser.ParsePath(); ODataUnrecognizedPathException ex = action.ShouldThrow <ODataUnrecognizedPathException>().And; ex.ParsedSegments.As <IEnumerable <ODataPathSegment> >().Count().Should().Be(1); ex.CurrentSegment.Should().Be("UndeclaredProperty"); ex.UnparsedSegments.As <IEnumerable <string> >().Count().Should().Be(0); var aliasNode = parser.ParameterAliasNodes; aliasNode.Count.Should().Be(1); aliasNode["@p1"].ShouldBeConstantQueryNode(32); }