using System;
using Xunit;

namespace VCommon.VAutoMapper.Tests
{
    public class NavigatePropertyMappingTest
    {
        [AutoMapFrom(typeof(Entity))]
        [AutoMapTo(typeof(Entity))]
        public class Dto
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public string NavigateName { 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; }

            public NavigateEntity Navigate { get; set; }
        }

        public class NavigateEntity
        {
            public string Name { get; set; }
        }


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

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

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


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

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

            dto.MapTo(entity);

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


        [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,
                NavigateName = "DtoNavigate"
            };

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

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

       
        

    }
}
