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 RequestServiceTest
    {
        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); Console.WriteLine(_message); Assert.AreEqual("success", _message);
        }

        #endregion


        /// <summary>
        ///A test for Request_ListRequestsToMe
        ///</summary>
        [TestMethod()]
        public void Request_ListRequestsToMeTest()
        {
            Guid collectionRequestGuid = new Guid("ad9ae1d0-447b-4a9f-bebf-11a499a2ac2f");

            RequestContext requestContext = new RequestContext();
            requestContext.CollectionRequestGuid = collectionRequestGuid;
            requestContext.User_CollectionType = Db.User_CollectionType.Contributor;

            List<Db.RequestType> types = new List<Db.RequestType>() { Db.RequestType.FollowUser, Db.RequestType.FollowCollection };
            _eq.RequestService.ListRequestsToMe(types, true, (List<Request> requests, EQException ex) => // onComplete
                    {
                        if (ex == null)
                        {
                            if (requests.Count > 0)
                                _message = "success";
                            else
                                _message = "requests.Count == 0";
                        }
                        else
                            _message = ex.Message;
                    });

        }
    }
}
