﻿using System;
using System.IO;
using System.Xml.Linq;
using Hardcore.Config;
using NUnit.Framework;

#if NET45
namespace Hardcore.Test.Net45.Config
#elif NETCOREAPP1_0
	namespace Hardcore.Test.NetCore10.Config
#else
	#error Undefined framework
#endif
{
    [TestFixture]
    public class DeserializerBehavior
    {
        [Test]
        public void ShouldDeserializeNullable()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml><model/></xml>";

            var d = new ConfigXmlDeserializer<Model>();

            XElement e;

            using (var reader = new StringReader(xml))
                e = XElement.Load(reader);

            var model = d.Deserialize(e);

            Console.WriteLine($"Model val = '{model.Val?.ToString() ?? "[null]"}'");
            Assert.IsNull(model.Val);
        }

        [ConfigModel("model")]
        public class Model
        {
            public bool? Val { get; set; }
        }
    }
}
