Exemple #1
0
        public static void Register(HttpConfiguration config)
        {
            if (ChaosConfigurationSection.Instance == null || ChaosConfigurationSection.Instance.GlobalSettings == null)
            {
                throw new InvalidOperationException("No chaos configuration settings could be found, please check your application configuration file");
            }

            var configuration = new ApiConfiguration(ChaosConfigurationSection.Instance);
            Register(config, configuration);
        }
        public async Task CreateOrUpdateAsync(ApiHostForwardingSettings forwardSettings, string apiKey, ApiConfiguration configuration)
        {
            var settings = new ChaosApiSettingsTableEntity
                               {
                                   PartitionKey = forwardSettings.ForwardApiHostName,
                                   RowKey = forwardSettings.ApiKey,
                                   Configuration = JsonConvert.SerializeObject(configuration)
                               };

            var insertOrReplaceOperation = TableOperation.InsertOrReplace(settings);

            await Table.ExecuteAsync(insertOrReplaceOperation);
        }
        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;
        }
 public void Given_I_Have_Created_Settings_From_The_Application_Configuration_File()
 {
     configuration = new ApiConfiguration(ChaosConfigurationSection.Instance);
     settings = configuration.ChaosSettings.FirstOrDefault();
 }
 public void Init()
 {
     apiConfiguration = new ApiConfiguration();
 }