Example #1
0
        private void VerifyStream(AstoriaQueryStreamValue streamValue, string contentType, ODataRequest request, ODataResponse response)
        {
            this.AssertAreEqual(contentType, streamValue.ContentType, "Stream content type did not match", request, response);

            var expectedPayload = (byte[])((PrimitiveValue)request.Body.RootElement).ClrValue;

            this.AssertAreEqual(expectedPayload, streamValue.Value, "Stream content did not match", request, response);
        }
 private static void InitMemberStreamTypes(QueryEntityType type, QueryStructuralValue structural)
 {
     // initialize named streams
     foreach (var namedStream in type.Properties.Streams())
     {
         AstoriaQueryStreamValue qsv = new AstoriaQueryStreamValue((AstoriaQueryStreamType)namedStream.PropertyType, (byte[])null, null, type.EvaluationStrategy);
         structural.SetStreamValue(namedStream.Name, qsv);
     }
 }
Example #3
0
        private static void UpdateStreamValueFromHeaders(AstoriaQueryStreamValue expectedStreamValue, DataServiceStreamResponse response)
        {
            expectedStreamValue.ContentType = response.Headers[HttpHeaders.ContentType];

            string etag;

            response.Headers.TryGetValue(HttpHeaders.ETag, out etag);
            expectedStreamValue.ETag = etag;
        }
Example #4
0
        private static Uri GetExpectedReadStreamUri(AstoriaQueryStreamValue expectedStreamValue)
        {
            var expectedReadStreamUri = expectedStreamValue.SelfLink;

            if (expectedReadStreamUri == null)
            {
                expectedReadStreamUri = expectedStreamValue.EditLink;
            }

            return(expectedReadStreamUri);
        }
        /// <summary>
        /// Initializes the given query type by creating a queryStreamValue to hold the expected values
        /// </summary>
        /// <param name="queryType">A QueryEntityType</param>
        /// <returns>a QueryStructurvalValue</returns>
        protected override QueryStructuralValue InitializeEntityValue(QueryEntityType queryType)
        {
            var entity = base.InitializeEntityValue(queryType);
            foreach (var namedStream in queryType.Properties.Streams())
            {
                AstoriaQueryStreamValue qsv = new AstoriaQueryStreamValue((AstoriaQueryStreamType)namedStream.PropertyType, (byte[])null, null, queryType.EvaluationStrategy);
                entity.SetStreamValue(namedStream.Name, qsv);
            }

            return entity;
        }
Example #6
0
        /// <summary>
        /// Initializes the given query type by creating a queryStreamValue to hold the expected values
        /// </summary>
        /// <param name="queryType">A QueryEntityType</param>
        /// <returns>a QueryStructurvalValue</returns>
        protected override QueryStructuralValue InitializeEntityValue(QueryEntityType queryType)
        {
            var entity = base.InitializeEntityValue(queryType);

            foreach (var namedStream in queryType.Properties.Streams())
            {
                AstoriaQueryStreamValue qsv = new AstoriaQueryStreamValue((AstoriaQueryStreamType)namedStream.PropertyType, (byte[])null, null, queryType.EvaluationStrategy);
                entity.SetStreamValue(namedStream.Name, qsv);
            }

            return(entity);
        }
Example #7
0
        /// <summary>
        /// Gets the expected etag for the stream value, taking into account that empty etags become null
        /// </summary>
        /// <param name="streamValue">The stream value to get the expected etag for</param>
        /// <returns>The expected etag</returns>
        internal static string GetExpectedETag(this AstoriaQueryStreamValue streamValue)
        {
            ExceptionUtilities.CheckArgumentNotNull(streamValue, "streamValue");

            // empty stream etags are not written out
            var streamETag = streamValue.ETag;

            if (string.IsNullOrEmpty(streamETag))
            {
                streamETag = null;
            }

            return(streamETag);
        }
