Exemple #1
0
        public void CanConvertWorksForDynamicTypeWrapper(Type type, bool expected)
        {
            // Arrange
            DynamicTypeWrapperConverter converter = new DynamicTypeWrapperConverter();

            // Act & Assert
            Assert.Equal(expected, converter.CanConvert(type));
        }
Exemple #2
0
        public void CreateConverterWorksForDynamicTypeWrapper(Type type, Type expected)
        {
            // Arrange
            JsonSerializerOptions       options   = new JsonSerializerOptions();
            DynamicTypeWrapperConverter converter = new DynamicTypeWrapperConverter();

            // Act
            JsonConverter typeConverter = converter.CreateConverter(type, options);

            // Assert
            if (expected == null)
            {
                Assert.Null(typeConverter);
            }
            else
            {
                Assert.Equal(expected, typeConverter.GetType());
            }
        }
Exemple #3
0
        internal static void TestDynamicTypeWrapperConverterRead <T>() where T : GroupByWrapper
        {
            // Arrange
            JsonSerializerOptions       options       = new JsonSerializerOptions();
            DynamicTypeWrapperConverter converter     = new DynamicTypeWrapperConverter();
            JsonConverter <T>           typeConverter = converter.CreateConverter(typeof(T), options) as JsonConverter <T>;

            try
            {
                // Act
                ReadOnlySpan <byte> jsonReadOnlySpan = Encoding.UTF8.GetBytes("any");
                Utf8JsonReader      reader           = new Utf8JsonReader(jsonReadOnlySpan);
                typeConverter.Read(ref reader, typeof(AggregationWrapper), options);
            }
            catch (NotImplementedException ex)
            {
                // Assert
                Assert.Equal($"'{typeof(T).Name}' is internal and should never be deserialized into.", ex.Message);
            }
        }
Exemple #4
0
        internal static void TestDynamicTypeWrapperConverterWrite <T>() where T : GroupByWrapper
        {
            // Arrange
            T wrapper = (T)Activator.CreateInstance(typeof(T));

            wrapper.GroupByContainer = new AggregationPropertyContainer()
            {
                Name  = "TestProp",
                Value = "TestValue"
            };

            JsonSerializerOptions       options       = new JsonSerializerOptions();
            DynamicTypeWrapperConverter converter     = new DynamicTypeWrapperConverter();
            JsonConverter <T>           typeConverter = converter.CreateConverter(typeof(T), options) as JsonConverter <T>;

            // Act
            string json = SerializeUtils.SerializeAsJson(jsonWriter => typeConverter.Write(jsonWriter, wrapper, options));

            // Assert
            Assert.Equal("{\"TestProp\":\"TestValue\"}", json);
        }