aboutsummaryrefslogtreecommitdiff
path: root/Timeline.Tests/Helpers/UserInfoComparers.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-05-16 21:57:56 +0800
committercrupest <crupest@outlook.com>2019-05-16 21:57:56 +0800
commitf0a317cc511a4a7b04a701c32881d1e3331f3711 (patch)
treea71563526342e8cc4a2c99227fcd178ea6d1fbde /Timeline.Tests/Helpers/UserInfoComparers.cs
parent44485a4559d75c8798972ba502c104d7e801e9ba (diff)
downloadtimeline-f0a317cc511a4a7b04a701c32881d1e3331f3711.tar.gz
timeline-f0a317cc511a4a7b04a701c32881d1e3331f3711.tar.bz2
timeline-f0a317cc511a4a7b04a701c32881d1e3331f3711.zip
Change roles in UserInfo into isadmin.
Diffstat (limited to 'Timeline.Tests/Helpers/UserInfoComparers.cs')
-rw-r--r--Timeline.Tests/Helpers/UserInfoComparers.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/Timeline.Tests/Helpers/UserInfoComparers.cs b/Timeline.Tests/Helpers/UserInfoComparers.cs
new file mode 100644
index 00000000..d88b6622
--- /dev/null
+++ b/Timeline.Tests/Helpers/UserInfoComparers.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Timeline.Entities;
+
+namespace Timeline.Tests.Helpers
+{
+ public static class UserInfoComparers
+ {
+ public static IEqualityComparer<UserInfo> EqualityComparer { get; } = new EqualityComparerImpl();
+ public static IComparer<UserInfo> Comparer { get; } = Comparer<UserInfo>.Create(Compare);
+
+
+ private class EqualityComparerImpl : IEqualityComparer<UserInfo>
+ {
+ bool IEqualityComparer<UserInfo>.Equals(UserInfo x, UserInfo y)
+ {
+ return Compare(x, y) == 0;
+ }
+
+ int IEqualityComparer<UserInfo>.GetHashCode(UserInfo obj)
+ {
+ return obj.Username.GetHashCode() ^ obj.IsAdmin.GetHashCode();
+ }
+ }
+
+ public static int Compare(UserInfo left, UserInfo right)
+ {
+ if (left == null)
+ {
+ if (right == null)
+ return 0;
+ return -1;
+ }
+
+ if (right == null)
+ return 1;
+
+ var uc = string.Compare(left.Username, right.Username);
+ if (uc != 0)
+ return uc;
+
+ if (left.IsAdmin == right.IsAdmin)
+ return 0;
+
+ return left.IsAdmin ? -1 : 1;
+ }
+ }
+}