﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Model;
using Server.Data.Runtime;
using Server.JobHandler;
using Server.Util;
using System.Collections.Generic;

namespace UnitTests
{
    [TestClass]
    public class ConfigTest : AbstractTest
    {

        [TestMethod]
        public void FetchConfig() // TODO test other config items as soon as implemented
        {
            List<string> lightNames = new List<string>() { "UnitTestLight1", "UnitTestLight2" };
            List<string> areaNames = new List<string>() { "UnitTestArea1", "UnitTestArea2", "UnitTestArea3", "UnitTestArea4" };
            AddArea(areaNames[0]);
            AddArea(areaNames[1]);
            AddLight(lightNames[0], 1, areaNames[2]);
            AddLight(lightNames[1], 2, areaNames[3]);
            JarvisResult result = ConfigJobHandler.HandleFetchConfig();
            Assert.AreEqual(JarvisStatusCode.Success, result.JarvisStatus);
            ConfigContainer conf = (ConfigContainer)ServerUtils.Deserialize(result.Content, typeof(ConfigContainer));
            Assert.AreEqual(2, conf.Lights.Count);
            Assert.AreEqual(4, conf.Areas.Count);
            Assert.AreEqual(256, conf.SwitchableCodes.Count);
            Assert.IsNotNull(conf.SerialInUse);
            foreach (Light l in conf.Lights)
            {
                Assert.IsTrue(lightNames.Contains(l.Label));
                lightNames.Remove(l.Label);
            }
            foreach (Area a in conf.Areas)
            {
                Assert.IsTrue(areaNames.Contains(a.Label));
                areaNames.Remove(a.Label);
            }
        }
    }
}
