示例#1
0
        public void parse_from_json_simple_concrete_object()
        {
            string json = "{\"id\":123,\"name\":\"SimpleModel\",\"code\":123456789012345678}";

            Mocks.SimpleModel simpleModel = _parserHelper
                                            .FromJson <Mocks.SimpleModel>(json);

            simpleModel.Id.Should().Be(123);
            simpleModel.Name.Should().Be("SimpleModel");
            simpleModel.Code.Should().Be(123456789012345678);
        }
示例#2
0
        public void parse_tojson_from_simple_concrete_object()
        {
            Mocks.SimpleModel simpleModel = new Mocks.SimpleModel()
            {
                Code = 123456789012345678,
                Id   = 123,
                Name = nameof(Mocks.SimpleModel)
            };

            _parserHelper
            .ToJson(simpleModel)
            .Should()
            .Be("{\"id\":123,\"name\":\"SimpleModel\",\"code\":123456789012345678}");
        }
示例#3
0
        public void parse_from_concrete_to_concrete_objects()
        {
            Mocks.SimpleModel simpleModel = new Mocks.SimpleModel()
            {
                Id   = 123,
                Code = 56789,
                Name = nameof(Mocks.SimpleModel)
            };

            Mocks.ComplexModel complexModel = _parserHelper.To <Mocks.ComplexModel, Mocks.SimpleModel>(simpleModel);

            complexModel.Id.Should().Be(simpleModel.Id);
            complexModel.Code.Should().Be(simpleModel.Code);
            complexModel.Name.Should().Be(simpleModel.Name);
        }
示例#4
0
        public void parse_from_dynamic_to_concrete_simple_object()
        {
            dynamic dynamicModel = new
            {
                Id   = 123,
                Code = 56789,
                Name = nameof(Mocks.SimpleModel)
            };

            Mocks.SimpleModel simpleModel = _parserHelper.To <Mocks.SimpleModel, dynamic>(dynamicModel);

            simpleModel.Id.Should().Be(dynamicModel.Id);
            simpleModel.Code.Should().Be(dynamicModel.Code);
            simpleModel.Name.Should().Be(dynamicModel.Name);
        }
示例#5
0
        public void parse_from_concrete_to_dynamic_simple_object()
        {
            Mocks.SimpleModel simpleModel = new Mocks.SimpleModel()
            {
                Id   = 123,
                Code = 56789,
                Name = nameof(Mocks.SimpleModel)
            };

            dynamic dynamicModel = _parserHelper.To <dynamic, Mocks.SimpleModel>(simpleModel);

            int    id   = dynamicModel.id;
            long   code = dynamicModel.code;
            string name = dynamicModel.name;

            id.Should().Be(simpleModel.Id);
            code.Should().Be(simpleModel.Code);
            name.Should().Be(simpleModel.Name);
        }