Ionite
1 year ago
6 changed files with 43 additions and 54 deletions
@ -0,0 +1,35 @@
|
||||
using DynamicData; |
||||
|
||||
namespace StabilityMatrix.Core.Extensions; |
||||
|
||||
public static class DynamicDataExtensions |
||||
{ |
||||
/// <summary> |
||||
/// Loads the cache with the specified items in an optimised manner i.e. calculates the differences between the old and new items |
||||
/// in the list and amends only the differences. |
||||
/// </summary> |
||||
/// <typeparam name="TObject">The type of the object.</typeparam> |
||||
/// <typeparam name="TKey">The type of the key.</typeparam> |
||||
/// <param name="source">The source.</param> |
||||
/// <param name="allItems">The items to add, update or delete.</param> |
||||
/// <exception cref="System.ArgumentNullException">source.</exception> |
||||
public static void EditDiff<TObject, TKey>( |
||||
this ISourceCache<TObject, TKey> source, |
||||
IEnumerable<TObject> allItems |
||||
) |
||||
where TObject : IEquatable<TObject> |
||||
where TKey : notnull |
||||
{ |
||||
if (source is null) |
||||
{ |
||||
throw new ArgumentNullException(nameof(source)); |
||||
} |
||||
|
||||
if (allItems is null) |
||||
{ |
||||
throw new ArgumentNullException(nameof(allItems)); |
||||
} |
||||
|
||||
source.EditDiff(allItems, (x, y) => x.Equals(y)); |
||||
} |
||||
} |
@ -1,33 +0,0 @@
|
||||
using StabilityMatrix.Core.Models; |
||||
using StabilityMatrix.Core.Models.Database; |
||||
|
||||
namespace StabilityMatrix.Tests.Models; |
||||
|
||||
[TestClass] |
||||
public class LocalImageFileTests |
||||
{ |
||||
[TestMethod] |
||||
public void TestComparer() |
||||
{ |
||||
var comparer = LocalImageFile.Comparer; |
||||
|
||||
var file1 = new LocalImageFile |
||||
{ |
||||
AbsolutePath = "same", |
||||
GenerationParameters = new GenerationParameters { Width = 10 } |
||||
}; |
||||
|
||||
var file2 = new LocalImageFile |
||||
{ |
||||
AbsolutePath = "same", |
||||
GenerationParameters = new GenerationParameters { Width = 10 } |
||||
}; |
||||
|
||||
var file3 = new LocalImageFile { AbsolutePath = "different" }; |
||||
|
||||
Assert.IsTrue(comparer.Equals(file1, file2)); |
||||
Assert.AreEqual(comparer.GetHashCode(file1), comparer.GetHashCode(file2)); |
||||
Assert.IsFalse(comparer.Equals(file1, file3)); |
||||
Assert.AreNotEqual(comparer.GetHashCode(file1), comparer.GetHashCode(file3)); |
||||
} |
||||
} |
Loading…
Reference in new issue