public void AsyncFuncDoesNotRunWhenRunning()
        {
            //arrange
            var func = new Mock<ICommand>();

            func.Setup(f => f.Progress.Status).Returns(StatusEnum.Running);

            var container = new Mock<IAsyncCommandContainer>();
            ICommand a = new AsyncManager(func.Object, "", container.Object);

            //act
            a.Start();

            //assert
            func.Verify(f => f.Start(), Times.Never());
        }
        public void RemovalTimerStartsWhenJobIsFinished()
        {
            var func = new Mock<ICommand>();
            var container = new Mock<IAsyncCommandContainer>();

            func.Setup(f => f.Progress.Status).ReturnsInOrder(StatusEnum.NotStarted, StatusEnum.Running);
            container.Setup(c => c.Exists(It.IsAny<string>(), It.IsAny<Type>())).Returns(true);
            var asyncFunc = new AsyncManager(func.Object, "", container.Object);

            asyncFunc.Start();

            container.Verify(c => c.SetInactive("", func.Object.GetType()));
        }
        public void RemovalTimerStopsWhenJobStartsRunning()
        {
            var func = new Mock<ICommand>();
            var container = new Mock<IAsyncCommandContainer>();

            func.Setup(f => f.Progress.Status).Returns(StatusEnum.Running);
            func.Setup(f => f.Start()).Callback(() => container.Verify(c => c.SetActive("", func.Object.GetType())));
            container.Setup(c => c.Exists(It.IsAny<string>(), It.IsAny<Type>())).Returns(true);
            var asyncFunc = new AsyncManager(func.Object, "", container.Object);

            asyncFunc.Start();
        }
        public void JobNotRemovedWhenFinishesAndShouldBeRemovedOnCompleteIsFalse()
        {
            var func = new Mock<ICommand>();
            var container = new Mock<IAsyncCommandContainer>();
            IAsyncCommand a = new AsyncManager(func.Object, "", container.Object);

            //act
            func.Setup(f => f.Progress.Status).Returns(StatusEnum.NotStarted);

            a.Start();

            //assert
            container.Verify(c => c.Remove("", func.Object.GetType()), Times.Never());
        }
        public void JobSetToInactiveWhenAdded()
        {
            var func = new Mock<ICommand>();
            var container = new Mock<IAsyncCommandContainer>();

            AsyncManager manager = new AsyncManager(func.Object, "", container.Object);

            container.Verify(c => c.SetInactive("", func.Object.GetType()));

            Assert.IsFalse(container.Object.Exists("", func.Object.GetType()));
        }
        public void CallingCancelTellsInnerClassToCancel()
        {
            var func = new Mock<ICommand>();
            var container = new Mock<IAsyncCommandContainer>();
            IAsyncCommand a = new AsyncManager(func.Object, "", container.Object);

            a.Cancel();
            func.Verify(f => f.Cancel(), Times.Exactly(1)); //even though we call a.cancel, func.Cancel is eventually called.
        }
        public void AsyncManagerRemovesEventToInnerClass()
        {
            //arrange
            var mock = new MockRepository();
            var func = mock.DynamicMock<ICommand>();
            var container = mock.DynamicMock<IAsyncCommandContainer>();
            IAsyncCommand a = new AsyncManager(func, "", container);
            Action set = () => { };

            //act
            func.Replay();
            a.OnStart += set;
            a.OnStart -= set;

            //assert
            func.AssertWasCalled(x => x.OnStart += set);
            func.AssertWasCalled(x => x.OnStart -= set);
        }
        public void AsyncManagerAddsAsyncJobToContainer()
        {
            //arrange
            var func = new Mock<ICommand>();
            var container = new Mock<IAsyncCommandContainer>();

            IAsyncCommand a = new AsyncManager(func.Object, "", container.Object);

            container.Verify(c => c.Add(a, "", func.Object.GetType()));
        }
 public static IAsyncCommand AsAsync(this ICommand func, string id, IAsyncCommandContainer container)
 {
     IAsyncCommand asyncFuncManager = new AsyncManager(func, id, container);
     return asyncFuncManager;
 }
        public void RemovalTimerStartsWhenJobIsAdded()
        {
            var func = new Mock<IAsyncCommand>();
            ILog logger = GetLogger();

            func.Setup(f => f.Progress.Status).Returns(StatusEnum.NotStarted);

            AsyncCommandContainer container = new AsyncCommandContainer(new AsyncCommandItemTimeSpan(), logger);

            IAsyncCommand a = new AsyncManager(func.Object, "", container);

            AsyncContainerItem item = container.GetContainerItem("", func.Object.GetType());
            Assert.IsTrue(item.Timer.Enabled);
        }