﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Arch.CFramework.Utility.Cats;

namespace Arch.CFX.Test
{
    [TestClass]
    public class CatsAgentTest
    {
        [TestCategory("CatsAgent")]
        [TestMethod]
        public void SendMessage_Test()
        {

            RequestMessage message = new RequestMessage()
            {

                Device = "test",
                Level = MessageLevel.High,
                Message = "test",
                Source = "unitest",
                Title = "test"
            };


            ResponseMessage resmessage = CatsAgent.SendMessage(message);

            var t1 = resmessage.Message;
            var t2 = resmessage.Result;

            Assert.IsTrue(t1.Length > 0);
            Assert.AreEqual(t2, MessageSendingResult.Succeed);


            System.Threading.ManualResetEvent hand = new System.Threading.ManualResetEvent(false);

            CatsAgent.SendMessageAsync(message, new
                 Action<ResponseMessage>((ar) => { hand.Set(); }));

            hand.WaitOne();
        }
    }
}
