Exemplo n.º 1
0
        public void CanReadTypeReturnsExpectedValues()
        {
            TestJsonMediaTypeFormatter formatter = new TestJsonMediaTypeFormatter();

            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                bool isSerializable = IsTypeSerializableWithJsonSerializer(type, obj);
                bool canSupport     = formatter.CanReadTypeProxy(type);

                // If we don't agree, we assert only if the DCJ serializer says it cannot support something we think it should
                if (isSerializable != canSupport && isSerializable)
                {
                    Assert.Fail(string.Format("CanReadType returned wrong value for '{0}'.", type));
                }

                // Ask a 2nd time to probe whether the cached result is treated the same
                canSupport = formatter.CanReadTypeProxy(type);
                if (isSerializable != canSupport && isSerializable)
                {
                    Assert.Fail(string.Format("2nd CanReadType returned wrong value for '{0}'.", type));
                }
            });
        }
        public void CanReadType_ReturnsExpectedValues(Type variationType, object testData)
        {
            TestJsonMediaTypeFormatter formatter = new TestJsonMediaTypeFormatter();

            bool isSerializable = IsTypeSerializableWithJsonSerializer(variationType, testData);
            bool canSupport     = formatter.CanReadTypeProxy(variationType);

            // If we don't agree, we assert only if the DCJ serializer says it cannot support something we think it should
            Assert.False(isSerializable != canSupport && isSerializable, String.Format("CanReadType returned wrong value for '{0}'.", variationType));

            // Ask a 2nd time to probe whether the cached result is treated the same
            canSupport = formatter.CanReadTypeProxy(variationType);
            Assert.False(isSerializable != canSupport && isSerializable, String.Format("2nd CanReadType returned wrong value for '{0}'.", variationType));
        }
        public void CanReadType_ReturnsTrueOnJtoken()
        {
            TestJsonMediaTypeFormatter formatter = new TestJsonMediaTypeFormatter();

            foreach (Type type in JTokenTypes)
            {
                Assert.True(formatter.CanReadTypeProxy(type), "formatter should have returned true.");
            }
        }