From dedf9869ea3a86ee14eafa575ed0dfb04a5487cd Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 9 Apr 2020 13:09:13 -0400 Subject: [PATCH] Fix RightsHelper.AllRights add test --- src/Tgstation.Server.Api/Rights/RightsHelper.cs | 8 ++++---- tests/Tgstation.Server.Api.Tests/Rights/TestRights.cs | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Tgstation.Server.Api/Rights/RightsHelper.cs b/src/Tgstation.Server.Api/Rights/RightsHelper.cs index f2a4772cb0..d63732ba2a 100644 --- a/src/Tgstation.Server.Api/Rights/RightsHelper.cs +++ b/src/Tgstation.Server.Api/Rights/RightsHelper.cs @@ -79,11 +79,11 @@ namespace Tgstation.Server.Api.Rights public static TRight AllRights() where TRight : Enum { ulong rights = 0; - Type rightsType = typeof(TRight); - foreach (Enum J in Enum.GetValues(rightsType)) - rights = rights | Convert.ToUInt64(J, CultureInfo.InvariantCulture); + foreach (Enum J in Enum.GetValues(typeof(TRight))) + rights |= Convert.ToUInt64(J, CultureInfo.InvariantCulture); - return (TRight)Convert.ChangeType(rights, rightsType, CultureInfo.InvariantCulture); + // cri evertim + return (TRight)(object)rights; } } } diff --git a/tests/Tgstation.Server.Api.Tests/Rights/TestRights.cs b/tests/Tgstation.Server.Api.Tests/Rights/TestRights.cs index afa8774bae..eb65d25aac 100644 --- a/tests/Tgstation.Server.Api.Tests/Rights/TestRights.cs +++ b/tests/Tgstation.Server.Api.Tests/Rights/TestRights.cs @@ -36,5 +36,14 @@ namespace Tgstation.Server.Api.Rights.Tests } } } + + [TestMethod] + public void TestAllRightsWorks() + { + var allByondRights = ByondRights.CancelInstall | ByondRights.ChangeVersion | ByondRights.ListInstalled | ByondRights.ReadActive; + var automaticByondRights = RightsHelper.AllRights(); + + Assert.AreEqual(allByondRights, automaticByondRights); + } } }