public void ServiceTest()
        {
            IppConfigurationSection target = new IppConfigurationSection(); // TODO: Initialize to an appropriate value
            ServiceElement          actual = target.Service;

            Assert.IsNotNull(actual);
        }
        public void RetryTest()
        {
            IppConfigurationSection target = new IppConfigurationSection(); // TODO: Initialize to an appropriate value
            RetryElement            actual = target.Retry;

            Assert.IsNotNull(actual);
        }
        public void LoggerTest()
        {
            IppConfigurationSection target = new IppConfigurationSection(); // TODO: Initialize to an appropriate value
            LoggerElement           actual = target.Logger;

            Assert.IsNotNull(actual);
        }
        public void InstanceTest()
        {
            IppConfigurationSection actual = IppConfigurationSection.Instance;

            Assert.IsNotNull(actual.WebhooksService.WebhooksVerifier.Value);
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Logger);
            Assert.IsNotNull(actual.Logger.RequestLog);
            Assert.IsTrue(actual.Logger.RequestLog.EnableRequestResponseLogging);
            Assert.IsNotNull(actual.Logger.RequestLog.RequestResponseLoggingDirectory);
            Assert.IsNotNull(actual.Logger.CustomLogger);
            Assert.IsNotNull(actual.Logger.CustomLogger.Name);
            Assert.IsNotNull(actual.Logger.CustomLogger.Type);
            Assert.IsTrue(actual.Logger.CustomLogger.Enable);
            Assert.IsNotNull(actual.Security);
            Assert.IsNotNull(actual.Security.Mode);
            Assert.IsNotNull(actual.Security.OAuth);
            Assert.IsNotNull(actual.Security.OAuth.AccessToken);
            Assert.IsNotNull(actual.Security.OAuth.AccessTokenSecret);
            Assert.IsNotNull(actual.Security.OAuth.ConsumerKey);
            Assert.IsNotNull(actual.Security.OAuth.ConsumerSecret);
            Assert.IsNotNull(actual.Security.CustomSecurity);
            Assert.IsNotNull(actual.Security.CustomSecurity.Name);
            Assert.IsNotNull(actual.Security.CustomSecurity.Type);
            Assert.IsNotNull(actual.Security.CustomSecurity.Params);
            Assert.IsTrue(actual.Security.CustomSecurity.Enable);
            Assert.IsNotNull(actual.Message);
            Assert.IsNotNull(actual.Message.Request);
            Assert.IsNotNull(actual.Message.Request.CompressionFormat);
            Assert.IsNotNull(actual.Message.Request.SerializationFormat);
            Assert.IsNotNull(actual.Message.Response);
            Assert.IsNotNull(actual.Message.Response.CompressionFormat);
            Assert.IsNotNull(actual.Message.Response.SerializationFormat);
            Assert.IsNotNull(actual.Message.CustomSerializer);
            Assert.IsNotNull(actual.Message.CustomSerializer.Name);
            Assert.IsNotNull(actual.Message.CustomSerializer.Type);
            Assert.IsTrue(actual.Message.CustomSerializer.Enable);
            Assert.IsNotNull(actual.Retry);
            Assert.IsNotNull(actual.Retry.Mode);
            Assert.IsNotNull(actual.Retry.LinearRetry);
            Assert.IsNotNull(actual.Retry.LinearRetry.RetryCount);
            Assert.IsNotNull(actual.Retry.LinearRetry.RetryInterval);
            Assert.IsNotNull(actual.Retry.IncrementatlRetry);
            Assert.IsNotNull(actual.Retry.IncrementatlRetry.RetryCount);
            Assert.IsNotNull(actual.Retry.IncrementatlRetry.InitialInterval);
            Assert.IsNotNull(actual.Retry.IncrementatlRetry.Increment);
            Assert.IsNotNull(actual.Retry.ExponentialRetry);
            Assert.IsNotNull(actual.Retry.ExponentialRetry.RetryCount);
            Assert.IsNotNull(actual.Retry.ExponentialRetry.MinBackoff);
            Assert.IsNotNull(actual.Retry.ExponentialRetry.MaxBackoff);
            Assert.IsNotNull(actual.Retry.ExponentialRetry.DeltaBackoff);
            Assert.IsNotNull(actual.Service);
            Assert.IsNotNull(actual.Service.BaseUrl);
            Assert.IsNotNull(actual.Service.BaseUrl.Qbo);
            Assert.IsNotNull(actual.Service.BaseUrl.Ips);
            Assert.IsNotNull(actual.Service.BaseUrl.UserNameAuthentication);
            Assert.IsNotNull(actual.Service.BaseUrl.OAuthAccessTokenUrl);
        }
        public void ConfigTest_LinearRetry()
        {
            TestHelper.UpdateIppConfig("retry", "mode", RetryMode.Linear.ToString());
            IppConfigurationSection ippConfigurationSection = IppConfigurationSection.Instance;
            Assert.AreEqual(ippConfigurationSection.Retry.Mode, RetryMode.Linear);

            LocalConfigReader reader = new LocalConfigReader();            
            TestHelper.UpdateIppConfig("retry/linearRetry", "retryCount", "1");
            TestHelper.UpdateIppConfig("retry/linearRetry", "retryInterval", new TimeSpan(20).ToString());
            IppConfiguration ippConfig = reader.ReadConfiguration();
            Assert.IsNotNull(ippConfig.RetryPolicy);
        }
        public void ConfigTest_ExponentialRetry()
        {
            TestHelper.UpdateIppConfig("retry", "mode", RetryMode.Exponential.ToString());
            IppConfigurationSection ippConfigurationSection = IppConfigurationSection.Instance;
            Assert.AreEqual(ippConfigurationSection.Retry.Mode, RetryMode.Exponential);

            LocalConfigReader reader = new LocalConfigReader();
            TestHelper.UpdateIppConfig("retry/exponentialRetry", "retryCount", "2");
            TestHelper.UpdateIppConfig("retry/exponentialRetry", "minBackoff", new TimeSpan(20).ToString());
            TestHelper.UpdateIppConfig("retry/exponentialRetry", "maxBackoff", new TimeSpan(20).ToString());
            TestHelper.UpdateIppConfig("retry/exponentialRetry", "deltaBackoff", new TimeSpan(20).ToString());
            IppConfiguration ippConfig = reader.ReadConfiguration();
            Assert.IsNotNull(ippConfig.RetryPolicy);
        }
        /// <summary>
        /// Reads the configuration from the config file and converts it to custom
        /// config objects which the end developer will use to get or set the properties.
        /// </summary>
        /// <returns>The custom config object.</returns>
        public IppConfiguration ReadConfiguration()
        {
            IppConfiguration ippConfig = new IppConfiguration();

#if !NETSTANDARD2_0
            IppConfigurationSection ippConfigurationSection = IppConfigurationSection.Instance;
            if (ippConfigurationSection == null)
            {
                ippConfig.Logger = new Logger
                {
                    CustomLogger = new TraceLogger(),
                    RequestLog   = new RequestLog
                    {
                        EnableRequestResponseLogging  = false,
                        ServiceRequestLoggingLocation = System.IO.Path.GetTempPath()
                    }
                };

                ippConfig.Message = new Message
                {
                    Request = new Request
                    {
                        CompressionFormat   = CompressionFormat.GZip,
                        SerializationFormat = SerializationFormat.Xml//do not change this as it will break code for devs
                    },
                    Response = new Response
                    {
                        CompressionFormat   = CompressionFormat.GZip,
                        SerializationFormat = SerializationFormat.Json
                    }
                };

                ippConfig.BaseUrl = new BaseUrl
                {
                    Qbo = null,
                    Ips = null,
                    OAuthAccessTokenUrl    = null,
                    UserNameAuthentication = null
                };

                ippConfig.MinorVersion = new MinorVersion
                {
                    Qbo = null
                };

                ippConfig.VerifierToken = new VerifierToken
                {
                    Value = null
                };

                return(ippConfig);
            }

            ippConfig.Logger            = new Logger();
            ippConfig.Logger.RequestLog = new RequestLog();
            ippConfig.Logger.RequestLog.EnableRequestResponseLogging = ippConfigurationSection.Logger.RequestLog.EnableRequestResponseLogging;
            if (string.IsNullOrEmpty(ippConfigurationSection.Logger.RequestLog.RequestResponseLoggingDirectory))
            {
                ippConfig.Logger.RequestLog.ServiceRequestLoggingLocation = Path.GetTempPath();
            }
            else
            {
                string location = ippConfigurationSection.Logger.RequestLog.RequestResponseLoggingDirectory;
                if (!Directory.Exists(location))
                {
                    IdsException exception = new IdsException(Properties.Resources.ValidDirectoryPathMessage, new DirectoryNotFoundException());
                    IdsExceptionManager.HandleException(exception);
                }

                ippConfig.Logger.RequestLog.ServiceRequestLoggingLocation = ippConfigurationSection.Logger.RequestLog.RequestResponseLoggingDirectory;
            }

            if (!string.IsNullOrEmpty(ippConfigurationSection.Logger.CustomLogger.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Logger.CustomLogger.Type) && ippConfigurationSection.Logger.CustomLogger.Enable)
            {
                Type customerLoggerType = Type.GetType(ippConfigurationSection.Logger.CustomLogger.Type);
                ippConfig.Logger.CustomLogger = Activator.CreateInstance(customerLoggerType) as ILogger;
            }
            else
            {
                ippConfig.Logger.CustomLogger = new TraceLogger();
            }

            switch (ippConfigurationSection.Security.Mode)
            {
            case SecurityMode.OAuth:
                OAuth2RequestValidator validator = new OAuth2RequestValidator(
                    ippConfigurationSection.Security.OAuth.AccessToken);
                ippConfig.Security = validator;
                break;

            case SecurityMode.Custom:
                if (!string.IsNullOrEmpty(ippConfigurationSection.Security.CustomSecurity.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Security.CustomSecurity.Type) && ippConfigurationSection.Security.CustomSecurity.Enable)
                {
                    Type     customSecurityType = Type.GetType(ippConfigurationSection.Security.CustomSecurity.Type);
                    string[] paramateres        = ippConfigurationSection.Security.CustomSecurity.Params.Split(',');
                    ippConfig.Security = Activator.CreateInstance(customSecurityType, paramateres) as IRequestValidator;
                }

                break;
            }

            //// TODO : This will not be used now.
            ////if (!string.IsNullOrEmpty(ippConfigurationSection.Message.CustomSerializer.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Message.CustomSerializer.Type) && ippConfigurationSection.Message.CustomSerializer.Enable)
            ////{
            ////    Type customSerializerType = Type.GetType(ippConfigurationSection.Message.CustomSerializer.Type);
            ////    IEntitySerializer entitySerializer = Activator.CreateInstance(customSerializerType) as IEntitySerializer;
            ////    if (ippConfigurationSection.Message.Request.SerializationFormat == SerializationFormat.Custom)
            ////    {
            ////        ippConfig.Message.Request.Serializer = entitySerializer;
            ////    }

            ////    if (ippConfigurationSection.Message.Response.SerializationFormat == SerializationFormat.Custom)
            ////    {

            ////        ippConfig.Message.Response.Serializer = entitySerializer;
            ////    }
            ////}

            ippConfig.Message          = new Message();
            ippConfig.Message.Request  = new Request();
            ippConfig.Message.Response = new Response();

            switch (ippConfigurationSection.Message.Request.CompressionFormat)
            {
            case Intuit.Ipp.Utility.CompressionFormat.None:
                ippConfig.Message.Request.CompressionFormat = CompressionFormat.None;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.DEFAULT:
            case Intuit.Ipp.Utility.CompressionFormat.GZip:
                ippConfig.Message.Request.CompressionFormat = CompressionFormat.GZip;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.Deflate:
                ippConfig.Message.Request.CompressionFormat = CompressionFormat.Deflate;
                break;

            default:
                break;
            }



            switch (ippConfigurationSection.Message.Response.CompressionFormat)
            {
            case Intuit.Ipp.Utility.CompressionFormat.None:
                ippConfig.Message.Response.CompressionFormat = CompressionFormat.None;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.DEFAULT:
            case Intuit.Ipp.Utility.CompressionFormat.GZip:
                ippConfig.Message.Response.CompressionFormat = CompressionFormat.GZip;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.Deflate:
                ippConfig.Message.Response.CompressionFormat = CompressionFormat.Deflate;
                break;
            }

            switch (ippConfigurationSection.Message.Request.SerializationFormat)
            {
            case Intuit.Ipp.Utility.SerializationFormat.DEFAULT:
            case Intuit.Ipp.Utility.SerializationFormat.Xml:
                ippConfig.Message.Request.SerializationFormat = SerializationFormat.Xml;    //do not change this as it will break code for devs
                break;

            case Intuit.Ipp.Utility.SerializationFormat.Json:
                ippConfig.Message.Request.SerializationFormat = SerializationFormat.Json;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.Custom:
                ippConfig.Message.Request.SerializationFormat = SerializationFormat.Custom;
                break;
            }

            switch (ippConfigurationSection.Message.Response.SerializationFormat)
            {
            case Intuit.Ipp.Utility.SerializationFormat.Xml:
                ippConfig.Message.Response.SerializationFormat = SerializationFormat.Xml;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.DEFAULT:
            case Intuit.Ipp.Utility.SerializationFormat.Json:
                ippConfig.Message.Response.SerializationFormat = SerializationFormat.Json;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.Custom:
                ippConfig.Message.Response.SerializationFormat = SerializationFormat.Custom;
                break;
            }


            switch (ippConfigurationSection.Retry.Mode)
            {
            case RetryMode.Linear:
                if (!CoreHelper.IsInvalidaLinearRetryMode(
                        ippConfigurationSection.Retry.LinearRetry.RetryCount,
                        ippConfigurationSection.Retry.LinearRetry.RetryInterval))
                {
                    ippConfig.RetryPolicy = new IntuitRetryPolicy(
                        ippConfigurationSection.Retry.LinearRetry.RetryCount,
                        ippConfigurationSection.Retry.LinearRetry.RetryInterval);
                }

                break;

            case RetryMode.Incremental:
                if (!CoreHelper.IsInvalidaIncrementalRetryMode(
                        ippConfigurationSection.Retry.IncrementatlRetry.RetryCount,
                        ippConfigurationSection.Retry.IncrementatlRetry.InitialInterval,
                        ippConfigurationSection.Retry.IncrementatlRetry.Increment))
                {
                    ippConfig.RetryPolicy = new IntuitRetryPolicy(
                        ippConfigurationSection.Retry.IncrementatlRetry.RetryCount,
                        ippConfigurationSection.Retry.IncrementatlRetry.InitialInterval,
                        ippConfigurationSection.Retry.IncrementatlRetry.Increment);
                }

                break;

            case RetryMode.Exponential:
                if (!CoreHelper.IsInvalidaExponentialRetryMode(
                        ippConfigurationSection.Retry.ExponentialRetry.RetryCount,
                        ippConfigurationSection.Retry.ExponentialRetry.MinBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.MaxBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.DeltaBackoff))
                {
                    ippConfig.RetryPolicy = new IntuitRetryPolicy(
                        ippConfigurationSection.Retry.ExponentialRetry.RetryCount,
                        ippConfigurationSection.Retry.ExponentialRetry.MinBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.MaxBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.DeltaBackoff);
                }

                break;
            }

            ippConfig.BaseUrl = new BaseUrl();

            ippConfig.BaseUrl.Qbo = ippConfigurationSection.Service.BaseUrl.Qbo;
            ippConfig.BaseUrl.Ips = ippConfigurationSection.Service.BaseUrl.Ips;
            ippConfig.BaseUrl.OAuthAccessTokenUrl    = ippConfigurationSection.Service.BaseUrl.OAuthAccessTokenUrl;
            ippConfig.BaseUrl.UserNameAuthentication = ippConfigurationSection.Service.BaseUrl.UserNameAuthentication;

            ippConfig.MinorVersion = new MinorVersion();

            ippConfig.MinorVersion.Qbo = ippConfigurationSection.Service.MinorVersion.Qbo;



            ippConfig.VerifierToken       = new VerifierToken();
            ippConfig.VerifierToken.Value = ippConfigurationSection.WebhooksService.WebhooksVerifier.Value;
#endif
#if NETSTANDARD2_0
            //Setting defaults for configurations
            #region defaults
            ippConfig.Logger = new Logger
            {
                CustomLogger = new TraceLogger(),
                RequestLog   = new RequestLog
                {
                    EnableRequestResponseLogging  = false,
                    ServiceRequestLoggingLocation = System.IO.Path.GetTempPath()
                }
            };

            ippConfig.Message = new Message
            {
                Request = new Request
                {
                    CompressionFormat   = CompressionFormat.GZip,
                    SerializationFormat = SerializationFormat.Json
                },
                Response = new Response
                {
                    CompressionFormat   = CompressionFormat.GZip,
                    SerializationFormat = SerializationFormat.Json
                }
            };

            ippConfig.BaseUrl = new BaseUrl
            {
                Qbo = null,
                Ips = null,
                OAuthAccessTokenUrl    = null,
                UserNameAuthentication = null
            };

            ippConfig.MinorVersion = new MinorVersion
            {
                Qbo = null
            };

            ippConfig.VerifierToken = new VerifierToken
            {
                Value = null
            };


            #endregion

            //ippConfig.Logger = new Logger();
            //ippConfig.Logger.RequestLog = new RequestLog();

            //Read all appsettings.json sections
            var loggerSettings                = builder.GetSection("Logger").GetSection("RequestLog");
            var customLoggerSettings          = builder.GetSection("CustomLogger").GetSection("RequestLog");
            var securitySettings              = builder.GetSection("Security").GetSection("Mode");
            var securityOauthSettings         = builder.GetSection("Security").GetSection("Mode").GetSection("OAuth");
            var securityCustomSettings        = builder.GetSection("Security").GetSection("Mode").GetSection("Custom");
            var messageRequestSettings        = builder.GetSection("Message").GetSection("Request");
            var messageResponseSettings       = builder.GetSection("Message").GetSection("Response");
            var retrySettings                 = builder.GetSection("Retry").GetSection("Mode");
            var retrySettingsLinear           = builder.GetSection("Retry").GetSection("Mode").GetSection("LinearRetry");
            var retrySettingsIncremental      = builder.GetSection("Retry").GetSection("Mode").GetSection("IncrementalRetry");
            var retrySettingsExponential      = builder.GetSection("Retry").GetSection("Mode").GetSection("ExponentialRetry");
            var serviceSettings               = builder.GetSection("Service");
            var serviceBaseUrlSettings        = builder.GetSection("Service").GetSection("BaseUrl");
            var serviceMinorversionSettings   = builder.GetSection("Service").GetSection("Minorversion");
            var webhooksVerifierTokenSettings = builder.GetSection("WebhooksService").GetSection("VerifierToken");



            if (!string.IsNullOrEmpty(loggerSettings["LogDirectory"]) && Convert.ToBoolean(loggerSettings["Enablelogs"]) == true)
            {
                ippConfig.Logger.RequestLog.EnableRequestResponseLogging = Convert.ToBoolean(loggerSettings["Enablelogs"]);


                string location = loggerSettings["LogDirectory"];
                if (!Directory.Exists(location))
                {
                    IdsException exception = new IdsException(Properties.Resources.ValidDirectoryPathMessage, new DirectoryNotFoundException());
                    IdsExceptionManager.HandleException(exception);
                }

                ippConfig.Logger.RequestLog.ServiceRequestLoggingLocation = loggerSettings["LogDirectory"];
            }

            if (!string.IsNullOrEmpty(customLoggerSettings["Name"]) && !string.IsNullOrEmpty(customLoggerSettings["Type"]) && Convert.ToBoolean(customLoggerSettings["Enable"]) == true)
            {
                Type customerLoggerType = Type.GetType(customLoggerSettings["Type"]);
                ippConfig.Logger.CustomLogger = Activator.CreateInstance(customerLoggerType) as ILogger;
            }
            else
            {
                ippConfig.Logger.CustomLogger = new TraceLogger();
            }

            if (!string.IsNullOrEmpty(securityOauthSettings["AccessToken"]) && Convert.ToBoolean(securityOauthSettings["Enable"]) == true)
            {
                OAuth2RequestValidator validator = new OAuth2RequestValidator(
                    securityOauthSettings["AccessToken"]);
                ippConfig.Security = validator;
            }
            else if (securityCustomSettings["Enable"] == "true")
            {
                if (!string.IsNullOrEmpty(securityCustomSettings["Name"]) && !string.IsNullOrEmpty(securityCustomSettings["Type"]) && Convert.ToBoolean(securityCustomSettings["Enable"]) == true)
                {
                    Type customSecurityType = Type.GetType(securityCustomSettings["Type"]);
                    if (!string.IsNullOrEmpty(securityCustomSettings["Params"]))
                    {
                        string[] paramateres = securityCustomSettings["Params"].Split(',');
                        ippConfig.Security = Activator.CreateInstance(customSecurityType, paramateres) as IRequestValidator;
                    }
                }
            }

            ippConfig.Message          = new Message();
            ippConfig.Message.Request  = new Request();
            ippConfig.Message.Response = new Response();

            if (!string.IsNullOrEmpty(messageRequestSettings["CompressionFormat"]))
            {
                switch (Enum.Parse(typeof(Utility.CompressionFormat), messageRequestSettings["CompressionFormat"]))
                {
                case Intuit.Ipp.Utility.CompressionFormat.None:
                    ippConfig.Message.Request.CompressionFormat = CompressionFormat.None;
                    break;

                case Intuit.Ipp.Utility.CompressionFormat.DEFAULT:
                case Intuit.Ipp.Utility.CompressionFormat.GZip:
                    ippConfig.Message.Request.CompressionFormat = CompressionFormat.GZip;
                    break;

                case Intuit.Ipp.Utility.CompressionFormat.Deflate:
                    ippConfig.Message.Request.CompressionFormat = CompressionFormat.Deflate;
                    break;

                default:
                    break;
                }
            }


            if (!string.IsNullOrEmpty(messageResponseSettings["CompressionFormat"]))
            {
                switch (Enum.Parse(typeof(Utility.CompressionFormat), messageResponseSettings["CompressionFormat"]))
                {
                case Intuit.Ipp.Utility.CompressionFormat.None:
                    ippConfig.Message.Response.CompressionFormat = CompressionFormat.None;
                    break;

                case Intuit.Ipp.Utility.CompressionFormat.DEFAULT:
                case Intuit.Ipp.Utility.CompressionFormat.GZip:
                    ippConfig.Message.Response.CompressionFormat = CompressionFormat.GZip;
                    break;

                case Intuit.Ipp.Utility.CompressionFormat.Deflate:
                    ippConfig.Message.Response.CompressionFormat = CompressionFormat.Deflate;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(messageRequestSettings["SerializationFormat"]))
            {
                switch (Enum.Parse(typeof(Utility.SerializationFormat), messageRequestSettings["SerializationFormat"]))
                {
                case Intuit.Ipp.Utility.SerializationFormat.DEFAULT:
                case Intuit.Ipp.Utility.SerializationFormat.Xml:
                    ippConfig.Message.Request.SerializationFormat = SerializationFormat.Xml;
                    break;

                case Intuit.Ipp.Utility.SerializationFormat.Json:
                    ippConfig.Message.Request.SerializationFormat = SerializationFormat.Json;
                    break;

                case Intuit.Ipp.Utility.SerializationFormat.Custom:
                    ippConfig.Message.Request.SerializationFormat = SerializationFormat.Custom;
                    break;
                }
            }


            if (!string.IsNullOrEmpty(messageResponseSettings["SerializationFormat"]))
            {
                switch (Enum.Parse(typeof(Utility.SerializationFormat), messageResponseSettings["SerializationFormat"]))
                {
                case Intuit.Ipp.Utility.SerializationFormat.Xml:
                    ippConfig.Message.Response.SerializationFormat = SerializationFormat.Xml;
                    break;

                case Intuit.Ipp.Utility.SerializationFormat.DEFAULT:
                case Intuit.Ipp.Utility.SerializationFormat.Json:
                    ippConfig.Message.Response.SerializationFormat = SerializationFormat.Json;
                    break;

                case Intuit.Ipp.Utility.SerializationFormat.Custom:
                    ippConfig.Message.Response.SerializationFormat = SerializationFormat.Custom;
                    break;
                }
            }


            if ((!string.IsNullOrEmpty(retrySettingsLinear["Enable"])) && Convert.ToBoolean(retrySettingsLinear["Enable"]) == true)
            {
                if (!string.IsNullOrEmpty(retrySettingsLinear["RetryCount"]) && !string.IsNullOrEmpty(retrySettingsLinear["RetryInterval"]))
                {
                    if (!CoreHelper.IsInvalidaLinearRetryMode(
                            Convert.ToInt32(retrySettingsLinear["RetryCount"]),
                            TimeSpan.Parse(retrySettingsLinear["RetryInterval"])))
                    {
                        ippConfig.RetryPolicy = new IntuitRetryPolicy(
                            Convert.ToInt32(retrySettingsLinear["RetryCount"]),
                            TimeSpan.Parse(retrySettingsLinear["RetryInterval"]));
                    }
                }
            }
            else if ((!string.IsNullOrEmpty(retrySettingsIncremental["Enable"])) && Convert.ToBoolean(retrySettingsIncremental["Enable"]) == true)
            {
                if (!string.IsNullOrEmpty(retrySettingsLinear["RetryCount"]) && !string.IsNullOrEmpty(retrySettingsLinear["InitialInterval"]) && !string.IsNullOrEmpty(retrySettingsLinear["Increment"]))
                {
                    if (!CoreHelper.IsInvalidaIncrementalRetryMode(
                            Convert.ToInt32(retrySettingsIncremental["RetryCount"]),
                            TimeSpan.Parse(retrySettingsIncremental["InitialInterval"]),
                            TimeSpan.Parse(retrySettingsIncremental["Increment"])))
                    {
                        ippConfig.RetryPolicy = new IntuitRetryPolicy(
                            Convert.ToInt32(retrySettingsIncremental["RetryCount"]),
                            TimeSpan.Parse(retrySettingsIncremental["InitialInterval"]),
                            TimeSpan.Parse(retrySettingsIncremental["Increment"]));
                    }
                }
            }
            else if ((!string.IsNullOrEmpty(retrySettingsExponential["Enable"])) && Convert.ToBoolean(retrySettingsExponential["Enable"]) == true)
            {
                if (!string.IsNullOrEmpty(retrySettingsLinear["RetryCount"]) && !string.IsNullOrEmpty(retrySettingsLinear["MinBackoff"]) && !string.IsNullOrEmpty(retrySettingsLinear["MaxBackoff"]) && !string.IsNullOrEmpty(retrySettingsLinear["DeltaBackoff"]))
                {
                    if (!CoreHelper.IsInvalidaExponentialRetryMode(
                            Convert.ToInt32(retrySettingsExponential["RetryCount"]),
                            TimeSpan.Parse(retrySettingsExponential["MinBackoff"]),
                            TimeSpan.Parse(retrySettingsExponential["MaxBackoff"]),
                            TimeSpan.Parse(retrySettingsExponential["DeltaBackoff"])))
                    {
                        ippConfig.RetryPolicy = new IntuitRetryPolicy(
                            Convert.ToInt32(retrySettingsExponential["RetryCount"]),
                            TimeSpan.Parse(retrySettingsExponential["MinBackoff"]),
                            TimeSpan.Parse(retrySettingsExponential["MaxBackoff"]),
                            TimeSpan.Parse(retrySettingsExponential["DeltaBackoff"]));
                    }
                }
            }


            //ippConfig.BaseUrl = new BaseUrl();

            ippConfig.BaseUrl.Qbo = serviceBaseUrlSettings["Qbo"];
            ippConfig.BaseUrl.Ips = serviceBaseUrlSettings["Ips"];
            ippConfig.BaseUrl.OAuthAccessTokenUrl    = serviceBaseUrlSettings["OAuthAccessTokenUrl"];
            ippConfig.BaseUrl.UserNameAuthentication = serviceBaseUrlSettings["UserNameAuthentication"];

            //ippConfig.MinorVersion = new MinorVersion();

            ippConfig.MinorVersion.Qbo = serviceMinorversionSettings["Qbo"];



            //ippConfig.VerifierToken = new VerifierToken();
            ippConfig.VerifierToken.Value = webhooksVerifierTokenSettings["Value"];
#endif
            //#if NETSTANDARD2_0
            //            //IppConfiguration ippConfig = new IppConfiguration();
            //            string temppath = Path.Combine(this.logPath, "Request-" + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture) + ".txt");
            //            ippConfig.Logger = new Logger
            //            {

            //                RequestLog = new RequestLog
            //                {
            //                    EnableRequestResponseLogging = true,//test
            //                    ServiceRequestLoggingLocation = temppath
            //                }
            //            };


            //#endif

            return(ippConfig);
        }
        /// <summary>
        /// Reads the configuration from the config file and converts it to custom
        /// config objects which the end developer will use to get or set the properties.
        /// </summary>
        /// <returns>The custom config object.</returns>
        public IppConfiguration ReadConfiguration()
        {
            IppConfigurationSection ippConfigurationSection = IppConfigurationSection.Instance;
            IppConfiguration        ippConfig = new IppConfiguration();

            if (ippConfigurationSection == null)
            {
                ippConfig.Logger = new Logger
                {
                    CustomLogger = new TraceLogger(),
                    RequestLog   = new RequestLog
                    {
                        EnableRequestResponseLogging  = false,
                        ServiceRequestLoggingLocation = System.IO.Path.GetTempPath()
                    }
                };

                ippConfig.Message = new Message
                {
                    Request = new Request
                    {
                        CompressionFormat   = CompressionFormat.GZip,
                        SerializationFormat = SerializationFormat.Xml
                    },
                    Response = new Response
                    {
                        CompressionFormat   = CompressionFormat.GZip,
                        SerializationFormat = SerializationFormat.Json
                    }
                };

                ippConfig.BaseUrl = new BaseUrl
                {
                    Qbo = null,
                    Ips = null,
                    OAuthAccessTokenUrl    = null,
                    UserNameAuthentication = null
                };

                ippConfig.MinorVersion = new MinorVersion
                {
                    Qbo = null
                };

                ippConfig.VerifierToken = new VerifierToken
                {
                    Value = null
                };

                return(ippConfig);
            }

            ippConfig.Logger            = new Logger();
            ippConfig.Logger.RequestLog = new RequestLog();
            ippConfig.Logger.RequestLog.EnableRequestResponseLogging = ippConfigurationSection.Logger.RequestLog.EnableRequestResponseLogging;
            if (string.IsNullOrEmpty(ippConfigurationSection.Logger.RequestLog.RequestResponseLoggingDirectory))
            {
                ippConfig.Logger.RequestLog.ServiceRequestLoggingLocation = Path.GetTempPath();
            }
            else
            {
                string location = ippConfigurationSection.Logger.RequestLog.RequestResponseLoggingDirectory;
                if (!Directory.Exists(location))
                {
                    IdsException exception = new IdsException(Properties.Resources.ValidDirectoryPathMessage, new DirectoryNotFoundException());
                    IdsExceptionManager.HandleException(exception);
                }

                ippConfig.Logger.RequestLog.ServiceRequestLoggingLocation = ippConfigurationSection.Logger.RequestLog.RequestResponseLoggingDirectory;
            }

            if (!string.IsNullOrEmpty(ippConfigurationSection.Logger.CustomLogger.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Logger.CustomLogger.Type) && ippConfigurationSection.Logger.CustomLogger.Enable)
            {
                Type customerLoggerType = Type.GetType(ippConfigurationSection.Logger.CustomLogger.Type);
                ippConfig.Logger.CustomLogger = Activator.CreateInstance(customerLoggerType) as ILogger;
            }
            else
            {
                ippConfig.Logger.CustomLogger = new TraceLogger();
            }

            switch (ippConfigurationSection.Security.Mode)
            {
            case SecurityMode.OAuth:
                OAuthRequestValidator validator = new OAuthRequestValidator(
                    ippConfigurationSection.Security.OAuth.AccessToken,
                    ippConfigurationSection.Security.OAuth.AccessTokenSecret,
                    ippConfigurationSection.Security.OAuth.ConsumerKey,
                    ippConfigurationSection.Security.OAuth.ConsumerSecret);
                ippConfig.Security = validator;
                break;

            case SecurityMode.Custom:
                if (!string.IsNullOrEmpty(ippConfigurationSection.Security.CustomSecurity.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Security.CustomSecurity.Type) && ippConfigurationSection.Security.CustomSecurity.Enable)
                {
                    Type     customSecurityType = Type.GetType(ippConfigurationSection.Security.CustomSecurity.Type);
                    string[] paramateres        = ippConfigurationSection.Security.CustomSecurity.Params.Split(',');
                    ippConfig.Security = Activator.CreateInstance(customSecurityType, paramateres) as IRequestValidator;
                }

                break;
            }

            //// TODO : This will not be used now.
            ////if (!string.IsNullOrEmpty(ippConfigurationSection.Message.CustomSerializer.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Message.CustomSerializer.Type) && ippConfigurationSection.Message.CustomSerializer.Enable)
            ////{
            ////    Type customSerializerType = Type.GetType(ippConfigurationSection.Message.CustomSerializer.Type);
            ////    IEntitySerializer entitySerializer = Activator.CreateInstance(customSerializerType) as IEntitySerializer;
            ////    if (ippConfigurationSection.Message.Request.SerializationFormat == SerializationFormat.Custom)
            ////    {
            ////        ippConfig.Message.Request.Serializer = entitySerializer;
            ////    }

            ////    if (ippConfigurationSection.Message.Response.SerializationFormat == SerializationFormat.Custom)
            ////    {

            ////        ippConfig.Message.Response.Serializer = entitySerializer;
            ////    }
            ////}

            ippConfig.Message          = new Message();
            ippConfig.Message.Request  = new Request();
            ippConfig.Message.Response = new Response();

            switch (ippConfigurationSection.Message.Request.CompressionFormat)
            {
            case Intuit.Ipp.Utility.CompressionFormat.None:
                ippConfig.Message.Request.CompressionFormat = CompressionFormat.None;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.DEFAULT:
            case Intuit.Ipp.Utility.CompressionFormat.GZip:
                ippConfig.Message.Request.CompressionFormat = CompressionFormat.GZip;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.Deflate:
                ippConfig.Message.Request.CompressionFormat = CompressionFormat.Deflate;
                break;

            default:
                break;
            }



            switch (ippConfigurationSection.Message.Response.CompressionFormat)
            {
            case Intuit.Ipp.Utility.CompressionFormat.None:
                ippConfig.Message.Response.CompressionFormat = CompressionFormat.None;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.DEFAULT:
            case Intuit.Ipp.Utility.CompressionFormat.GZip:
                ippConfig.Message.Response.CompressionFormat = CompressionFormat.GZip;
                break;

            case Intuit.Ipp.Utility.CompressionFormat.Deflate:
                ippConfig.Message.Response.CompressionFormat = CompressionFormat.Deflate;
                break;
            }

            switch (ippConfigurationSection.Message.Request.SerializationFormat)
            {
            case Intuit.Ipp.Utility.SerializationFormat.DEFAULT:
            case Intuit.Ipp.Utility.SerializationFormat.Xml:
                ippConfig.Message.Request.SerializationFormat = SerializationFormat.Xml;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.Json:
                ippConfig.Message.Request.SerializationFormat = SerializationFormat.Json;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.Custom:
                ippConfig.Message.Request.SerializationFormat = SerializationFormat.Custom;
                break;
            }

            switch (ippConfigurationSection.Message.Response.SerializationFormat)
            {
            case Intuit.Ipp.Utility.SerializationFormat.Xml:
                ippConfig.Message.Response.SerializationFormat = SerializationFormat.Xml;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.DEFAULT:
            case Intuit.Ipp.Utility.SerializationFormat.Json:
                ippConfig.Message.Response.SerializationFormat = SerializationFormat.Json;
                break;

            case Intuit.Ipp.Utility.SerializationFormat.Custom:
                ippConfig.Message.Response.SerializationFormat = SerializationFormat.Custom;
                break;
            }

            switch (ippConfigurationSection.Retry.Mode)
            {
            case RetryMode.Linear:
                if (!CoreHelper.IsInvalidaLinearRetryMode(
                        ippConfigurationSection.Retry.LinearRetry.RetryCount,
                        ippConfigurationSection.Retry.LinearRetry.RetryInterval))
                {
                    ippConfig.RetryPolicy = new IntuitRetryPolicy(
                        ippConfigurationSection.Retry.LinearRetry.RetryCount,
                        ippConfigurationSection.Retry.LinearRetry.RetryInterval);
                }

                break;

            case RetryMode.Incremental:
                if (!CoreHelper.IsInvalidaIncrementalRetryMode(
                        ippConfigurationSection.Retry.IncrementatlRetry.RetryCount,
                        ippConfigurationSection.Retry.IncrementatlRetry.InitialInterval,
                        ippConfigurationSection.Retry.IncrementatlRetry.Increment))
                {
                    ippConfig.RetryPolicy = new IntuitRetryPolicy(
                        ippConfigurationSection.Retry.IncrementatlRetry.RetryCount,
                        ippConfigurationSection.Retry.IncrementatlRetry.InitialInterval,
                        ippConfigurationSection.Retry.IncrementatlRetry.Increment);
                }

                break;

            case RetryMode.Exponential:
                if (!CoreHelper.IsInvalidaExponentialRetryMode(
                        ippConfigurationSection.Retry.ExponentialRetry.RetryCount,
                        ippConfigurationSection.Retry.ExponentialRetry.MinBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.MaxBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.DeltaBackoff))
                {
                    ippConfig.RetryPolicy = new IntuitRetryPolicy(
                        ippConfigurationSection.Retry.ExponentialRetry.RetryCount,
                        ippConfigurationSection.Retry.ExponentialRetry.MinBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.MaxBackoff,
                        ippConfigurationSection.Retry.ExponentialRetry.DeltaBackoff);
                }

                break;
            }

            ippConfig.BaseUrl = new BaseUrl();

            ippConfig.BaseUrl.Qbo = ippConfigurationSection.Service.BaseUrl.Qbo;
            ippConfig.BaseUrl.Ips = ippConfigurationSection.Service.BaseUrl.Ips;
            ippConfig.BaseUrl.OAuthAccessTokenUrl    = ippConfigurationSection.Service.BaseUrl.OAuthAccessTokenUrl;
            ippConfig.BaseUrl.UserNameAuthentication = ippConfigurationSection.Service.BaseUrl.UserNameAuthentication;

            ippConfig.MinorVersion = new MinorVersion();

            ippConfig.MinorVersion.Qbo = ippConfigurationSection.Service.MinorVersion.Qbo;



            ippConfig.VerifierToken       = new VerifierToken();
            ippConfig.VerifierToken.Value = ippConfigurationSection.WebhooksService.WebhooksVerifier.Value;



            return(ippConfig);
        }
        public void IppConfigurationSectionConstructorTest()
        {
            IppConfigurationSection target = new IppConfigurationSection();

            Assert.IsNotNull(target);
        }