using System.Threading;
using HWModules;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CPFUnitTests.Core
{
    class MotorizedValveUnitTests
    {
        [TestMethod]
        public void TestMotorizedValve()
        {
            var motherboard = MotherBoard.Instance;
            motherboard.EnableChannelPower(MotherBoard.ChannelNames.MotorizedValve);
            Thread.Sleep(5000);

            //Wait till its ready
            var attempts = 10;
            while (--attempts > 0 && motherboard.getMVReadyStatus())
            {
                EngrLogger.Comment("MV Not Ready");
                Thread.Sleep(2000);
            }
            EngrLogger.Comment("MV Ready Status = " + !motherboard.getMVReadyStatus());
            EngrLogger.Comment("Closing MV");
            motherboard.closeMV();
            Thread.Sleep(1000);
            EngrLogger.Comment("MV Opened Status = " + !motherboard.getMVOpenedStatus());
            Thread.Sleep(5000);

            for(var i=0; i<5; i++)
            {
                EngrLogger.Comment("Cycle Number = " + i);
                EngrLogger.Comment("MV Ready Status = " + !motherboard.getMVReadyStatus());
                EngrLogger.Comment("Opening MV");
                motherboard.openMV();
                Thread.Sleep(1000);
                EngrLogger.Comment("MV Opened Status = " + !motherboard.getMVOpenedStatus());
                Thread.Sleep(5000);

                EngrLogger.Comment("MV Ready Status = " + !motherboard.getMVReadyStatus());
                EngrLogger.Comment("Closing MV");
                motherboard.closeMV();
                Thread.Sleep(1000);
                EngrLogger.Comment("MV Opened Status = " + !motherboard.getMVOpenedStatus());
                Thread.Sleep(5000);
            }
            motherboard.DisableChannelPower(MotherBoard.ChannelNames.MotorizedValve);
        }
    }
}
