@ -24,36 +24,123 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
# endregion
using System ;
using System.Collections.Generic ;
using NUnit.Framework ;
using PlexRequests.Core.Models ;
using PlexRequests.Core.SettingModels ;
namespace PlexRequests.Core.Tests
{
[TestFixture]
public class AuthenticationSettingsTests
public class NotificationMessageResolverTests
{
[TestCaseSource(nameof(MessageBodyResolver))]
public string ResolveBody ( string body , NotificationMessageCurlys param )
{
[Test, TestCaseSource(nameof(UserData))]
public void DeniedUserListTest ( string users , string [ ] expected )
var n = new NotificationMessageResolver ( ) ;
var s = new NotificationSettings
{
var model = new AuthenticationSettings { DeniedUsers = users } ;
Message = new Dictionary < NotificationType , NotificationMessageContent > { { NotificationType . NewRequest , new NotificationMessageContent { Body = body } } }
} ;
var result = model . DeniedUserList ;
var result = n . ParseMessage ( s , NotificationType . NewRequest , param ) ;
return result . Body ;
}
Assert . That ( result . Count , Is . EqualTo ( expected . Length ) ) ;
for ( var i = 0 ; i < expected . Length ; i + + )
[TestCaseSource(nameof(MessageSubjectResolver))]
public string ResolveSubject ( string subject , NotificationMessageCurlys param )
{
Assert . That ( result [ i ] , Is . EqualTo ( expected [ i ] ) ) ;
}
var n = new NotificationMessageResolver ( ) ;
var s = new NotificationSettings
{
Message = new Dictionary < NotificationType , NotificationMessageContent > { { NotificationType . NewRequest , new NotificationMessageContent { Subject = subject } } }
} ;
var result = n . ParseMessage ( s , NotificationType . NewRequest , param ) ;
return result . Subject ;
}
static readonly object [ ] UserData =
private static IEnumerable < TestCaseData > MessageSubjectResolver
{
new object [ ] { "john" , new [ ] { "john" } } ,
new object [ ] { "john , abc ," , new [ ] { "john" , "abc" } } ,
new object [ ] { "john,, cde" , new [ ] { "john" , "cde" } } ,
new object [ ] { "john,,, aaa , baaa , " , new [ ] { "john" , "aaa" , "baaa" } } ,
new object [ ] { "john, aaa , baaa , maaa, caaa" , new [ ] { "john" , "aaa" , "baaa" , "maaa" , "caaa" } } ,
} ;
get
{
yield return new TestCaseData (
"{Username} has requested a {Type}" ,
new NotificationMessageCurlys ( "Jamie" , "Finding Dory" , DateTime . Now . ToString ( ) , "Movie" , string . Empty ) )
. Returns ( "Jamie has requested a Movie" ) . SetName ( "Subject Curlys" ) ;
yield return new TestCaseData (
null ,
new NotificationMessageCurlys ( "Jamie" , "Finding Dory" , DateTime . Now . ToString ( ) , "Movie" , string . Empty ) )
. Returns ( string . Empty ) . SetName ( "Empty Subject" ) ;
yield return new TestCaseData (
"New Request Incoming!" ,
new NotificationMessageCurlys ( "Jamie" , "Finding Dory" , DateTime . Now . ToString ( ) , "Movie" , string . Empty ) )
. Returns ( "New Request Incoming!" ) . SetName ( "No curlys" ) ;
yield return new TestCaseData (
"%$R£%$£^%$&{Username}@{}:§" ,
new NotificationMessageCurlys ( "Jamie" , "Finding Dory" , DateTime . Now . ToString ( ) , "Movie" , string . Empty ) )
. Returns ( "%$R£%$£^%$&Jamie@{}:§" ) . SetName ( "Special Chars" ) ;
}
}
private static IEnumerable < TestCaseData > MessageBodyResolver
{
get
{
yield return new TestCaseData (
"There has been a new request from {Username}, Title: {Title} for {Type}" ,
new NotificationMessageCurlys ( "Jamie" , "Finding Dory" , DateTime . Now . ToString ( ) , "Movie" , string . Empty ) )
. Returns ( "There has been a new request from Jamie, Title: Finding Dory for Movie" ) . SetName ( "FindingDory" ) ;
yield return new TestCaseData (
null ,
new NotificationMessageCurlys ( string . Empty , string . Empty , string . Empty , string . Empty , string . Empty ) )
. Returns ( string . Empty )
. SetName ( "Empty Message" ) ;
yield return new TestCaseData (
"{{Wowwzer}} Damn}{{Username}}}}" ,
new NotificationMessageCurlys ( "HEY!" , string . Empty , string . Empty , string . Empty , string . Empty ) )
. Returns ( "{{Wowwzer}} Damn}{HEY!}}}" )
. SetName ( "Multiple Curlys" ) ;
yield return new TestCaseData (
"This is a message with no curlys" ,
new NotificationMessageCurlys ( "Jamie" , "Finding Dory" , DateTime . Now . ToString ( ) , "Movie" , string . Empty ) )
. Returns ( "This is a message with no curlys" )
. SetName ( "No Curlys" ) ;
yield return new TestCaseData (
new string ( ')' , 5000 ) ,
new NotificationMessageCurlys ( string . Empty , string . Empty , string . Empty , string . Empty , string . Empty ) )
. Returns ( new string ( ')' , 5000 ) )
. SetName ( "Long String" ) ;
yield return new TestCaseData (
"This is a {Username} and {Username} Because {Issue}{Issue}" ,
new NotificationMessageCurlys ( "HEY!" , string . Empty , string . Empty , string . Empty , "Bob" ) )
. Returns ( "This is a HEY! and HEY! Because BobBob" )
. SetName ( "Double Curly" ) ;
yield return new TestCaseData (
"This is a {username} and {username} Because {Issue}{Issue}" ,
new NotificationMessageCurlys ( "HEY!" , string . Empty , string . Empty , string . Empty , "Bob" ) )
. Returns ( "This is a {username} and {username} Because BobBob" )
. SetName ( "Case sensitive" ) ;
yield return new TestCaseData (
"{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}" ,
new NotificationMessageCurlys ( "HEY!" , string . Empty , "b" , string . Empty , "Bob" ) )
. Returns ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" )
. SetName ( "Lots of curlys" ) ;
}
}
}
}