public void ContentIdMustBeDollarNumber() { IEdmEntityType type = ModelBuildingHelpers.BuildValidEntityType(); Action createWitnInvalidContentId1 = () => new BatchReferenceSegment("stuff", type, HardCodedTestModel.GetPeopleSet()); Action createWitnInvalidContentId2 = () => new BatchReferenceSegment("1$2", type, HardCodedTestModel.GetPeopleSet()); Action createWitnInvalidContentId3 = () => new BatchReferenceSegment("$", type, HardCodedTestModel.GetPeopleSet()); Action createWitnInvalidContentId4 = () => new BatchReferenceSegment("$0a1", type, HardCodedTestModel.GetPeopleSet()); createWitnInvalidContentId1.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.BatchReferenceSegment_InvalidContentID("stuff")); createWitnInvalidContentId2.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.BatchReferenceSegment_InvalidContentID("1$2")); createWitnInvalidContentId3.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.BatchReferenceSegment_InvalidContentID("$")); createWitnInvalidContentId4.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.BatchReferenceSegment_InvalidContentID("$0a1")); }
public BatchReferenceSegment(string contentId, IEdmType edmType, IEdmEntitySetBase entitySet) { ExceptionUtils.CheckArgumentNotNull(edmType, "resultingType"); ExceptionUtils.CheckArgumentNotNull(contentId, "contentId"); if (!ODataPathParser.ContentIdRegex.IsMatch(contentId)) { throw new ODataException(ODataErrorStrings.BatchReferenceSegment_InvalidContentID(contentId)); } this.edmType = edmType; this.entitySet = entitySet; this.contentId = contentId; this.Identifier = this.ContentId; this.TargetEdmType = edmType; this.TargetEdmNavigationSource = this.EntitySet; this.SingleResult = true; this.TargetKind = RequestTargetKind.Resource; if (entitySet != null) { UriParserErrorHelper.ThrowIfTypesUnrelated(edmType, entitySet.EntityType(), "BatchReferenceSegments"); } }