Пример #1
0
        public static async Task Run([TimerTrigger("%" + Constants.Configurations.ScheduleExpression + "%", RunOnStartup = true)] TimerInfo timer, ILogger log)
        {
            log.LogInformation($"Emulator function triggered at: {DateTime.Now}");

            var context = new EmulationContext();

            // Generate random flow of steps, weighted and sorted by priority
            var max   = EmulationSteps.Value.Max(s => s.Priority) + 1;
            var steps = Faker.Value.Random.ListItems(EmulationSteps.Value.SelectMany(s => Enumerable.Repeat(s, max - s.Priority)).ToList())
                        .OrderBy(s => s.Priority)
                        .GroupBy(s => s.Id)
                        .Select(g => g.First());

            foreach (var step in steps)
            {
                try
                {
                    context = await step.Method(context);
                }
                catch (Exception e)
                {
                    log.LogWarning(e, "Emulator function step failed");
                }

                await Task.Delay(Faker.Value.Random.Int(0, 1000) *DateTimeOffset.UtcNow.Minute);
            }
        }
Пример #2
0
        private async Task <EmulationContext> GetUserProfile(EmulationContext ec)
        {
            await Configurations.ServiceFuncUrl
            .AppendPathSegment("user")
            .SetQueryParams(new { code = Configurations.ServiceFuncKey })
            .GetStringAsync();

            return(ec);
        }
Пример #3
0
        private async Task <EmulationContext> CalculatePrimeNumber(EmulationContext ec)
        {
            var number = _faker.Value.Random.Int(100000);

            await Configurations.ServiceFuncUrl
            .AppendPathSegment("search")
            .SetQueryParams(new { code = Configurations.ServiceFuncKey })
            .PostJsonAsync(number);

            return(ec);
        }
Пример #4
0
        private async Task <EmulationContext> SearchRequest(EmulationContext ec)
        {
            var term = _faker.Value.Lorem.Word();

            await Configurations.ServiceFuncUrl
            .AppendPathSegment("search")
            .SetQueryParams(new { code = Configurations.ServiceFuncKey })
            .PostJsonAsync(term);

            return(ec);
        }
Пример #5
0
        private async Task <EmulationContext> DeleteProject(EmulationContext ec)
        {
            var key = _faker.Value.PickRandom(ec.Entities.OfType <Project>().Select(p => p.RowKey).DefaultIfEmpty(EntityBase.NewRowKey));

            var result = await Configurations.ServiceFuncUrl
                         .AppendPathSegment("projects")
                         .AppendPathSegment($"{key}")
                         .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                         .DeleteAsync();

            return(ec);
        }
Пример #6
0
        private async Task <EmulationContext> GetAllPersons(EmulationContext ec)
        {
            var result = await Configurations.ServiceFuncUrl
                         .AppendPathSegment("persons")
                         .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                         .GetAsync()
                         .ReceiveJson <ICollection <Person> >();

            if (result?.Any() == true)
            {
                ec.Entities.AddRange(result);
            }

            return(ec);
        }
Пример #7
0
        private async Task <EmulationContext> UpdatePerson(EmulationContext ec)
        {
            var persons = ec.Entities.OfType <Person>();

            if (!persons.Any())
            {
                return(ec);
            }

            var generated = _faker.Value.Entities.Person.Generate();
            var person    = _faker.Value.PickRandom(persons);

            // Load all data to person
            person = await Configurations.ServiceFuncUrl
                     .AppendPathSegment("persons")
                     .AppendPathSegment($"{person.RowKey}")
                     .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                     .GetAsync()
                     .ReceiveJson <Person>();

            // Manipulate data
            person.RowKey        = _faker.Value.Random.Bool(0.1f) ? generated.RowKey : person.RowKey;
            person.Firstname     = _faker.Value.Random.Bool(0.3f) ? generated.Firstname : person.Firstname;
            person.Lastname      = _faker.Value.Random.Bool(0.3f) ? generated.Lastname : person.Lastname;
            person.JobTitle      = _faker.Value.Random.Bool(0.6f) ? generated.JobTitle : person.JobTitle;
            person.Slogan        = _faker.Value.Random.Bool(0.5f) ? generated.Slogan : person.Slogan;
            person.EmployedSince = _faker.Value.Random.Bool(0.3f) ? generated.EmployedSince : person.EmployedSince;
            person.Status        = _faker.Value.Random.Bool(0.3f) ? generated.Status : person.Status;

            _faker.Value.Entities.PopulatePersonSkills(_faker.Value, person, ec.Entities.OfType <Technology>());
            _faker.Value.Entities.PopulatePersonProjects(_faker.Value, person, ec.Entities.OfType <Project>());

            // Store person
            var result = await Configurations.ServiceFuncUrl
                         .AppendPathSegment("persons")
                         .AppendPathSegment($"{person.RowKey}")
                         .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                         .PutJsonAsync(person)
                         .ReceiveJson <Person>();

            if (result != null)
            {
                ec.Entities.Add(result);
            }

            return(ec);
        }
Пример #8
0
        private async Task <EmulationContext> UpdateProject(EmulationContext ec)
        {
            var projects = ec.Entities.OfType <Project>();

            if (!projects.Any())
            {
                return(ec);
            }

            var generated = _faker.Value.Entities.Project.Generate();
            var project   = _faker.Value.PickRandom(projects);

            // Load all data to entity
            project = await Configurations.ServiceFuncUrl
                      .AppendPathSegment("projects")
                      .AppendPathSegment($"{project.RowKey}")
                      .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                      .GetAsync()
                      .ReceiveJson <Project>();

            // Manipulate data
            project.RowKey       = _faker.Value.Random.Bool(0.1f) ? generated.RowKey : project.RowKey;
            project.CustomerName = _faker.Value.Random.Bool(0.3f) ? generated.CustomerName : project.CustomerName;
            project.ProjectName  = _faker.Value.Random.Bool(0.3f) ? generated.ProjectName : project.ProjectName;
            project.Description  = _faker.Value.Random.Bool(0.6f) ? generated.Description : project.Description;
            project.ProjectUrl   = _faker.Value.Random.Bool(0.3f) ? generated.ProjectUrl : project.ProjectUrl;
            project.IconUrl      = _faker.Value.Random.Bool(0.3f) ? generated.IconUrl : project.IconUrl;
            project.Status       = _faker.Value.Random.Bool(0.3f) ? generated.Status : project.Status;

            _faker.Value.Entities.PopulateProjectTechnologies(_faker.Value, project, ec.Entities.OfType <Technology>());

            // Store entity
            var result = await Configurations.ServiceFuncUrl
                         .AppendPathSegment("projects")
                         .AppendPathSegment($"{project.RowKey}")
                         .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                         .PutJsonAsync(project)
                         .ReceiveJson <Project>();

            if (result != null)
            {
                ec.Entities.Add(result);
            }

            return(ec);
        }
Пример #9
0
        private async Task <EmulationContext> CreateProject(EmulationContext ec)
        {
            var project = _faker.Value.Entities.Project.Generate();

            _faker.Value.Entities.PopulateProjectTechnologies(_faker.Value, project, ec.Entities.OfType <Technology>());

            var result = await Configurations.ServiceFuncUrl
                         .AppendPathSegment("projects")
                         .SetQueryParams(new { code = Configurations.ServiceFuncKey })
                         .PostJsonAsync(project)
                         .ReceiveJson <Project>();

            if (result != null)
            {
                ec.Entities.Add(result);
            }

            return(ec);
        }