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")); }
/// <summary> /// Build a BatchReferenceSegment /// </summary> /// <param name="contentId">The contentId of this segment is referring to</param> /// <param name="edmType">The <see cref="IEdmType"/> of the resource that this placeholder <see cref="BatchReferenceSegment"/> represents.</param> /// <param name="entitySet">The resulting entity set</param> /// <exception cref="System.ArgumentNullException">Throws if the input edmType of contentID is null.</exception> /// <exception cref="ODataException">Throws if the contentID is not in the right format.</exception> 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) { ExceptionUtil.ThrowIfTypesUnrelated(edmType, entitySet.EntityType(), "BatchReferenceSegments"); } }