Пример #1
0
        public Stream GetResponseWrappingStream(Stream sourceStream)
        {
            Assert.IsNotNull(sourceStream, "getResponseWrappingStream test hook was called with null response stream");
            WrappingStream wrappedStream = new WrappingStream(sourceStream);

            responseWrappingStreams.Add(wrappedStream);
            return(wrappedStream);
        }
        public void NamedStreams_PayloadDrivenMaterialization()
        {
            // Make sure DSSL properties can materialized and populated with the right url in non-projection cases
            {
                // Testing without projections (payload driven) and making sure one is able to project out the stream url
                DataServiceContext context = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
                context.EnableAtom = true;
                context.Format.UseAtom();
                context.IgnoreMissingProperties = true;
                var q = context.CreateQuery<EntityWithStreamLink>("MySet1");
                object entity = null;

                foreach (EntityWithStreamLink o in q)
                {
                    Assert.IsNotNull(o.Stream1, "Stream1 must have some value");
                    Assert.AreEqual(o.Stream1.EditLink, context.GetReadStreamUri(o, "Stream1"), "the value in the entity descriptor must match with the property value");
                    Assert.IsNull(o.SomeRandomProperty, "SomeRandomProperty must be null, since the payload does not have the link with the property name");
                    entity = o;
                }

                // Try updating the entity and make sure that the link is not send back in the payload.
                context.UpdateObject(entity);

                WrappingStream wrappingStream = null;
                context.RegisterStreamCustomizer((inputStream) =>
                    {
                        wrappingStream = new WrappingStream(inputStream);
                        return wrappingStream;
                    },
                    null);

                try
                {
                    context.SaveChanges();
                    Assert.Fail("Save changes should throw an exception");
                }
                catch (Exception)
                {
                    // do nothing
                }

                string payload = wrappingStream.GetLoggingStreamAsString();
                Assert.IsTrue(payload.Contains("<d:ID m:type=\"Int32\">1</d:ID>"), "Id element must be present");
                Assert.IsFalse(payload.Contains("Stream1Url"), "link url should not be sent in the payload");
            }
        }