using EQNetwork.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using EQNetwork;
using EQNetwork.Objects;
using EQNetwork.Utility;
using System.Collections.Generic;

namespace UnitTests
{
    
    
    /// <summary>
    ///This is a test class for MiscServiceTest and is intended
    ///to contain all MiscServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MiscServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes

        static EQProcess _eq = null;
        static string _message = null;

        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            _eq = new EQProcess("accesskey", "secret");

            _eq.SessionService.Create("BrianARice", "f00tball",
                (Session session, EQException ex) => // onComplete
                {
                    if (ex != null)
                        Assert.Fail(ex.Message);
                }
            );

            while (_eq.Session == null) System.Threading.Thread.Sleep(100);
        }
        
        [ClassCleanup()]
        public static void MyClassCleanup()
        {
        }
        
        [TestInitialize()]
        public void MyTestInitialize()
        {
            _message = null;
        }
        
        [TestCleanup()]
        public void MyTestCleanup()
        {
            while (_message == null)
                System.Threading.Thread.Sleep(100);
            Console.WriteLine(_message); Assert.AreEqual("success", _message);
        }
        
        #endregion


        /// <summary>
        ///A test for ContentMenu_List
        ///</summary>
        [TestMethod()]
        public void ContentMenu_ListTest()
        {
            _eq.MiscService.ContentMenu_List(null,
                (List<ContentMenu> contentMenus, DateTime? maxModified, EQException ex) => // onComplete
                {
                    if (ex == null)
                    {
                        Assert.IsFalse(contentMenus.Count == 0);
                        Assert.AreNotEqual(null, maxModified);
                        _message = "success";
                    }
                    else
                    {
                        _message = ex.Message;
                    }
                }
            );
        }

        /// <summary>
        ///A test for Hashtag_Search
        ///</summary>
        [TestMethod()]
        public void Hashtag_SearchTest()
        {
            PagingParameters pagingParameters = new PagingParameters(5, "recent");
            _eq.MiscService.Hashtag_Search(null, pagingParameters,
                (List<Hashtag> hashtags, bool hasMore, EQException ex) => // onComplete
                {
                    if (ex == null)
                    {
                        foreach (var hashtag in hashtags)
                            Console.WriteLine("=> " + hashtag);
                        Assert.IsFalse(hashtags.Count == 0);
                        Assert.AreNotEqual(false, hasMore);
                        _message = "success";
                    }
                    else
                    {
                        _message = ex.Message;
                    }
                }
            );

        }

        /// <summary>
        ///A test for Hashtag_Trending
        ///</summary>
        [TestMethod()]
        public void Hashtag_TrendingTest()
        {
            PagingParameters pagingParameters = new PagingParameters(5, "alpha"); // there is no order by defined for Hashtag_Trending
            _eq.MiscService.Hashtag_Trending(pagingParameters,
                (List<Hashtag> hashtags, bool hasMore, EQException ex) => // onComplete
                {
                    if (ex == null)
                    {
                        foreach (var hashtag in hashtags)
                            Console.WriteLine("=> " + hashtag);
                        Assert.IsFalse(hashtags.Count == 0);
                        Assert.AreNotEqual(false, hasMore);
                        _message = "success";
                    }
                    else
                    {
                        _message = ex.Message;
                    }
                }
            );

        }

        /// <summary>
        ///A test for Activity_Create
        ///</summary>
        [TestMethod()]
        public void Activity_CreateTest()
        {
            _eq.MiscService.Activity_Create("unittest", null,
                (EQException ex) => // onComplete
                {
                    if (ex == null)
                    {
                        _message = "success";
                    }
                    else
                    {
                        _message = ex.Message;
                    }
                }
            );
        }
    }
}
