public void WriteOperationsOnRequestsShouldThrow()
 {
     using (MemoryStream stream = new MemoryStream())
     {
         var context = this.CreateJsonLightOutputContext(stream, writingResponse: false);
         var serializer = new ODataJsonLightEntryAndFeedSerializer(context);
         Action test = () => serializer.WriteOperations(new ODataOperation[] { new ODataAction { Metadata = new Uri("#foo", UriKind.Relative) } }, /*isAction*/true);
         test.ShouldThrow<ODataException>().WithMessage(ErrorStrings.WriterValidationUtils_OperationInRequest("#foo"));
     }
 }
        private void WriteOperationsAndValidatePayload(IEnumerable<ODataOperation> operations, string expectedPayload, bool isAction = true, bool setMetadataDocumentUri = true, bool writeMetadataAnnotation = false)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                var context = this.CreateJsonLightOutputContext(stream, /*writingResponse*/true, setMetadataDocumentUri);
                var serializer = new ODataJsonLightEntryAndFeedSerializer(context);
                serializer.JsonWriter.StartObjectScope();
                if (writeMetadataAnnotation)
                {
                    serializer.WriteContextUriProperty(ODataPayloadKind.ServiceDocument);
                }

                serializer.WriteOperations(operations, isAction);
                serializer.JsonWriter.EndObjectScope();
                context.Flush();
                stream.Position = 0;
                string actualPayload = (new StreamReader(stream)).ReadToEnd();
                Assert.Equal(expectedPayload, actualPayload);
            }

        }