예제 #1
0
        private static bool IsFormatSupported(SampleDirection sampleDirection, MediaTypeFormatter formatter, Type type)
        {
            switch (sampleDirection)
            {
            case SampleDirection.Request:
                return(formatter.CanReadType(type));

            case SampleDirection.Response:
                return(formatter.CanWriteType(type));
            }
            return(false);
        }
        public void CanReadType_Calls_Inner()
        {
            // Arrange
            HttpRequestMessage request      = new HttpRequestMessage();
            Type randomType                 = typeof(string);
            Mock <TFormatter> mockFormatter = new Mock <TFormatter>()
            {
                CallBase = true
            };

            mockFormatter.Setup(f => f.CanReadType(randomType)).Returns(true).Verifiable();
            MediaTypeFormatter tracer = CreateTracer(mockFormatter.Object, request, new TestTraceWriter());

            // Act
            bool valueReturned = tracer.CanReadType(randomType);

            // Assert
            Assert.True(valueReturned);
            mockFormatter.Verify();
        }
예제 #3
0
        private static async Task <object> ReadAsync(
            MemoryStream ms,
            Type tSource,
            MediaTypeFormatter formatter
            )
        {
            bool f = formatter.CanReadType(tSource);

            Assert.True(f);

            object o = await formatter.ReadFromStreamAsync(
                tSource,
                ms,
                content : null,
                formatterLogger : null
                );

            Assert.True(tSource.IsAssignableFrom(o.GetType()));

            return(o);
        }
예제 #4
0
 public override bool CanReadType(Type type)
 {
     return(_internalFormatter.CanReadType(type));
 }