nunomaia / NwRfcNet

An easy way of making SAP RFC calls from .NET Core
Apache License 2.0
96 stars 28 forks source link

Fix ArgumentException in RfcConnectionParameterBuilder #55

Closed DavidStahl97 closed 4 years ago

DavidStahl97 commented 4 years ago

I want to try your library for a SSO scenario and need to set the snc_mode but the method UseSecureNetworkCommunicationMode of the class RfcConnectionParameterBuilder throws always an ArgumentException:

        public RfcConnectionParameterBuilder UseSecureNetworkCommunicationMode(string sncMode, string key = RfcConnectionParameters.DefaultSncModeParameterKey)
        {
            if (int.TryParse(sncMode, out var parsed) && (parsed == 0 || parsed == 1))
            {
                SetParameter(key, parsed.ToString());
            }

            throw new ArgumentException(paramName: nameof(sncMode), message: "The only permitted values for the snc-mode are: '0' for SNC-Disabled or'1' for SNC-Enabled.");
        }

It is the same thing with the UseSecureNetworkCommunicationQop method.

The pull request fixed it and added unit tests for the two methods.

        public RfcConnectionParameterBuilder UseSecureNetworkCommunicationMode(string sncMode, string key = RfcConnectionParameters.DefaultSncModeParameterKey)
        {
            if (int.TryParse(sncMode, out var parsed) == false || (parsed != 0 && parsed != 1))
            {
                throw new ArgumentException(paramName: nameof(sncMode), message: "The only permitted values for the snc-mode are: '0' for SNC-Disabled or'1' for SNC-Enabled.");                
            }

            return SetParameter(key, parsed.ToString());
        }

At the moment using UseAdditionalParameter is an alternative to avoid the ArgumentException:

builder.UseAdditionalParameter("snc_mode", "1")
   .UseAdditionalParameter("snc_qop", "3");