using qdr.fnd.core.pqueue.Enums;

namespace qdr.fnd.core.pqueue.test
{
    public class PsQueueItemTest
    {
        private string _id = "id";
        private string _owner = "owner";
        private string _ownerRef = "ownerRef";
        private string _providerClass = "providerClass";
        private DateTime _created = DateTime.Now;
        private PsStatusEnum _status = PsStatusEnum.New;
        private bool _statusTrancient = false;
        private string _statusMessage = "message";

        [SetUp]
        public void Setup()
        {
        }

        [Test(TestOf=typeof(PsQueueItem))]
        public void ConstructorOk()
        {
            var item = new PsQueueItem(_id, _owner,_ownerRef,_providerClass,_created, null);
            Assert.That(item.Id, Is.EqualTo(_id));
            Assert.That(item.Owner, Is.EqualTo(_owner));
            Assert.That(item.OwnerRef, Is.EqualTo(_ownerRef));
            Assert.That(item.ProcessProviderClass, Is.EqualTo(_providerClass));
            Assert.That(item.Created, Is.EqualTo(_created));
            Assert.That(item.Status, Is.EqualTo(_status));
            Assert.That(item.Arguments, Is.Not.Null);
            Assert.That(item.StatusJournal, Is.Not.Null);
            Assert.That(item.Log, Is.Not.Null);
            Assert.That(item.IsStatusTransient, Is.False);

            item = new PsQueueItem(_id);
            Assert.That(item.Id, Is.EqualTo(_id));
            Assert.That(item.Arguments, Is.Not.Null);
            Assert.That(item.StatusJournal, Is.Not.Null);
            Assert.That(item.Log, Is.Not.Null);
            Assert.That(item.IsStatusTransient, Is.False);
            Assert.That(item.Status, Is.EqualTo(_status));
        }

        [Test(TestOf=typeof(PsQueueItem))]
        public void SetStatusOk()
        {
            var item = new PsQueueItem(_id, _owner,_ownerRef,_providerClass,_created,null);
            Assert.That(item.Status, Is.EqualTo(_status));
            Assert.That(item.StatusJournal.Count, Is.EqualTo(0));

            item.SetStatus(PsStatusEnum.Pending, true, "message");
            Assert.That(item.Status, Is.EqualTo(PsStatusEnum.Pending));
            Assert.That(item.StatusJournal.Count, Is.EqualTo(1));
            Assert.That(item.StatusJournal.First().PreviousStatus, Is.EqualTo(_status));
            Assert.That(item.StatusJournal.First().PreviousIsStatusTransient, Is.EqualTo(_statusTrancient));
        }

        [Test(TestOf=typeof(PsQueueItem))]
        public void SetStatusFail()
        {
            var item = new PsQueueItem(_id, _owner,_ownerRef,_providerClass,_created, null);
            Assert.Throws<ArgumentNullException>(() => item.SetStatus(null,true,string.Empty));
        }
    }
}
