public void IsPartialMatchWithHighestOverlap() { var first = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(2, 0)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(long).FullName, typeof(long).Assembly.GetName()), new Version(2, 1)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(double).FullName, typeof(double).Assembly.GetName()), new Version(2, 2)), }); var second = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(sbyte).FullName, typeof(sbyte).Assembly.GetName()), new Version(1, 0)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(short).FullName, typeof(short).Assembly.GetName()), new Version(1, 1)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(1, 2)), }); Assert.IsTrue(second.IsPartialMatch(first)); }
public void IsPartialMatchWithNullReference() { var fallback = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(1, 0)), }); Assert.IsFalse(fallback.IsPartialMatch(null)); }
public void HighestVersionMatchWithNullReference() { var fallback = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(1, 0)), }); Assert.Throws <ArgumentNullException>(() => fallback.HighestVersionMatch(null)); }
/// <summary> /// Returns the type information for the type which is in both collections and has the highest version number. /// </summary> /// <param name="other">The other collection.</param> /// <returns> /// The type information for the type which is in both collections and has the highest version number. /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="other"/> is <see langword="null" />. /// </exception> public OfflineTypeInformation HighestVersionMatch(VersionedTypeFallback other) { { Lokad.Enforce.Argument(() => other); } var bestMatchPair = m_Types.Intersect(other.m_Types, new VersionedOfflineTypeEqualityComparer()) .OrderByDescending(t => t.Item2) .FirstOrDefault(); return(bestMatchPair != null ? bestMatchPair.Item1 : null); }
public bool IsPartialMatch(VersionedTypeFallback other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(m_Types.Intersect(other.m_Types, new VersionedOfflineTypeEqualityComparer()).Any()); }
public void IsPartialMatchWithNoMatch() { var first = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(1, 0)), }); var second = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(double).FullName, typeof(int).Assembly.GetName()), new Version(1, 0)), }); Assert.IsFalse(first.IsPartialMatch(second)); }
public void HighestVersionMatchWithOverlap() { var firstType = new OfflineTypeInformation(typeof(long).FullName, typeof(long).Assembly.GetName()); var first = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(2, 0)), new Tuple <OfflineTypeInformation, Version>( firstType, new Version(2, 1)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(double).FullName, typeof(double).Assembly.GetName()), new Version(2, 2)), }); var secondType = new OfflineTypeInformation(typeof(long).FullName, typeof(long).Assembly.GetName()); var second = new VersionedTypeFallback( new[] { new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(sbyte).FullName, typeof(sbyte).Assembly.GetName()), new Version(1, 0)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(short).FullName, typeof(short).Assembly.GetName()), new Version(1, 1)), new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(typeof(int).FullName, typeof(int).Assembly.GetName()), new Version(1, 1)), new Tuple <OfflineTypeInformation, Version>( secondType, new Version(1, 2)), }); var type = first.HighestVersionMatch(second); Assert.AreEqual(firstType, type); }