public void ShouldReturnFalseForInvalidVersionStrings() { string[] stringsToTest = { "", " ", "a", "a.b", "1,000", "1.0.3-alpha", "1.0. " }; foreach (var s in stringsToTest) { Assert.IsFalse(PackageConstraintExtensions.IsValidVersionString(s)); } }
public void ShouldReturnTrueForValidVersionStrings() { string[] stringsToTest = { "0", "0.1", "1.0.0", "0.0.0.0", "1.2" }; foreach (var s in stringsToTest) { Assert.IsTrue(PackageConstraintExtensions.IsValidVersionString(s)); } }
public void ShouldReturnTrueForValidNugetPackageIds() { // http://nuget.codeplex.com/wikipage?title=Package%20Id%20Specification&IsNewlyCreatedPage=true string[] stringsToTest = { "hello", "i.am.a.valid.id", "nuget-core_is.cool", "123.456.789", "newsletters" }; foreach (var s in stringsToTest) { Assert.IsTrue(PackageConstraintExtensions.IsValidNugetPackageId(s)); } }
public void ShouldReturnFalseForInvalidNugetPackageIds() { // http://nuget.codeplex.com/wikipage?title=Package%20Id%20Specification&IsNewlyCreatedPage=true string[] stringsToTest = { "hello._there", "i.am.not.valid.", "_neitherami", "bad..id", "", " " }; foreach (var s in stringsToTest) { Assert.IsFalse(PackageConstraintExtensions.IsValidNugetPackageId(s)); } }
public void ShouldReturnTokensForValidPackageConstraint() { string[] stringsToTest = { "packageName:1", "packageName:1.02.4.0" }; foreach (var s in stringsToTest) { var tokens = PackageConstraintExtensions.GetPackageIdAndVersion(s); Assert.IsTrue(tokens.Length == 2); Assert.IsFalse(string.IsNullOrWhiteSpace(tokens[0])); Assert.IsFalse(string.IsNullOrWhiteSpace(tokens[1])); } }
public void ShouldThrowArgumentExceptionForInvalidPackageConstraint() { string[] stringsToTest = { "package name:1.0", "", " ", "packageName:1.0:2.0", "packageA:1.0;packageB:2.0" }; foreach (var s in stringsToTest) { Assert.Throws <ArgumentException>(delegate { PackageConstraintExtensions. GetPackageIdAndVersion(s); }); } }
public void ParsePackageConstraint(string value) { try { var packageIdAndVersion = PackageConstraintExtensions.GetPackageIdAndVersion(value); if (PackageVersionNumberOverrides.ContainsKey(packageIdAndVersion[0])) { throw new ArgumentException(string.Format("More than one constraint was specified for package {0}", packageIdAndVersion[0])); } PackageVersionNumberOverrides.Add(packageIdAndVersion[0], packageIdAndVersion[1]); } catch (ArgumentException ex) { throw new CommandException(ex.Message); } }