|
| 1 | +public class PackageCacheKeyComparerTests |
| 2 | +{ |
| 3 | + static PackageCacheKeyComparer comparer = PackageCacheKeyComparer.Instance; |
| 4 | + |
| 5 | + [Fact] |
| 6 | + public void Equals_SamePackageAndVersion() |
| 7 | + { |
| 8 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 9 | + var y = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 10 | + |
| 11 | + Assert.True(comparer.Equals(x, y)); |
| 12 | + } |
| 13 | + |
| 14 | + [Fact] |
| 15 | + public void Equals_DifferentCase() |
| 16 | + { |
| 17 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 18 | + var y = ("newtonsoft.json", NuGetVersion.Parse("13.0.1")); |
| 19 | + |
| 20 | + Assert.True(comparer.Equals(x, y)); |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public void Equals_DifferentVersion() |
| 25 | + { |
| 26 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 27 | + var y = ("Newtonsoft.Json", NuGetVersion.Parse("12.0.1")); |
| 28 | + |
| 29 | + Assert.False(comparer.Equals(x, y)); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void Equals_DifferentPackage() |
| 34 | + { |
| 35 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 36 | + var y = ("NUnit", NuGetVersion.Parse("13.0.1")); |
| 37 | + |
| 38 | + Assert.False(comparer.Equals(x, y)); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void GetHashCode_SameForDifferentCase() |
| 43 | + { |
| 44 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 45 | + var y = ("newtonsoft.json", NuGetVersion.Parse("13.0.1")); |
| 46 | + |
| 47 | + Assert.Equal(comparer.GetHashCode(x), comparer.GetHashCode(y)); |
| 48 | + } |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void GetHashCode_DifferentForDifferentVersion() |
| 52 | + { |
| 53 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 54 | + var y = ("Newtonsoft.Json", NuGetVersion.Parse("12.0.1")); |
| 55 | + |
| 56 | + Assert.NotEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void GetHashCode_DifferentForDifferentPackage() |
| 61 | + { |
| 62 | + var x = ("Newtonsoft.Json", NuGetVersion.Parse("13.0.1")); |
| 63 | + var y = ("NUnit", NuGetVersion.Parse("13.0.1")); |
| 64 | + |
| 65 | + Assert.NotEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); |
| 66 | + } |
| 67 | + |
| 68 | + [Fact] |
| 69 | + public void WorksWithDictionary() |
| 70 | + { |
| 71 | + var dictionary = new Dictionary<(string Package, NuGetVersion Version), string>(comparer) |
| 72 | + { |
| 73 | + [("Newtonsoft.Json", NuGetVersion.Parse("13.0.1"))] = "first" |
| 74 | + }; |
| 75 | + |
| 76 | + Assert.True(dictionary.ContainsKey(("newtonsoft.json", NuGetVersion.Parse("13.0.1")))); |
| 77 | + Assert.True(dictionary.ContainsKey(("NEWTONSOFT.JSON", NuGetVersion.Parse("13.0.1")))); |
| 78 | + Assert.False(dictionary.ContainsKey(("Newtonsoft.Json", NuGetVersion.Parse("12.0.1")))); |
| 79 | + } |
| 80 | +} |
0 commit comments