PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 19using System;
 20using System.IO;
 21using System.Text;
 22using System.Xml;
 23
 24using System.Xml.Linq;
 25using ICSharpCode.Core;
 26using ICSharpCode.PackageManagement;
 27using ICSharpCode.PackageManagement.Design;
 28using NuGet;
 29using NUnit.Framework;
 30
 31namespace PackageManagement.Tests
 32{
 33	[TestFixture]
 34	public class RecentPackageInfoTests
 35	{
 36		[Test]
 37		public void ToString_IdAndVersionSpecified_ContainsIdAndVersion()
 38		{
 39			var recentPackageInfo = new RecentPackageInfo("id", new SemanticVersion("1.0"));
 40			
 41			string actual = recentPackageInfo.ToString();
 42			
 43			string expected = "[RecentPackageInfo Id=id, Version=1.0]";
 44			Assert.AreEqual(expected, actual);
 45		}
 46		
 47		[Test]
 48		public void IsMatch_PackageWithSameIdAndVersionPassed_ReturnsTrue()
 49		{
 50			string id = "id";
 51			var version = new SemanticVersion(1, 0, 0, 0);
 52			var recentPackageInfo = new RecentPackageInfo(id, version);
 53			var package = new FakePackage(id);
 54			package.Version = version;
 55			
 56			bool result = recentPackageInfo.IsMatch(package);
 57			
 58			Assert.IsTrue(result);
 59		}
 60		
 61		[Test]
 62		public void IsMatch_PackageWithSameIdButDifferentVersionPassed_ReturnsFalse()
 63		{
 64			string id = "id";
 65			var version = new SemanticVersion(1, 0, 0, 0);
 66			var recentPackageInfo = new RecentPackageInfo(id, version);
 67			var package = new FakePackage(id);
 68			package.Version = new SemanticVersion(2, 0, 0, 0);
 69			
 70			bool result = recentPackageInfo.IsMatch(package);
 71			
 72			Assert.IsFalse(result);
 73		}
 74		
 75		[Test]
 76		public void IsMatch_PackageWithDifferentIdButSameVersionPassed_ReturnsFalse()
 77		{
 78			var version = new SemanticVersion(1, 0, 0, 0);
 79			var recentPackageInfo = new RecentPackageInfo("id", version);
 80			var package = new FakePackage("different-id");
 81			package.Version = version;
 82			
 83			bool result = recentPackageInfo.IsMatch(package);
 84			
 85			Assert.IsFalse(result);
 86		}
 87		
 88		[Test]
 89		public void Version_SerializeThenDeserializeRecentPackageInfoInPropertiesObject_ReturnsSameValueAfterDeserialization()
 90		{
 91			var version = new SemanticVersion(1, 0, 0, 0);
 92			var recentPackageInfo = new RecentPackageInfo("id", version);
 93			var properties = new Properties();
 94			properties.Set<RecentPackageInfo>("RecentPackageInfo", recentPackageInfo);
 95			
 96			XElement savedXml = properties.Save();
 97			properties = Properties.Load(savedXml);
 98			var deserializedRecentPackageInfo = properties.Get<RecentPackageInfo>("RecentPackageInfo", (RecentPackageInfo)null);
 99			
100			Assert.AreEqual(recentPackageInfo.Version, deserializedRecentPackageInfo.Version);
101		}
102	}
103}