Example #8
0
        /// <summary>
        /// Compares properties of a structural object with expected value. Overridden here to handle named streams.
        /// </summary>
        /// <param name="structuralValue">The structural object containing the property to compare</param>
        /// <param name="expectedName">The name of the property to compare</param>
        /// <param name="expectedPropertyType">The expected type of the property</param>
        /// <param name="actualValue">The actual value of the property</param>
        /// <param name="path">The path to the compared object (for debugging purposes)</param>
        /// <param name="shouldThrow">Should exception be thrown if error is encountered</param>
        /// <returns>The comparison result</returns>
        protected override ComparisonResult CompareProperty(QueryStructuralValue structuralValue, string expectedName, QueryType expectedPropertyType, object actualValue, string path, bool shouldThrow)
        {
            if (this.CodeGenerator.GetType() == typeof(RemoteClientCodeLayerGenerator))
            {
                if (structuralValue.GetValue(expectedName).IsNull&& expectedPropertyType is QueryComplexType)
                {
                    return(ComparisonResult.Success);
                }
            }

            if (expectedPropertyType is AstoriaQueryStreamType)
            {
#if WINDOWS_PHONE
                return(ComparisonResult.Success);
#else
                DataServiceStreamLink   actualStreamLink    = (DataServiceStreamLink)actualValue;
                AstoriaQueryStreamValue expectedStreamValue = (AstoriaQueryStreamValue)structuralValue.GetStreamValue(expectedName);

                if (actualStreamLink == null)
                {
                    if (!expectedStreamValue.IsNull)
                    {
                        this.ThrowOrLogError(shouldThrow, "Expected DataServiceStreamLink property to be null. Actual: {0}", actualStreamLink);
                        return(ComparisonResult.Failure);
                    }
                    else
                    {
                        return(ComparisonResult.Success);
                    }
                }

                try
                {
                    this.VerifyStreamLink(expectedStreamValue, actualStreamLink);
                    return(ComparisonResult.Success);
                }
                catch (TestFailedException e)
                {
                    this.ThrowOrLogError(shouldThrow, e.ToString());
                    return(ComparisonResult.Failure);
                }
#endif
            }
            else
            {
                return(base.CompareProperty(structuralValue, expectedName, expectedPropertyType, actualValue, path, shouldThrow));
            }
        }
        /// <summary>
        /// Creates a copy of the given value recursively
        /// </summary>
        /// <param name="value">The value to copy</param>
        /// <returns>The copied value</returns>
        public QueryValue Visit(AstoriaQueryStreamValue value)
        {
            ExceptionUtilities.CheckArgumentNotNull(value, "value");

            if (value.EvaluationError != null)
            {
                return(value.Type.CreateErrorValue(value.EvaluationError));
            }

            if (value.IsNull)
            {
                return(value.Type.NullValue);
            }

            return(value.Type.CreateValue(value.Value, value.ContentType, value.ETag, value.EditLink, value.SelfLink));
        }
Example #10
0
        /// <summary>
        /// Verifies the streams data.
        /// </summary>
        /// <param name="expectedStreamValue">The expected stream value.</param>
        /// <param name="response">The stream response.</param>
        /// <returns>The result of stream verification</returns>
        protected bool VerifyStreams(AstoriaQueryStreamValue expectedStreamValue, DataServiceStreamResponse response)
        {
            var expectedBytes = new byte[0];

            if (!expectedStreamValue.IsNull)
            {
                expectedBytes = expectedStreamValue.Value;
            }

            var expectedStream = new MemoryStream(expectedBytes);

            try
            {
                ExceptionUtilities.Assert(response.Stream.CanRead, "Cannot read from the stream");

                return(StreamHelpers.CompareStream(response.Stream, expectedStream));
            }
            finally
            {
                response.Stream.Dispose();
                expectedStream.Dispose();
            }
        }
Example #11
0
        private void VerifyStreamDescriptorValues(AstoriaQueryStreamValue expected, string name, string contentType, string etag, Uri editLink, Uri selfLink)
        {
            if (!this.SkipStreamDescriptorValuesVerification)
            {
                string message;
                if (name == null)
                {
                    message = "default stream";
                }
                else
                {
                    message = "named stream " + name;
                }

                if (name != null)
                {
                    this.Assert.AreEqual(expected.ContentType, contentType, "Content type did not match for {0}", message);
                }

                this.Assert.AreEqual(expected.GetExpectedETag(), etag, "ETag did not match for {0}", message);
                this.Assert.AreEqual(expected.EditLink, editLink, "Edit link did not match for {0}", message);
                this.Assert.AreEqual(expected.SelfLink, selfLink, "Self link did not match for {0}", message);
            }
        }
Example #12
0
 private void VerifyStreamLink(AstoriaQueryStreamValue expected, DataServiceStreamLink actual)
 {
     this.VerifyStreamDescriptorValues(expected, actual.Name, actual.ContentType, actual.ETag, actual.EditLink, actual.SelfLink);
 }
 private void CompareStreamETag(AstoriaQueryStreamValue queryStreamValue, string actualETag)
 {
     this.parent.Assert.AreEqual(queryStreamValue.GetExpectedETag(), actualETag, "ETag did not match");
 }
Example #14
0
        public static void SetStreamValue(this QueryStructuralValue instance, string namedStream, AstoriaQueryStreamValue value)
        {
            ExceptionUtilities.CheckArgumentNotNull(instance, "instance");
            ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(namedStream, "namedStream");

            instance.AssertPropertyType <AstoriaQueryStreamType>(namedStream);

            instance.SetValue(namedStream, value);
        }
Example #15
0
        public static void SetDefaultStreamValue(this QueryStructuralValue instance, AstoriaQueryStreamValue value)
        {
            ExceptionUtilities.CheckArgumentNotNull(instance, "instance");

            instance.SetStreamValue(AstoriaQueryStreamType.DefaultStreamPropertyName, value);
        }
        private void VerifyStream(AstoriaQueryStreamValue streamValue, string contentType, ODataRequest request, ODataResponse response)
        {
            this.AssertAreEqual(contentType, streamValue.ContentType, "Stream content type did not match", request, response);

            var expectedPayload = (byte[])((PrimitiveValue)request.Body.RootElement).ClrValue;
            this.AssertAreEqual(expectedPayload, streamValue.Value, "Stream content did not match", request, response);
        }