public void UpdateChecker_UpdatesPreReleases()
        {
            var current = SemanticVersion.Parse("2.0.0-pre2", ParseMode.Lenient);
            var sourceWithNewPrerelease = new DummyUpdateSource
            {
                Versions = new List <ProgramVersion>
                {
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre2"),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre3"),
                        IsPrerelease  = true
                    },
                    // Versions may be specified in any order
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre1"),
                        IsPrerelease  = true
                    }
                }
            };

            using (var checker = new UpdateChecker(sourceWithNewPrerelease, current, true, TimeSpan.FromMilliseconds(1)))
            {
                AssertUpdateCheck(checker, (sender, args) =>
                {
                    Assert.AreEqual(args.Version.VersionNumber, SemanticVersion.Parse("2.0.0-pre3", ParseMode.Lenient));
                });
            }

            // Ensure we get back the final release, even if it's specified as a pre-release.
            var sourceWithFinalRelease = new DummyUpdateSource
            {
                Versions = new List <ProgramVersion>
                {
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre3"),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre2"),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre1"),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0-pre4"),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = SemanticVersion.Parse("2.0.0"),
                        IsPrerelease  = true
                    }
                }
            };

            using (var checker = new UpdateChecker(sourceWithFinalRelease, current, true, TimeSpan.FromMilliseconds(1)))
            {
                AssertUpdateCheck(checker, (sender, args) =>
                {
                    Assert.AreEqual(args.Version.VersionNumber, SemanticVersion.Parse("2.0.0", ParseMode.Lenient));
                });
            }
        }
        public void UpdateChecker_ProvidesCorrectReleaseType()
        {
            var sourceWithNewerPrerelease = new DummyUpdateSource
            {
                Versions = new List <ProgramVersion>
                {
                    new ProgramVersion
                    {
                        VersionNumber = new SemanticVersion(3, 0, 0),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = new SemanticVersion(2, 0, 0),
                    }
                }
            };
            var sourceWithOlderPrerelease = new DummyUpdateSource
            {
                Versions = new List <ProgramVersion>
                {
                    new ProgramVersion
                    {
                        VersionNumber = new SemanticVersion(3, 0, 0),
                    },
                    new ProgramVersion
                    {
                        VersionNumber = new SemanticVersion(2, 0, 0),
                        IsPrerelease  = true
                    },
                    new ProgramVersion
                    {
                        VersionNumber = new SemanticVersion(1, 0, 0)
                    }
                }
            };

            // An update checker that may not return prereleases should return the latest non-prerelease version.
            using (var checker = new UpdateChecker(sourceWithNewerPrerelease, new SemanticVersion(1, 0, 0), false, TimeSpan.FromMilliseconds(1)))
            {
                AssertUpdateCheck(checker, (sender, args) =>
                {
                    Assert.IsFalse(args.Version.IsPrerelease);
                    Assert.AreEqual(args.Version.VersionNumber, new SemanticVersion(2, 0, 0));
                });
            }

            // An update checker that may return prereleases should return a prerelease if it's the latest version.
            using (var checker = new UpdateChecker(sourceWithNewerPrerelease, new SemanticVersion(1, 0, 0), true, TimeSpan.FromMilliseconds(1)))
            {
                AssertUpdateCheck(checker, (sender, args) =>
                {
                    Assert.IsTrue(args.Version.IsPrerelease);
                    Assert.AreEqual(args.Version.VersionNumber, new SemanticVersion(3, 0, 0));
                });
            }


            // An update checker that may return prereleases should not return a prerelease if there's a newer general release.
            using (var checker = new UpdateChecker(sourceWithOlderPrerelease, new SemanticVersion(1, 0, 0), true, TimeSpan.FromMilliseconds(1)))
            {
                AssertUpdateCheck(checker, (sender, args) =>
                {
                    Assert.IsFalse(args.Version.IsPrerelease);
                    Assert.AreEqual(args.Version.VersionNumber, new SemanticVersion(3, 0, 0));
                });
            }
        }