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_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);
            }
        }
Exemple #3
0
        public void Should_CallTimeoutCallback_When_TimeRunsOut()
        {
            ManualResetEvent callbackSignal = new ManualResetEvent(false);
            int timeoutSec = 1;

            WuStateAsyncJob.TimeoutCallback callback = (x, y) => { callbackSignal.Set(); };

            var job = (new WuStateAsyncJobProxy(WuStateId.Downloading, "name", timeoutSec, callback, null));

            job.EnterState(new WuStateReady());
            if (!callbackSignal.WaitOne(timeoutSec * 2000))
            {
                Assert.Fail($"timeout callback was not called");
            }
            Assert.IsFalse(job.IsRunning);
            job.Dispose();
        }