From f0ce5556c3b8ebc522af4d2a531558dc0634c375 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 8 Jul 2016 14:47:01 +0100 Subject: [PATCH] Added tests for the string hash --- PlexRequests.Api/CouchPotatoApi.cs | 4 +- .../PlexRequests.Helpers.Tests.csproj | 1 + .../StringHasherTests.cs | 54 +++++++++++++++++++ PlexRequests.Helpers/StringHasher.cs | 4 +- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 PlexRequests.Helpers.Tests/StringHasherTests.cs diff --git a/PlexRequests.Api/CouchPotatoApi.cs b/PlexRequests.Api/CouchPotatoApi.cs index 99f2563cc..9f5bb7887 100644 --- a/PlexRequests.Api/CouchPotatoApi.cs +++ b/PlexRequests.Api/CouchPotatoApi.cs @@ -169,8 +169,8 @@ namespace PlexRequests.Api Method = Method.GET }; - request.AddUrlSegment("username", StringHasher.CalcuateMD5Hash(username)); - request.AddUrlSegment("password", StringHasher.CalcuateMD5Hash(password)); + request.AddUrlSegment("username", StringHasher.CalcuateMd5Hash(username)); + request.AddUrlSegment("password", StringHasher.CalcuateMd5Hash(password)); var obj = RetryHandler.Execute(() => Api.Execute(request, baseUrl), null, (exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan)); diff --git a/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj b/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj index 79362e466..5194c29e7 100644 --- a/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj +++ b/PlexRequests.Helpers.Tests/PlexRequests.Helpers.Tests.csproj @@ -73,6 +73,7 @@ + diff --git a/PlexRequests.Helpers.Tests/StringHasherTests.cs b/PlexRequests.Helpers.Tests/StringHasherTests.cs new file mode 100644 index 000000000..e09fea347 --- /dev/null +++ b/PlexRequests.Helpers.Tests/StringHasherTests.cs @@ -0,0 +1,54 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: DateTimeHelperTests.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +using System; +using System.Collections.Generic; + +using NUnit.Framework; + +namespace PlexRequests.Helpers.Tests +{ + [TestFixture] + public class StringHasherTests + { + [TestCaseSource(nameof(StringHashData))] + public string CalcuateMd5HashTest(string input) + { + return StringHasher.CalcuateMd5Hash(input); + } + + private static IEnumerable StringHashData + { + get + { + yield return new TestCaseData("hello!").Returns("5a8dd3ad0756a93ded72b823b19dd877").SetName("Hello"); + yield return new TestCaseData("0111111").Returns("9549d400a68633435918290085f06293").SetName("Number"); + yield return new TestCaseData("hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!hello!").Returns("26d0d126918fbecfc0fa4a63070d314c") + .SetName("Long string"); + } + } + } +} \ No newline at end of file diff --git a/PlexRequests.Helpers/StringHasher.cs b/PlexRequests.Helpers/StringHasher.cs index d91e42d5d..41477b7b7 100644 --- a/PlexRequests.Helpers/StringHasher.cs +++ b/PlexRequests.Helpers/StringHasher.cs @@ -31,7 +31,7 @@ namespace PlexRequests.Helpers { public class StringHasher { - public static string CalcuateMD5Hash(string input) + public static string CalcuateMd5Hash(string input) { using (var md5 = MD5.Create()) { @@ -40,7 +40,7 @@ namespace PlexRequests.Helpers var sb = new StringBuilder(); - foreach (byte t in hash) + foreach (var t in hash) { sb.Append(t.ToString("x2")); }