From 38d5cb190d073b07b8ad6c0a8e7e36bdd5498ddc Mon Sep 17 00:00:00 2001 From: Maria Furman Date: Fri, 18 Oct 2019 12:21:56 -0700 Subject: [PATCH] Added a setter for the AuthenticationProtocolMessage.Script property (#1280) --- .../AuthenticationProtocolMessage.cs | 26 +++++++++++++++---- .../AuthenticationProtocolMessageTests.cs | 4 ++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.IdentityModel.Protocols/AuthenticationProtocolMessage.cs b/src/Microsoft.IdentityModel.Protocols/AuthenticationProtocolMessage.cs index 24ff3e9cce..c777323457 100644 --- a/src/Microsoft.IdentityModel.Protocols/AuthenticationProtocolMessage.cs +++ b/src/Microsoft.IdentityModel.Protocols/AuthenticationProtocolMessage.cs @@ -40,6 +40,7 @@ namespace Microsoft.IdentityModel.Protocols public abstract class AuthenticationProtocolMessage { private string _postTitle = "Working..."; + private string _script = ""; private string _scriptButtonText = "Submit"; private string _scriptDisabledText = "Script is disabled. Click Submit to continue."; @@ -148,7 +149,7 @@ public string IssuerAddress set { if (value == null) - throw LogHelper.LogArgumentNullException("value"); + throw LogHelper.LogArgumentNullException(nameof(IssuerAddress)); _issuerAddress = value; } @@ -179,7 +180,7 @@ public string PostTitle set { if (value == null) - throw LogHelper.LogArgumentNullException("value"); + throw LogHelper.LogArgumentNullException(nameof(PostTitle)); _postTitle = value; } @@ -239,7 +240,22 @@ public virtual void SetParameters(NameValueCollection nameValueCollection) /// /// Gets the script used when constructing the post string. /// - public string Script { get; } = ""; + /// If the 'value' is null. + public string Script + { + get + { + return _script; + } + + set + { + if (value == null) + throw LogHelper.LogArgumentNullException(nameof(Script)); + + _script = value; + } + } /// /// Gets or sets the script button text used when constructing the post string. @@ -255,7 +271,7 @@ public string ScriptButtonText set { if (value == null) - throw LogHelper.LogArgumentNullException("value"); + throw LogHelper.LogArgumentNullException(nameof(ScriptButtonText)); _scriptButtonText = value; } @@ -275,7 +291,7 @@ public string ScriptDisabledText set { if (value == null) - throw LogHelper.LogArgumentNullException("value"); + throw LogHelper.LogArgumentNullException(nameof(ScriptDisabledText)); _scriptDisabledText = value; } diff --git a/test/Microsoft.IdentityModel.Protocols.Tests/AuthenticationProtocolMessageTests.cs b/test/Microsoft.IdentityModel.Protocols.Tests/AuthenticationProtocolMessageTests.cs index d2501ee2c8..da73e22ce0 100644 --- a/test/Microsoft.IdentityModel.Protocols.Tests/AuthenticationProtocolMessageTests.cs +++ b/test/Microsoft.IdentityModel.Protocols.Tests/AuthenticationProtocolMessageTests.cs @@ -71,6 +71,7 @@ public void GetSets() { "IssuerAddress", "PostTitle", + "Script", "ScriptButtonText", "ScriptDisabledText", }; @@ -78,7 +79,8 @@ public void GetSets() var context = new GetSetContext(); foreach(string property in properties) { - TestUtilities.SetGet(authenticationProtocolMessage, property, null, ExpectedException.ArgumentNullException(substringExpected: "value"), context); + TestUtilities.SetGet(authenticationProtocolMessage, property, null, ExpectedException.ArgumentNullException(substringExpected: property), context); + TestUtilities.SetGet(authenticationProtocolMessage, property, "", ExpectedException.NoExceptionExpected, context); TestUtilities.SetGet(authenticationProtocolMessage, property, property, ExpectedException.NoExceptionExpected, context); TestUtilities.SetGet(authenticationProtocolMessage, property, " ", ExpectedException.NoExceptionExpected, context); TestUtilities.SetGet(authenticationProtocolMessage, property, "\t\n\r", ExpectedException.NoExceptionExpected, context);