Esempio n. 1
0
        public void ReadFromStreamAsyncCallsOnReadFromStreamInTask()
        {
            Type               calledType    = null;
            Stream             calledStream  = null;
            HttpContentHeaders calledHeaders = null;

            SMediaTypeFormatter formatter = new SMediaTypeFormatter()
            {
                CallBase = true
            };

            formatter.OnReadFromStreamTypeStreamHttpContentHeaders = (type, stream, headers) =>
            {
                calledType    = type;
                calledStream  = stream;
                calledHeaders = headers;
                return(5);
            };

            SHttpContent       content        = new SHttpContent();
            HttpContentHeaders contentHeaders = content.Headers;

            Task <object> createdTask =
                StreamAssert.WriteAndReadResult <Task <object> >(
                    (stream) => { },
                    (stream) => formatter.ReadFromStreamAsync(typeof(int), stream, contentHeaders));

            object readObject = TaskAssert.SucceedsWithResult(createdTask);

            Assert.AreEqual(5, readObject, "ReadFromStreamAsync should have returned this value from stub.");
            Assert.AreEqual(typeof(int), calledType, "OnReadFromStreamAsync was not called or did not pass Type.");
            Assert.IsNotNull(calledStream, "OnReadFromStreamAsync was not called or did not pass Type.");
            Assert.AreSame(contentHeaders, calledHeaders, "OnReadFromStreamAsync was not called or did not pass ContentHeaders.");
        }
Esempio n. 2
0
        public void ReadFromStreamAsyncCallsOnReadFromStreamAsync()
        {
            Type               calledType    = null;
            Stream             calledStream  = null;
            HttpContentHeaders calledHeaders = null;

            SMediaTypeFormatter formatter = new SMediaTypeFormatter()
            {
                CallBase = true
            };

            formatter.OnReadFromStreamAsyncTypeStreamHttpContentHeaders = (type, stream, headers) =>
            {
                calledType    = type;
                calledStream  = stream;
                calledHeaders = headers;
                return(null);
            };
            SHttpContent       content        = new SHttpContent();
            HttpContentHeaders contentHeaders = content.Headers;

            StreamAssert.WriteAndRead(
                (stream) => { },
                (stream) => formatter.ReadFromStreamAsync(typeof(int), stream, contentHeaders));

            Assert.AreEqual(typeof(int), calledType, "OnReadFromStreamAsync was not called or did not pass Type.");
            Assert.IsNotNull(calledStream, "OnReadFromStreamAsync was not called or did not pass Type.");
            Assert.AreSame(contentHeaders, calledHeaders, "OnReadFromStreamAsync was not called or did not pass ContentHeaders.");
        }