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

namespace UnitTests
{


    /// <summary>
    ///This is a test class for ContentFileServiceTest and is intended
    ///to contain all ContentFileServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ContentFileServiceTest
    {
        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 ContentFile_ListPosts
        ///</summary>
        [TestMethod()]
        public void ContentFile_ListPosts()
        {
            string filename = "9b46e714-f15a-4aaa-a6d0-63db9bfb2efb.mov";
            _eq.ContentFileService.ListPosts(filename, new PagingParameters(5, "Recent"),
                (List<Post> posts, bool hasMore, EQException ex) => // onComplete
                {
                    if (ex == null)
                    {
                        Assert.IsFalse(posts.Count == 0);
                        Assert.AreEqual(true, hasMore);
                        _message = "success";
                    }
                    else
                        _message = ex.Message;
                }
            );
        }
    }
}
