Exemple #1
0
        public void Should_CallProgressCallback_When_NewProgessNotEqualsOldProgress()
        {
            int progressChangedCallbackCounter = 0;

            WuStateAsyncJob.ProgressChangedCallback progressCallback = (j, cu, ci, co, p) => { progressChangedCallbackCounter++; };
            WuStateAsyncJob.TimeoutCallback         timeoutCallback  = (j, t) => { Assert.Fail("Should not be called."); };

            UpdateFake update1 = new UpdateFake("update1");
            UpdateFake update2 = new UpdateFake("update2");

            Tuple <IUpdate, int, int, int>[] progessChanges =
            {
                new Tuple <IUpdate, int, int, int>(update1, 0, 1,   0),
                new Tuple <IUpdate, int, int, int>(update1, 0, 1, 100),
                new Tuple <IUpdate, int, int, int>(update1, 1, 1, 100),
                new Tuple <IUpdate, int, int, int>(update2, 1, 1, 100)
            };

            using (var asyncJob = new WuStateAsyncJobProxy(WuStateId.Downloading, "name", 10000, timeoutCallback, progressCallback))
            {
                foreach (var pc in progessChanges)
                {
                    asyncJob.SimulateOnProgressNow(pc.Item1, pc.Item2, pc.Item3, pc.Item4);
                }
            }
            Assert.AreEqual(progessChanges.Length, progressChangedCallbackCounter);
        }
Exemple #2
0
        public void Should_CallProgressCallback_When_OnProgressIsCalled()
        {
            ManualResetEvent callbackSignal = new ManualResetEvent(false);
            int             timeoutSec = 1;
            IUpdate         callbackUpdate = null, inputUpdate = new UpdateFake("id");
            int             callbackIndex = -1, callbackCount = -1, callbackPercent = -1, inputIndex = 0, inputCount = 1, inputPercent = 37;
            WuStateAsyncJob callbackJob = null;

            WuStateAsyncJob.ProgressChangedCallback callback = (sender, update, index, count, percent) =>
            {
                callbackJob     = sender;
                callbackUpdate  = update;
                callbackIndex   = index;
                callbackCount   = count;
                callbackPercent = percent;
                callbackSignal.Set();
            };

            var job = (new WuStateAsyncJobProxy(WuStateId.Downloading, "name", timeoutSec, (x, y) => { }, callback));

            job.EnterState(new WuStateReady());
            job.SimulateOnProgressNow(inputUpdate, inputIndex, inputCount, inputPercent);
            if (!callbackSignal.WaitOne(timeoutSec * 2000))
            {
                Assert.Fail($"progress callback was not called");
            }
            Assert.AreEqual(callbackIndex, inputIndex);
            Assert.AreEqual(callbackCount, inputCount);
            Assert.AreSame(callbackUpdate, inputUpdate);
            Assert.AreSame(callbackJob, job);

            job.Dispose();
        }
Exemple #3
0
        public void Should_ContainSpecifiedTimeOut_When_CreateWuStateAsyncJob()
        {
            int timeout = 34;

            WuStateAsyncJob.ProgressChangedCallback progressCallback = (a, b, c, d, e) => { };
            WuStateAsyncJob.TimeoutCallback         timeoutCallback  = (a, b) => { };
            using (var state = new WuStateAsyncJobProxy(WuStateId.Downloading, "name", timeout, timeoutCallback, progressCallback))
            {
                Assert.AreEqual(timeout, state.TimeoutSec);
                Assert.AreSame(progressCallback, state.ProgressChangedCallbackDelegate);
                Assert.AreSame(timeoutCallback, state.TimeoutCallbackDelegate);
            }
        }