Пример #1
0
        private void AssertUpdateCheck(UpdateChecker checker, EventHandler <UpdateAvailableEventArgs> handler)
        {
            var raised = false;

            checker.UpdateAvailable += handler;
            checker.UpdateAvailable += (sender, args) => raised = true;
            checker.Start();

            // Wait a while to see if the event is raised.
            for (var i = 0; i < 20; i++)
            {
                Thread.Sleep(50);
                if (raised)
                {
                    return;
                }
            }
            Assert.Fail("Update checker did not raise event.");
        }
Пример #2
0
        public void UpdateChecker_RaisesAfterSpecifiedTime()
        {
            const int checkBeforeMs = 800;
            const int raiseAfterMs  = 1000;
            const int checkAgainMs  = 400;
            const int checkAttempts = 10;

            var source = new DummyUpdateSource
            {
                Versions = new List <ProgramVersion>
                {
                    new ProgramVersion
                    {
                        VersionNumber = new SemanticVersion(1, 0, 1)
                    }
                }
            };

            var checker = new UpdateChecker(source, new SemanticVersion(1, 0, 0), false, TimeSpan.FromMilliseconds(raiseAfterMs));

            var raised = false;

            checker.UpdateAvailable += (sender, args) => { raised = true; };
            checker.Start();

            // Validate that the event is not raised before the time specified in raiseAfterMs has expired.
            Thread.Sleep(checkBeforeMs);
            Assert.IsFalse(raised, "Notification was raised before update interval expired");

            // Validate that the event has been raised now.
            Thread.Sleep(checkAgainMs);
            for (int i = 0; i < checkAttempts && !raised; i++)
            {
                Thread.Sleep(checkAgainMs);
            }

            Assert.IsTrue(raised, "Notification was not raised");
        }
Пример #3
0
        /// <summary>
        /// Checks whether supplying a given update version against a given base version raises an update-available event.
        /// </summary>
        private bool RaisesEvent(SemanticVersion currentVersion, SemanticVersion updateVersion)
        {
            var source = new DummyUpdateSource
            {
                Versions = new List <ProgramVersion>
                {
                    new ProgramVersion
                    {
                        VersionNumber = updateVersion
                    }
                }
            };

            var checker = new UpdateChecker(source, currentVersion, false, TimeSpan.FromMilliseconds(1));

            var raised = false;

            checker.UpdateAvailable += (sender, args) =>
            {
                raised = true;
                checker.Dispose();
            };
            checker.Start();

            // Wait a while to see if the event is raised.
            for (var i = 0; i < 20; i++)
            {
                Thread.Sleep(50);
                if (raised)
                {
                    return(true);
                }
            }

            return(raised);
        }