using System;
using Xunit;

namespace VCommon.VAutoMapper.Tests
{
    public class NormalMappingTest
    {
        [AutoMapFrom(typeof(Entity))]
        [AutoMapTo(typeof(Entity))]
        public class Dto
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public bool IsEnable { get; set; }
        }

        public class Entity
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public bool IsEnable { 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,
            };

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

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

        [Fact]
        public void UpdateEntityByDto()
        {
            var entity = new Entity
            {
                Id = Guid.Empty,
                Name = "EntityName",
                IsEnable = false,
            };

            var dto = new Dto
            {
                Id = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1),
                Name = "DtoName",
                IsEnable = true,
            };

            dto.MapTo(entity);

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

        [Fact]
        public void EntityToDto()
        {
            var entity = new Entity
            {
                Id = Guid.Empty,
                Name = "EntityName",
                IsEnable = false,
            };

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

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