using System;
using Xunit;
using Newtonsoft.Json.Linq;
using FluentAssertions;
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace raven_integration
{

    public class JobOperations
    {

        /// <summary>
        ///
        /// </summary>
        [Fact]
        public async void TestJobShouldSubmit()
        {
            ApiResponse a = await Util.GetAsync("Widget/TestWidgetJob", await Util.GetTokenAsync("OpsAdminFull"));
            //Util.ValidateDataReturnResponseOk(a);
            Util.ValidateHTTPStatusCode(a, 202);
            //should return something like this:
            /*
            {
              "testJobId": 4
            }
             */

            String jobId = a.ObjectResponse["jobId"].Value<String>();

            //Get a list of operations
            a = await Util.GetAsync("JobOperations", await Util.GetTokenAsync("OpsAdminFull"));
            Util.ValidateDataReturnResponseOk(a);
            Util.ValidateHTTPStatusCode(a, 200);



            //there should be at least 1
            ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterOrEqualTo(1);

            //See if our job is in there
            bool bFound=false;
             foreach(JToken t in a.ObjectResponse["data"])
             {
                 if(t["gId"].Value<String>()==jobId)
                    bFound=true;
             }
             bFound.Should().BeTrue();

             

        }


        //==================================================

    }//eoc
}//eons
