Browse Source

Added extension method: HasSameExtraProperties

pull/13644/head
Halil İbrahim Kalkan 4 years ago
parent
commit
ede078a4b1
  1. 27
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/ExtraPropertyDictionaryExtensions.cs
  2. 11
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs
  3. 21
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/HasExtraPropertiesExtensions_Tests.cs

27
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/ExtraPropertyDictionaryExtensions.cs

@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
namespace Volo.Abp.Data;
@ -26,4 +27,28 @@ public static class ExtraPropertyDictionaryExtensions
extraPropertyDictionary[key] = Enum.Parse(enumType, extraPropertyDictionary[key].ToString(), ignoreCase: true);
return extraPropertyDictionary[key];
}
}
public static bool HasSameItems(
[NotNull] this ExtraPropertyDictionary dictionary,
[NotNull] ExtraPropertyDictionary otherDictionary)
{
Check.NotNull(dictionary, nameof(dictionary));
Check.NotNull(otherDictionary, nameof(otherDictionary));
if (dictionary.Count != otherDictionary.Count)
{
return false;
}
foreach (var key in dictionary.Keys)
{
if (!otherDictionary.ContainsKey(key) ||
dictionary[key]?.ToString() != otherDictionary[key]?.ToString())
{
return false;
}
}
return true;
}
}

11
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Reflection;
@ -121,4 +122,14 @@ public static class HasExtraPropertiesExtensions
source.RemoveProperty(property.Name);
}
}
public static bool HasSameExtraProperties(
[NotNull] this IHasExtraProperties source,
[NotNull] IHasExtraProperties other)
{
Check.NotNull(source, nameof(source));
Check.NotNull(other, nameof(other));
return source.ExtraProperties.HasSameItems(other.ExtraProperties);
}
}

21
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/HasExtraPropertiesExtensions_Tests.cs

@ -45,4 +45,25 @@ public class HasExtraPropertiesExtensions_Tests
city.SetProperty("DateTime?", DateTime.MinValue);
city.GetProperty<DateTime?>("DateTime?").ShouldBe(DateTime.MinValue);
}
[Fact]
public void HasSameExtraProperties_Tests()
{
var adana = new City(Guid.NewGuid(), "Adana");
adana.SetProperty("IsHot", true);
var antalya = new City(Guid.NewGuid(), "Antalya");
antalya.SetProperty("IsHot", true);
adana.HasSameExtraProperties(antalya).ShouldBeTrue();
adana.SetProperty("IsHot", false);
adana.HasSameExtraProperties(antalya).ShouldBeFalse();
adana.SetProperty("IsHot", true);
adana.HasSameExtraProperties(antalya).ShouldBeTrue();
adana.SetProperty("Population", 3_000_000);
adana.HasSameExtraProperties(antalya).ShouldBeFalse();
}
}

Loading…
Cancel
Save