Beispiel #1
0
        public void Convert_DepthLimitZero_ReturnsStructureToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);
            var value     = new Nested
            {
                Value = 1,
                Next  = new Nested
                {
                    Value = 10,
                    Next  = new Nested
                    {
                        Value = 100
                    }
                }
            };

            var structure = converter.Convert(value, 0) as StructureToken;

            Assert.NotNull(structure);
            Assert.Equal(2, structure.Properties.Count);
            Assert.Equal(nameof(Nested.Next), structure.Properties[0].Name);
            Assert.Equal(nameof(Nested.Value), structure.Properties[1].Name);

            var scalar = structure.Properties[0].Value as ScalarToken;

            Assert.NotNull(scalar);
            Assert.Null(scalar.Value);
        }
Beispiel #2
0
        public void Convert_Array_ReturnsSequenceToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);

            var token = converter.Convert(new[] { 1, 2, 3 });

            Assert.NotNull(token);
            Assert.IsType <SequenceToken>(token);
        }
Beispiel #3
0
        public void Convert_SystemType_ReturnsScalarToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);

            var token = converter.Convert(typeof(string));

            Assert.NotNull(token);
            Assert.IsType <ScalarToken>(token);
        }
Beispiel #4
0
        public void Convert_Guid_ReturnsScalarToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);

            var token = converter.Convert(Guid.NewGuid());

            Assert.NotNull(token);
            Assert.IsType <ScalarToken>(token);
        }
Beispiel #5
0
        public void Convert_DateTimeOffset_ReturnsScalarToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);

            var token = converter.Convert(DateTimeOffset.Now);

            Assert.NotNull(token);
            Assert.IsType <ScalarToken>(token);
        }
Beispiel #6
0
        public void Convert_ByteArray_ReturnsScalarToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);
            var value     = Enumerable.Range(0, 10).Select(b => (byte)b).ToArray();

            var token = converter.Convert(value);

            Assert.NotNull(token);
            Assert.IsType <ScalarToken>(token);
        }
Beispiel #7
0
        public void Convert_Delegate_ReturnsScalarToken()
        {
            var    logger    = Mock.Of <ILogger>();
            var    config    = new DefaultConversionConfig(logger);
            var    converter = new PropertyConverter(config, logger);
            Action value     = Convert_Delegate_ReturnsScalarToken;

            var token = converter.Convert(value);

            Assert.NotNull(token);
            Assert.IsType <ScalarToken>(token);
        }
Beispiel #8
0
        public void Convert_DictionaryKeyIsScalar_ReturnsDictionaryToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);
            var value     = new Dictionary <int, string> {
                { 1, "hello" }
            };

            var token = converter.Convert(value);

            Assert.NotNull(token);
            Assert.IsType <DictionaryToken>(token);
        }
Beispiel #9
0
        public void Convert_DictionaryKeyIsComplex_ReturnsSequenceToken()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);
            var value     = new Dictionary <A, string> {
                { new A(), "hello" }
            };

            var token = converter.Convert(value);

            Assert.NotNull(token);
            Assert.IsType <SequenceToken>(token);
        }
Beispiel #10
0
        public void Convert_CyclicStructure_DoesNotStackOverflow()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);
            var value     = new A
            {
                B = new B()
            };

            value.B.A = value;

            var token = converter.Convert(value);

            Assert.NotNull(token);
            Assert.IsType <StructureToken>(token);
        }
Beispiel #11
0
        public void Convert_CyclicCollections_DoNotStackOverflow()
        {
            var logger    = Mock.Of <ILogger>();
            var config    = new DefaultConversionConfig(logger);
            var converter = new PropertyConverter(config, logger);
            var value     = new C
            {
                D = new D
                {
                    C = new List <C?>()
                }
            };

            value.D.C.Add(value);

            var token = converter.Convert(value);

            Assert.NotNull(token);
            Assert.IsType <StructureToken>(token);
        }