using System;
using System.IO;
using System.Runtime.Serialization;
using Omnius.Base;
using Omnius.Configuration;
using Xunit;
using Xunit.Abstractions;

namespace Omnius.Tests
{
    [Trait("Category", "Omnius.Configuration")]
    public class Omnius_Configuration_Tests : TestsBase
    {
        private BufferManager _bufferManager = BufferManager.Instance;
        private Random _random = new Random();

        public Omnius_Configuration_Tests(ITestOutputHelper output) : base(output)
        {

        }

        [Fact]
        public void SettingsBaseTest()
        {
            string path = "Test_SettingsBase";

            Directory.CreateDirectory(path);

            var testSettings = new Settings(path);
            testSettings.Save("Text", "test");
            testSettings.Save("Config", new Config() { Text = "Test1" });

            Assert.Equal(testSettings.Load<string>("Text"), "test");
            Assert.Equal(testSettings.Load<Config>("Config").Text, "Test1");

            Directory.Delete(path, true);
        }

        [DataContract(Name = nameof(Config))]
        private class Config
        {
            [DataMember(Name = nameof(Text))]
            public string Text { get; set; }
        }
    }
}
