Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public override bool CanReadType(Type type)
 {
     return(_internalFormatter.CanReadType(type));
 }