public static AndConstraint <OperationImportSegment> ShouldHaveConstantParameter <TValue>(this OperationImportSegment segment, string name, TValue value) { OperationSegmentParameter parameter = segment.Parameters.SingleOrDefault(p => p.Name == name); parameter.Should().NotBeNull(); parameter.ShouldBeConstantParameterWithValueType(name, value); return(new AndConstraint <OperationImportSegment>(segment)); }
public static OperationImportSegment ShouldHaveConstantParameter <TValue>(this OperationImportSegment segment, string name, TValue value) { Assert.NotNull(segment); OperationSegmentParameter parameter = segment.Parameters.SingleOrDefault(p => p.Name == name); Assert.NotNull(parameter); parameter.ShouldBeConstantParameterWithValueType(name, value); return(segment); }
public void FunctionImportWithTemplateShouldWork() { IEdmOperationImport operationImport = HardCodedTestModel.GetFunctionImportForFindMyOwner(); IList <ODataPathSegment> path = this.templateParser.ParsePath(new[] { "FindMyOwner(dogsName={fido})" }); OperationSegmentParameter parameter = path[0].ShouldBeOperationImportSegment(operationImport).And.Parameters.Single(); parameter.ShouldBeConstantParameterWithValueType("dogsName", new UriTemplateExpression { LiteralText = "{fido}", ExpectedType = operationImport.Operation.Parameters.Single().Type }); }
public void ActionWithTemplateShouldWork() { IEdmFunction operation = HardCodedTestModel.GetHasDogOverloadForPeopleWithTwoParameters(); IList <ODataPathSegment> path = this.templateParser.ParsePath(new[] { "Boss", "Fully.Qualified.Namespace.HasDog(inOffice={fido})" }); OperationSegmentParameter parameter = path[1].ShouldBeOperationSegment(operation).And.Parameters.Single(); parameter.ShouldBeConstantParameterWithValueType("inOffice", new UriTemplateExpression { LiteralText = "{fido}", ExpectedType = operation.Parameters.Last().Type }); }
public void ParseParameterTemplateForFunctionImportWithTemplateParser() { var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("IsAddressGood(address={ADDR})", UriKind.Relative)) { EnableUriTemplateParsing = true }; IEdmFunctionImport functionImport = HardCodedTestModel.TestModel.EntityContainer.FindOperationImports("IsAddressGood").Single().As <IEdmFunctionImport>(); var path = uriParser.ParsePath(); OperationSegmentParameter parameter = path.LastSegment.ShouldBeOperationImportSegment(functionImport).And.Parameters.Single(); parameter.ShouldBeConstantParameterWithValueType("address", new UriTemplateExpression { LiteralText = "{ADDR}", ExpectedType = functionImport.Function.Parameters.Single().Type }); }
public void ParseParameterTemplateOfEnumTypeWithTemplateParser() { var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("GetPetCount(colorPattern={COLOR})", UriKind.Relative)) { EnableUriTemplateParsing = true }; IEdmOperationImport operationImport = HardCodedTestModel.TestModel.EntityContainer.FindOperationImports("GetPetCount").Single(); var path = uriParser.ParsePath(); OperationSegmentParameter parameter = path.LastSegment.ShouldBeOperationImportSegment(operationImport).And.Parameters.Single(); parameter.ShouldBeConstantParameterWithValueType("colorPattern", new UriTemplateExpression { LiteralText = "{COLOR}", ExpectedType = operationImport.Operation.Parameters.Single().Type }); }
public void ParseParameterTemplateWithTemplateParser() { var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://host"), new Uri("http://host/People(1)/Fully.Qualified.Namespace.HasHat(onCat={why555})")) { EnableUriTemplateParsing = true }; IEdmFunction function = HardCodedTestModel.TestModel.FindOperations("Fully.Qualified.Namespace.HasHat").Single(f => f.Parameters.Count() == 2).As <IEdmFunction>(); var path = uriParser.ParsePath(); OperationSegmentParameter parameter = path.LastSegment.ShouldBeOperationSegment(function).And.Parameters.Single(); parameter.ShouldBeConstantParameterWithValueType("onCat", new UriTemplateExpression { LiteralText = "{why555}", ExpectedType = function.Parameters.Last().Type }); }
public void ValidTemplateInputShouldWork() { var inputs = new[] { "{}", "{_12}", "{12}", "{j}", "{count}", "{temp1}", "{top_of_p}", "{skip12}", "{LastNum}", "{_1V!@$%^&*}", "{(}", "{)}", "{)(*&^%$@!}", "{___}", "{_v1V)_}", "{變量}", "{嵐山}", "{춘향전}", "{的1_vé@_@}", "{{}and{}}", }; // Validate template for parameters IEdmFunction function = HardCodedTestModel.TestModel.FindOperations("Fully.Qualified.Namespace.HasHat").Single(f => f.Parameters.Count() == 2).As <IEdmFunction>(); foreach (var input in inputs) { var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People(1)/Fully.Qualified.Namespace.HasHat(onCat=" + input + ")", UriKind.Relative)) { EnableUriTemplateParsing = true }; var path = uriParser.ParsePath(); OperationSegmentParameter parameter = path.LastSegment.ShouldBeOperationSegment(function).And.Parameters.Single(); parameter.ShouldBeConstantParameterWithValueType("onCat", new UriTemplateExpression { LiteralText = input, ExpectedType = function.Parameters.Last().Type }); } // Validate template for keys foreach (var input in inputs) { var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://host"), new Uri("http://host/People(" + input + ")")) { EnableUriTemplateParsing = true }; var path = uriParser.ParsePath(); var keySegment = path.LastSegment.As <KeySegment>(); KeyValuePair <string, object> keypair = keySegment.Keys.Single(); keypair.Key.Should().Be("ID"); keypair.Value.As <UriTemplateExpression>().ShouldBeEquivalentTo(new UriTemplateExpression() { LiteralText = input, ExpectedType = keySegment.EdmType.As <IEdmEntityType>().DeclaredKey.Single().Type }); } }