public static ApiConfiguration ToApiConfiguration(UpdateConfigurationRequest updateConfigurationRequest)
        {
            var config = new ApiConfiguration
                             {
                                 ChaosInterval = new TimeSpan(0, 0, updateConfigurationRequest.ChaosInterval),
                                 ConfigurationRotationInterval = new TimeSpan(0, 0, updateConfigurationRequest.ConfigurationRotationInterval),
                                 Enabled = updateConfigurationRequest.Enabled
                             };

            foreach (var updateChaosSettings in updateConfigurationRequest.ChaosSettings)
            {
                var chaosConfiguration = new ChaosSettings
                                             {
                                                 Name = updateChaosSettings.Name,
                                                 MaxResponseDelayTime = updateChaosSettings.MaxResponseDelayTime,
                                                 MinResponseDelayTime = updateChaosSettings.MinResponseDelayTime,
                                                 PercentageOfChaos = updateChaosSettings.PercentageOfChaos,
                                                 PercentageOfSlowResponses = updateChaosSettings.PercentageOfSlowResponses,
                                                 ResponseTypeMediaType = updateChaosSettings.ResponseTypeMediaType
                                             };

                if (updateChaosSettings.IgnoreUrls != null)
                {
                    foreach (var url in updateChaosSettings.IgnoreUrls)
                    {
                        chaosConfiguration.IgnoreUrlPattern.Add(url.Pattern);
                    }                    
                }
                
                foreach (var updateResponse in updateChaosSettings.HttpResponses)
                {
                    var httpResponse = new ResponseDetails { StatusCode = updateResponse.StatusCode };

                    foreach (var payload in updateResponse.Payloads.Select(chaosResponsePayload => new ChaosResponsePayload { Code = chaosResponsePayload.Code, Content = chaosResponsePayload.Content }))
                    {
                        httpResponse.Payloads.Add(payload);
                    }

                    chaosConfiguration.HttpResponses.Add(httpResponse);
                }

                config.ChaosSettings.Add(chaosConfiguration);
            }

            return config;
        }
예제 #2
0
        public ApiConfiguration(ChaosConfigurationSection chaosConfigurationSection)
        {
            if (chaosConfigurationSection == null)
            {
                throw new ArgumentNullException("chaosConfigurationSection");
            }

            Enabled = chaosConfigurationSection.GlobalSettings.Enabled;
            ChaosInterval = new TimeSpan(0, 0, chaosConfigurationSection.GlobalSettings.ChaosIntervalSeconds);
            ConfigurationRotationInterval = new TimeSpan(0, 0, chaosConfigurationSection.GlobalSettings.RotationIntervalSeconds);

            foreach (ChaosConfiguration chaosConfiguration in chaosConfigurationSection.ChaosConfigurations)
            {
                var settings = new ChaosSettings
                                   {
                                       Name = chaosConfiguration.Name,
                                       MinResponseDelayTime = chaosConfiguration.MinResponseDelayTime,
                                       MaxResponseDelayTime = chaosConfiguration.MaxResponseDelayTime,
                                       PercentageOfSlowResponses = chaosConfiguration.PercentageOfSlowResponses,
                                       PercentageOfChaos = chaosConfiguration.PercentageOfChaos,
                                       ResponseTypeMediaType = chaosConfiguration.ResponsePayloadMediaType
                                   };

                foreach (Response httpResponse in chaosConfiguration.HttpResponses)
                {
                    var responseDetails = new ResponseDetails { StatusCode = httpResponse.StatusCode };
                    if (httpResponse.Payloads.Count > 0)
                    {
                        foreach (ResponsePayload payload in httpResponse.Payloads)
                        {
                            responseDetails.Payloads.Add(new ChaosResponsePayload { Content = payload.Content, Code = payload.Code });
                        }
                    }

                    settings.HttpResponses.Add(responseDetails);
                }

                ChaosSettings.Add(settings);
            }
        }
예제 #3
0
 public void Given_I_Have_Created_Settings_From_The_Application_Configuration_File()
 {
     configuration = new ApiConfiguration(ChaosConfigurationSection.Instance);
     settings = configuration.ChaosSettings.FirstOrDefault();
 }
 public void Setup()
 {
     chaosSettings = new ChaosSettings();
 }