/src/AddIns/Misc/PackageManagement/Test/Src/RecentPackageInfoTests.cs

https://github.com/ajadex/SharpDevelop · C# · 103 lines · 69 code · 17 blank · 17 comment · 0 complexity · d4358c09b43ebe4fe99b69194af67c75 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.IO;
  20. using System.Text;
  21. using System.Xml;
  22. using System.Xml.Linq;
  23. using ICSharpCode.Core;
  24. using ICSharpCode.PackageManagement;
  25. using ICSharpCode.PackageManagement.Design;
  26. using NuGet;
  27. using NUnit.Framework;
  28. namespace PackageManagement.Tests
  29. {
  30. [TestFixture]
  31. public class RecentPackageInfoTests
  32. {
  33. [Test]
  34. public void ToString_IdAndVersionSpecified_ContainsIdAndVersion()
  35. {
  36. var recentPackageInfo = new RecentPackageInfo("id", new SemanticVersion("1.0"));
  37. string actual = recentPackageInfo.ToString();
  38. string expected = "[RecentPackageInfo Id=id, Version=1.0]";
  39. Assert.AreEqual(expected, actual);
  40. }
  41. [Test]
  42. public void IsMatch_PackageWithSameIdAndVersionPassed_ReturnsTrue()
  43. {
  44. string id = "id";
  45. var version = new SemanticVersion(1, 0, 0, 0);
  46. var recentPackageInfo = new RecentPackageInfo(id, version);
  47. var package = new FakePackage(id);
  48. package.Version = version;
  49. bool result = recentPackageInfo.IsMatch(package);
  50. Assert.IsTrue(result);
  51. }
  52. [Test]
  53. public void IsMatch_PackageWithSameIdButDifferentVersionPassed_ReturnsFalse()
  54. {
  55. string id = "id";
  56. var version = new SemanticVersion(1, 0, 0, 0);
  57. var recentPackageInfo = new RecentPackageInfo(id, version);
  58. var package = new FakePackage(id);
  59. package.Version = new SemanticVersion(2, 0, 0, 0);
  60. bool result = recentPackageInfo.IsMatch(package);
  61. Assert.IsFalse(result);
  62. }
  63. [Test]
  64. public void IsMatch_PackageWithDifferentIdButSameVersionPassed_ReturnsFalse()
  65. {
  66. var version = new SemanticVersion(1, 0, 0, 0);
  67. var recentPackageInfo = new RecentPackageInfo("id", version);
  68. var package = new FakePackage("different-id");
  69. package.Version = version;
  70. bool result = recentPackageInfo.IsMatch(package);
  71. Assert.IsFalse(result);
  72. }
  73. [Test]
  74. public void Version_SerializeThenDeserializeRecentPackageInfoInPropertiesObject_ReturnsSameValueAfterDeserialization()
  75. {
  76. var version = new SemanticVersion(1, 0, 0, 0);
  77. var recentPackageInfo = new RecentPackageInfo("id", version);
  78. var properties = new Properties();
  79. properties.Set<RecentPackageInfo>("RecentPackageInfo", recentPackageInfo);
  80. XElement savedXml = properties.Save();
  81. properties = Properties.Load(savedXml);
  82. var deserializedRecentPackageInfo = properties.Get<RecentPackageInfo>("RecentPackageInfo", (RecentPackageInfo)null);
  83. Assert.AreEqual(recentPackageInfo.Version, deserializedRecentPackageInfo.Version);
  84. }
  85. }
  86. }