public async Task CheckAsync_NewerVersion_UpdateAvailable()
        {
            UpdateChecker updates = GetUpdateChecker(_repoNewerVersion);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsTrue(result.Available, $"{nameof(updates.CheckAsync)}() should say there's an update available when the latest version is newer than the current version.");
        }
        public async Task CheckAsync_NotFoundException_NoUpdateNoReleases()
        {
            UpdateChecker updates = GetUpdateChecker("notFound", GetHttpWebException(HttpStatusCode.NotFound));

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when there are no releases for the repo or it doesn't exist.");
            Assert.AreEqual(Messages.NoUpdateNoReleases, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateNoReleases)} message when there are no releases for the repo or it doesn't exist.");
        }
        public async Task CheckAsync_NoFiles_NoUpdateNoFiles()
        {
            UpdateChecker updates = GetUpdateChecker(_repoNoFiles);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the latest version has no files.");
            Assert.AreEqual(Messages.NoUpdateNoFiles, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateNoFiles)} message when the latest version has no files.");
        }
        public async Task CheckAsync_SameVersion_NoUpdateAlreadyLatest()
        {
            UpdateChecker updates = GetUpdateChecker(_repoSameVersion);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the latest version matches the current version.");
            Assert.AreEqual(Messages.NoUpdateAlreadyLatest, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateAlreadyLatest)} message when the latest version matches the current version.");
        }
        public async Task CheckAsync_UnexpectedException_NoUpdateError(WebExceptionStatus status)
        {
            WebException  ex      = GetWebException(status);
            UpdateChecker updates = GetUpdateChecker("otherException", ex);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the API does not return a response.");
            Assert.AreEqual(string.Format(Messages.NoUpdateError, ex.Message), result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateError)} message when the API does not return a response.");
        }
        public async Task CheckAsync_OtherProtocolException_NoUpdateError(HttpStatusCode status)
        {
            WebException  ex      = GetHttpWebException(status);
            UpdateChecker updates = GetUpdateChecker("otherProtocolException", ex);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the API returns an error response other than 404 not found.");
            Assert.AreEqual(string.Format(Messages.NoUpdateError, ex.Message), result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateError)} message when the API returns an error response other than 404 not found.");
        }
        public async Task CheckAsync_CannotConnect_NoUpdateCannotConnect(WebExceptionStatus status)
        {
            WebException  ex      = GetWebException(status);
            UpdateChecker updates = GetUpdateChecker("otherException", ex);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when unable to connect to the API server.");
            Assert.AreEqual(Messages.NoUpdateCannotConnect, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateCannotConnect)} message when unable to connect to the API server.");
        }
Example #8
0
        private void AboutDialog_Load(object sender, EventArgs e)
        {
            try
            {
                lblAppVersion.Text = UpdateChecker.AssemblyVersion.ToAppFormat();

                lnkDownloadUpdate.Visible = false;

                _updateChecker = new UpdateChecker();
                _updateChecker.UpdateAvailable   += new EventHandler <UpdateCheckEventArgs>(checker_UpdateAvailable);
                _updateChecker.NoUpdateAvailable += new EventHandler <UpdateCheckEventArgs>(checker_NoUpdateAvailable);
                _updateChecker.UpdateCheckFailed += new EventHandler <UpdateCheckEventArgs>(checker_UpdateCheckFailed);
                Task.Run(() => _updateChecker.CheckAsync());
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, String.Format(Res.Exception_GetAppVersion, ex.Message), Res.Error_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }