using System;
using System.Collections.Generic;
using Xunit;

namespace VCommon.VAutoMapper.Tests
{
    public class JsonMappingTest
    {
        public class JsonObj
        {
            public string Name { get; set; }
            public string XXXX { get; set; }
        }


        //TODO JsonMappingTest
        [AutoMapFrom(typeof(Entity))]
        [AutoMapTo(typeof(Entity))]
        public class Dto
        {
            public Guid Id { get; set; }
            public Guid? NullableValue { get; set; }
            public string Name { get; set; }
            public bool IsEnable { get; set; }

            [AutoMapJsonConvert]
            public IReadOnlyDictionary<int, string> Tags { get; set; }

            //好耶！ AutoMapper 更新到 10.x 之后支持 IReadOnlyDictionary 了！
        }

        public class Entity
        {
            public Guid Id { get; set; }
            public Guid? NullableValue { get; set; }
            public string Name { get; set; }
            public bool IsEnable { get; set; }
            public string Tags { get; set; }
        }

        [Fact]
        public void DtoToEntity()
        {
            var dto = new Dto
            {
                Id = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1),
                Name = "DtoName",
                IsEnable = true,
                Tags = new Dictionary<int, string> { { 123, "abc" } }
            };

            var entity = dto.MapTo<Entity>();
            var dto2 = entity.MapTo<Dto>();

            Assert.Equal(dto.Id, entity.Id);
            Assert.Equal(dto.Name, entity.Name);
            Assert.Equal(dto.IsEnable, entity.IsEnable);
        }
    }
}
