Example #1
0
        public Test SetUpSimulatedUsers()
        {
            SimulatedUserSetup setup = new SimulatedUserSetup();

            ApiConnectionFactory.SetConnectionLimit(Configuration, TestResources.SwaggerDocument);
            SimulatedUserList = setup.PopulateUserList(Configuration, ApiConnectionFactory);

            if (!setup.bSuccessful)
            {
                ErrorHandler.InitialisationError(ErrorLevel.Fatal,
                                                 InitialiserErrorType.SimulatedUserSetup,
                                                 setup.Errors);
            }

            return(this);
        }
Example #2
0
        public SwaggerDocument FetchSwaggerDocument(ApiConnectionFactory factory, string swaggerDocName)
        {
            SwaggerDocument swaggerDoc = new SwaggerDocument();

            using (var connection = factory.NewConnection())
            {
                HttpResponseMessage response = connection.GetAsync(swaggerDocName).Result;
                if (response.IsSuccessStatusCode)
                {
                    try
                    {
                        swaggerDoc = JsonConvert.DeserializeObject <SwaggerDocument>(response.Content.ReadAsStringAsync().Result);
                    }
                    catch (Exception ex)
                    {
                        Errors.Add(new SetupError
                        {
                            Severity = ErrorLevel.Fatal,
                            Type     = InitialiserErrorType.SwaggerDocumentSetup,
                            Message  =
                                InitialiserErrorMessages.Swagger_ParseError
                                .Replace("[[Name]]", swaggerDocName)
                                .Replace("[[Message]]", ex.Message)
                        });
                    }
                }

                else
                {
                    Errors.Add(new SetupError
                    {
                        Severity = ErrorLevel.Fatal,
                        Type     = InitialiserErrorType.SwaggerDocumentSetup,
                        Message  =
                            InitialiserErrorMessages.Swagger_FetchError
                            .Replace("[[Name]]", swaggerDocName)
                            .Replace("[[StatusCode]]", ((int)response.StatusCode).ToString())
                            .Replace("[[StatusMessage]]", response.StatusCode.ToString())
                    });
                }
            }

            return(swaggerDoc);
        }
Example #3
0
        public IList <SimulatedUser> PopulateUserList(TestConfig config, ApiConnectionFactory factory)
        {
            IList <SimulatedUser> list = new List <SimulatedUser>();

            for (int i = 0; i < config.SimulatedUsers; ++i)
            {
                list.Add(
                    new SimulatedUser
                {
                    TargetAPI            = factory.NewConnection(),
                    bSaveResponses       = true,
                    bSavePerformanceData = true,
                    bAsyncUser           = config.UseAsyncUsers,
                    UserID = i + 1,
                    NumberOfConcurrentUsers = config.SimulatedUsers
                });
            }

            return(list);
        }
Example #4
0
        public Dictionary <string, string> GenerateAuthDictionary(TestConfig config, ApiConnectionFactory api)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            if (config.Auths.Any())
            {
                foreach (Auth authItem in config.Auths)
                {
                    AuthLogin           login = new AuthLogin(authItem.Username, authItem.Password);
                    var                 authRequestContent = new StringContent(JsonConvert.SerializeObject(login), Encoding.UTF8, "application/json");
                    HttpResponseMessage response           = api.NewConnection().PostAsync(authItem.LoginEndpoint, authRequestContent).Result;

                    JObject authJson = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                    string  token    = authJson["access_token"].Value <string>();

                    foreach (string endpoint in authItem.TargetEndpoints)
                    {
                        dict.Add(SanitiseRegex(endpoint), token);
                    }
                }
            }

            return(dict);
        }