Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private async Task <EmulationContext> GetUserProfile(EmulationContext ec)
        {
            var result = await Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("user")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .GetStringAsync();

            return(ec);
        }
Exemplo n.º 3
0
        private async Task <EmulationContext> CalculatePrimeNumber(EmulationContext ec)
        {
            var number = _faker.Value.Random.Int(100000);

            var result = await Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("search")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .PostJsonAsync(number);

            return(ec);
        }
Exemplo n.º 4
0
        private async Task <EmulationContext> SearchRequest(EmulationContext ec)
        {
            var term = _faker.Value.Lorem.Word();

            var result = await Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("search")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .PostJsonAsync(term);

            return(ec);
        }
Exemplo n.º 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 Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("projects")
                         .AppendPathSegment($"{key}")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .DeleteAsync();

            return(ec);
        }
Exemplo n.º 6
0
        private async Task <EmulationContext> GetAllPersons(EmulationContext ec)
        {
            var result = await Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("persons")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .GetAsync()
                         .ReceiveJson <ICollection <Person> >();

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

            return(ec);
        }
Exemplo n.º 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 Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                     .AppendPathSegment("persons")
                     .AppendPathSegment($"{person.RowKey}")
                     .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                     .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 Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("persons")
                         .AppendPathSegment($"{person.RowKey}")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .PutJsonAsync(person)
                         .ReceiveJson <Person>();

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

            return(ec);
        }
Exemplo n.º 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 Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                      .AppendPathSegment("projects")
                      .AppendPathSegment($"{project.RowKey}")
                      .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                      .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 Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("projects")
                         .AppendPathSegment($"{project.RowKey}")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .PutJsonAsync(project)
                         .ReceiveJson <Project>();

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

            return(ec);
        }
Exemplo n.º 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 Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncUrl)
                         .AppendPathSegment("projects")
                         .SetQueryParams(new { code = Environment.GetEnvironmentVariable(Constants.Configurations.ServiceFuncKeyEmulator) })
                         .PostJsonAsync(project)
                         .ReceiveJson <Project>();

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

            return(ec);
        }