mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
Some more unit tests around the NotificationMessageResolver
This commit is contained in:
parent
a32599cbde
commit
7e6742e70c
2 changed files with 29 additions and 2 deletions
|
@ -84,6 +84,31 @@ namespace PlexRequests.Core.Tests
|
|||
new Dictionary<string, string> { { "son", "HEY!" } })
|
||||
.Returns(new string(')', 5000))
|
||||
.SetName("Long String");
|
||||
|
||||
|
||||
yield return new TestCaseData(
|
||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "This is a {Username} and {Username} Because {Curly}{Curly}" } },
|
||||
new Dictionary<string, string> { { "Username", "HEY!" }, {"Curly","Bob"} })
|
||||
.Returns("This is a HEY! and HEY! Because BobBob")
|
||||
.SetName("Double Curly");
|
||||
|
||||
yield return new TestCaseData(
|
||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "This is a {Username} and {Username} Because {Curly}{Curly}" } },
|
||||
new Dictionary<string, string> { { "username", "HEY!" }, { "Curly", "Bob" } })
|
||||
.Returns("This is a {Username} and {Username} Because BobBob")
|
||||
.SetName("Case sensitive");
|
||||
|
||||
yield return new TestCaseData(
|
||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}" } },
|
||||
new Dictionary<string, string> { { "a", "b" } })
|
||||
.Returns("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
|
||||
.SetName("Lots of curlys");
|
||||
|
||||
yield return new TestCaseData(
|
||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, $"{{{new string('b', 10000)}}}" } },
|
||||
new Dictionary<string, string> { { new string('b', 10000), "Hello" } })
|
||||
.Returns("Hello")
|
||||
.SetName("Very long Curly");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace PlexRequests.Core
|
|||
{
|
||||
public class NotificationMessageResolver
|
||||
{
|
||||
private const char StartChar = (char)123;
|
||||
private const char EndChar = (char)125;
|
||||
public string ParseMessage<T>(T notification, NotificationType type) where T : NotificationSettings
|
||||
{
|
||||
var notificationToParse = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
||||
|
@ -75,13 +77,13 @@ namespace PlexRequests.Core
|
|||
continue;
|
||||
}
|
||||
|
||||
if (c == 123) // Start of curly '{'
|
||||
if (c == StartChar) // Start of curly '{'
|
||||
{
|
||||
insideCurly = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == 125) // End of curly '}'
|
||||
if (c == EndChar) // End of curly '}'
|
||||
{
|
||||
fields.Add(currentWord); // We have finished the curly, add the word into the list
|
||||
currentWord = string.Empty;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue