Exemple #1
0
        public static void EnsureSeedData(this WebSuiteContext context)
        {
            context.RemoveRange(context.Agents);
            context.SaveChanges();

            List <Agent> agents = new List <Agent>();
            Agent        amazon = new Agent();

            amazon.Id        = Guid.NewGuid();
            amazon.City      = "Seattle";
            amazon.Country   = "USA";
            amazon.Latitude  = 123.345;
            amazon.Longitude = 135.543;

            Agent rackspace = new Agent();

            rackspace.Id        = Guid.NewGuid();
            rackspace.City      = "Frankfurt";
            rackspace.Country   = "Germany";
            rackspace.Latitude  = -123.654;
            rackspace.Longitude = 121.321;

            Agent azure = new Agent();

            azure.Id        = Guid.NewGuid();
            azure.City      = "Tokyo";
            azure.Country   = "Japan";
            azure.Latitude  = 23.45;
            azure.Longitude = 12.343;

            agents.Add(amazon);
            agents.Add(rackspace);
            agents.Add(azure);
            context.Agents.AddRange(agents);

            context.RemoveRange(context.Customers);
            context.SaveChanges();

            List <Customer> customers    = new List <Customer>();
            Customer        niceCustomer = new Customer();

            niceCustomer.Id          = Guid.NewGuid();
            niceCustomer.Address     = "New York";
            niceCustomer.MainContact = "Elvis Presley";
            niceCustomer.Name        = "Nice customer";

            Customer greatCustomer = new Customer();

            greatCustomer.Id          = Guid.NewGuid();
            greatCustomer.Address     = "London";
            greatCustomer.MainContact = "Phil Collins";
            greatCustomer.Name        = "Great customer";

            Customer okCustomer = new Customer();

            okCustomer.Id          = Guid.NewGuid();
            okCustomer.Address     = "Berlin";
            okCustomer.MainContact = "Freddie Mercury";
            okCustomer.Name        = "OK Customer";

            customers.Add(niceCustomer);
            customers.Add(greatCustomer);
            customers.Add(okCustomer);
            context.Customers.AddRange(customers);

            context.RemoveRange(context.Engineers);
            context.SaveChanges();

            List <Engineer> engineers = new List <Engineer>();
            Engineer        john      = new Engineer();

            john.Id                = Guid.NewGuid();
            john.Name              = "John";
            john.Title             = "Load test engineer";
            john.YearJoinedCompany = 2013;

            Engineer mary = new Engineer();

            mary.Id                = Guid.NewGuid();
            mary.Name              = "Mary";
            mary.Title             = "Sr. load test engineer";
            mary.YearJoinedCompany = 2012;

            Engineer fred = new Engineer();

            fred.Id                = Guid.NewGuid();
            fred.Name              = "Fred";
            fred.Title             = "Jr. load test engineer";
            fred.YearJoinedCompany = 2014;

            engineers.Add(john);
            engineers.Add(mary);
            engineers.Add(fred);
            context.Engineers.AddRange(engineers);

            context.RemoveRange(context.LoadtestTypes);
            context.SaveChanges();

            List <LoadtestType> testTypes  = new List <LoadtestType>();
            LoadtestType        stressTest = new LoadtestType();

            stressTest.Id = Guid.NewGuid();
            stressTest.ShortDescription = "Stress test";
            stressTest.LongDescription  = "To determine or validate an application’s behavior when it is pushed beyond normal or peak load conditions.";

            LoadtestType capacityTest = new LoadtestType();

            capacityTest.Id = Guid.NewGuid();
            capacityTest.ShortDescription = "Capacity test";
            capacityTest.LongDescription  = "To determine how many users and/or transactions a given system will support and still meet performance goals.";

            testTypes.Add(stressTest);
            testTypes.Add(capacityTest);
            context.LoadtestTypes.AddRange(testTypes);

            context.RemoveRange(context.Projects);
            context.SaveChanges();

            List <Project> projects     = new List <Project>();
            Project        firstProject = new Project();

            firstProject.Id = Guid.NewGuid();
            firstProject.DateInsertedUtc  = DateTime.UtcNow;
            firstProject.ShortDescription = "First project";
            firstProject.LongDescription  = "Long description of first project";

            Project secondProject = new Project();

            secondProject.Id = Guid.NewGuid();
            secondProject.DateInsertedUtc  = DateTime.UtcNow.AddDays(-5);
            secondProject.ShortDescription = "Second project";
            secondProject.LongDescription  = "Long description of second project";

            Project thirdProject = new Project();

            thirdProject.Id = Guid.NewGuid();
            thirdProject.DateInsertedUtc  = DateTime.UtcNow.AddDays(-10);
            thirdProject.ShortDescription = "Third project";
            thirdProject.LongDescription  = "Long description of third project";

            projects.Add(firstProject);
            projects.Add(secondProject);
            projects.Add(thirdProject);
            context.Projects.AddRange(projects);

            context.RemoveRange(context.Scenarios);
            context.SaveChanges();

            List <Scenario> scenarios   = new List <Scenario>();
            Scenario        scenarioOne = new Scenario();

            scenarioOne.Id     = Guid.NewGuid();
            scenarioOne.UriOne = "www.bbc.co.uk";
            scenarioOne.UriTwo = "www.cnn.com";

            Scenario scenarioTwo = new Scenario();

            scenarioTwo.Id     = Guid.NewGuid();
            scenarioTwo.UriOne = "www.amazon.com";
            scenarioTwo.UriTwo = "www.microsoft.com";

            Scenario scenarioThree = new Scenario();

            scenarioThree.Id       = Guid.NewGuid();
            scenarioThree.UriOne   = "www.greatsite.com";
            scenarioThree.UriTwo   = "www.nosuchsite.com";
            scenarioThree.UriThree = "www.neverheardofsite.com";

            scenarios.Add(scenarioOne);
            scenarios.Add(scenarioTwo);
            scenarios.Add(scenarioThree);
            context.Scenarios.AddRange(scenarios);

            context.RemoveRange(context.Loadtests);
            context.SaveChanges();

            List <Loadtest> loadtests = new List <Loadtest>();
            Loadtest        ltOne     = new Loadtest();

            ltOne.Id             = Guid.NewGuid();
            ltOne.AgentId        = amazon.Id;
            ltOne.CustomerId     = niceCustomer.Id;
            ltOne.EngineerId     = john.Id;
            ltOne.LoadtestTypeId = stressTest.Id;
            ltOne.DurationSec    = 60;
            ltOne.StartDateUtc   = DateTime.UtcNow;
            ltOne.UserCount      = 10;
            ltOne.ProjectId      = firstProject.Id;
            ltOne.ScenarioId     = scenarioOne.Id;

            Loadtest ltTwo = new Loadtest();

            ltTwo.Id             = Guid.NewGuid();
            ltTwo.AgentId        = azure.Id;
            ltTwo.CustomerId     = greatCustomer.Id;
            ltTwo.EngineerId     = mary.Id;
            ltTwo.LoadtestTypeId = capacityTest.Id;
            ltTwo.DurationSec    = 120;
            ltTwo.StartDateUtc   = DateTime.UtcNow.AddMinutes(20);
            ltTwo.UserCount      = 40;
            ltTwo.ProjectId      = secondProject.Id;
            ltTwo.ScenarioId     = scenarioThree.Id;

            Loadtest ltThree = new Loadtest();

            ltThree.Id             = Guid.NewGuid();
            ltThree.AgentId        = rackspace.Id;
            ltThree.CustomerId     = okCustomer.Id;
            ltThree.EngineerId     = fred.Id;
            ltThree.LoadtestTypeId = stressTest.Id;
            ltThree.DurationSec    = 180;
            ltThree.StartDateUtc   = DateTime.UtcNow.AddMinutes(30);
            ltThree.UserCount      = 50;
            ltThree.ProjectId      = thirdProject.Id;
            ltThree.ScenarioId     = scenarioTwo.Id;

            loadtests.Add(ltOne);
            loadtests.Add(ltTwo);
            loadtests.Add(ltThree);
            context.Loadtests.AddRange(loadtests);

            context.SaveChanges();
        }
        public IList <Loadtest> ConvertToDomain(IEnumerable <LoadtestViewModel> viewModels)
        {
            List <Loadtest>    loadtests = new List <Loadtest>();
            LoadTestingContext context   = new LoadTestingContext();

            foreach (LoadtestViewModel vm in viewModels)
            {
                Guid id = vm.Id;
                LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec);
                Agent agent = (from a in context.Agents
                               where a.Location.City.Equals(vm.AgentCity, StringComparison.InvariantCultureIgnoreCase) &&
                               a.Location.Country.ToLower() == vm.AgentCountry.ToLower()
                               select a).FirstOrDefault();
                if (agent == null)
                {
                    throw new ArgumentException("There is no agent with the given properties.");
                }

                Customer customer = (from c in context.Customers where c.Name.Equals(vm.CustomerName, StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault();
                if (customer == null)
                {
                    throw new ArgumentException("There is no customer with the given properties.");
                }

                Guid?engineerId = null;
                if (!string.IsNullOrEmpty(vm.EngineerName))
                {
                    Engineer engineer = (from e in context.Engineers where e.Name.Equals(vm.EngineerName, StringComparison.InvariantCultureIgnoreCase) select e).FirstOrDefault();
                    if (engineer == null)
                    {
                        throw new ArgumentException("There is no engineer with the given properties.");
                    }
                    engineerId = engineer.Id;
                }

                LoadtestType ltType = (from t in context.LoadtestTypes where t.Description.ShortDescription.Equals(vm.LoadtestTypeShortDescription, StringComparison.InvariantCultureIgnoreCase) select t).FirstOrDefault();
                if (ltType == null)
                {
                    throw new ArgumentException("There is no load test type with the given properties.");
                }

                Project project = (from p in context.Projects where p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower() select p).FirstOrDefault();
                if (project == null)
                {
                    throw new ArgumentException("There is no project with the given properties.");
                }

                Scenario scenario = (from s in context.Scenarios
                                     where s.UriOne.Equals(vm.ScenarioUriOne, StringComparison.InvariantCultureIgnoreCase) &&
                                     s.UriTwo.Equals(vm.ScenarioUriTwo, StringComparison.InvariantCultureIgnoreCase) &&
                                     s.UriThree.Equals(vm.ScenarioUriThree, StringComparison.InvariantCultureIgnoreCase)
                                     select s).FirstOrDefault();

                if (scenario == null)
                {
                    List <Uri> uris      = new List <Uri>();
                    Uri        firstUri  = string.IsNullOrEmpty(vm.ScenarioUriOne) ? null : new Uri(vm.ScenarioUriOne);
                    Uri        secondUri = string.IsNullOrEmpty(vm.ScenarioUriTwo) ? null : new Uri(vm.ScenarioUriTwo);
                    Uri        thirdUri  = string.IsNullOrEmpty(vm.ScenarioUriThree) ? null : new Uri(vm.ScenarioUriThree);
                    if (firstUri != null)
                    {
                        uris.Add(firstUri);
                    }
                    if (secondUri != null)
                    {
                        uris.Add(secondUri);
                    }
                    if (thirdUri != null)
                    {
                        uris.Add(thirdUri);
                    }
                    scenario = new Scenario(Guid.NewGuid(), uris);
                    context.Scenarios.Add(scenario);
                    context.SaveChanges();
                }

                Loadtest converted = new Loadtest(id, ltParams, agent.Id, customer.Id, engineerId, ltType.Id, project.Id, scenario.Id);
                loadtests.Add(converted);
            }
            return(loadtests);
        }
Exemple #3
0
        protected override void Seed(WebSuiteContext context)
        {
            var agents = new List <Agent>();
            var amazon = new Agent
            {
                Id       = Guid.NewGuid(),
                Location = new Location
                {
                    City      = "Seattle",
                    Country   = "USA",
                    Latitude  = 123.345,
                    Longitude = 135.543
                }
            };
            var rackspace = new Agent
            {
                Id       = Guid.NewGuid(),
                Location = new Location
                {
                    City      = "Frankfurt",
                    Country   = "Germany",
                    Latitude  = -123.654,
                    Longitude = 121.321
                }
            };
            var azure = new Agent
            {
                Id       = Guid.NewGuid(),
                Location = new Location
                {
                    City      = "Tokyo",
                    Country   = "Japan",
                    Latitude  = 23.45,
                    Longitude = 12.343
                }
            };

            agents.Add(amazon);
            agents.Add(rackspace);
            agents.Add(azure);
            context.Agents.AddRange(agents);

            var customers    = new List <Customer>();
            var niceCustomer = new Customer
            {
                Id          = Guid.NewGuid(),
                Address     = "New York",
                MainContact = "Elvis Presley",
                Name        = "Nice customer"
            };

            var greatCustomer = new Customer
            {
                Id          = Guid.NewGuid(),
                Address     = "London",
                MainContact = "Phil Collins",
                Name        = "Great customer"
            };

            var okCustomer = new Customer
            {
                Id          = Guid.NewGuid(),
                Address     = "Berlin",
                MainContact = "Freddie Mercury",
                Name        = "OK Customer"
            };

            customers.Add(niceCustomer);
            customers.Add(greatCustomer);
            customers.Add(okCustomer);
            context.Customers.AddRange(customers);

            var engineers = new List <Engineer>();
            var john      = new Engineer
            {
                Id                = Guid.NewGuid(),
                Name              = "John",
                Title             = "Load test engineer",
                YearJoinedCompany = 2013
            };

            var mary = new Engineer
            {
                Id                = Guid.NewGuid(),
                Name              = "Mary",
                Title             = "Sr. load test engineer",
                YearJoinedCompany = 2012
            };

            var fred = new Engineer
            {
                Id                = Guid.NewGuid(),
                Name              = "Fred",
                Title             = "Jr. load test engineer",
                YearJoinedCompany = 2014
            };

            engineers.Add(john);
            engineers.Add(mary);
            engineers.Add(fred);
            context.Engineers.AddRange(engineers);

            var testTypes  = new List <LoadtestType>();
            var stressTest = new LoadtestType
            {
                Id          = Guid.NewGuid(),
                Description = new Description
                {
                    ShortDescription = "Stress test",
                    LongDescription  =
                        "To determine or validate an application’s behavior when it is pushed beyond normal or peak load conditions."
                }
            };

            var capacityTest = new LoadtestType
            {
                Id          = Guid.NewGuid(),
                Description = new Description
                {
                    ShortDescription = "Capacity test",
                    LongDescription  =
                        "To determine how many users and/or transactions a given system will support and still meet performance goals."
                }
            };

            testTypes.Add(stressTest);
            testTypes.Add(capacityTest);
            context.LoadtestTypes.AddRange(testTypes);

            var projects     = new List <Project>();
            var firstProject = new Project
            {
                Id = Guid.NewGuid(),
                DateInsertedUtc = DateTime.UtcNow,
                Description     = new Description
                {
                    ShortDescription = "First project",
                    LongDescription  = "Long description of first project"
                }
            };

            var secondProject = new Project
            {
                Id = Guid.NewGuid(),
                DateInsertedUtc = DateTime.UtcNow.AddDays(-5),
                Description     = new Description
                {
                    ShortDescription = "Second project",
                    LongDescription  = "Long description of second project"
                }
            };

            var thirdProject = new Project
            {
                Id = Guid.NewGuid(),
                DateInsertedUtc = DateTime.UtcNow.AddDays(-10),
                Description     = new Description
                {
                    ShortDescription = "Third project",
                    LongDescription  = "Long description of third project"
                }
            };

            projects.Add(firstProject);
            projects.Add(secondProject);
            projects.Add(thirdProject);
            context.Projects.AddRange(projects);

            var scenarios   = new List <Scenario>();
            var scenarioOne = new Scenario
            {
                Id     = Guid.NewGuid(),
                UriOne = "www.bbc.co.uk",
                UriTwo = "www.cnn.com"
            };

            var scenarioTwo = new Scenario
            {
                Id     = Guid.NewGuid(),
                UriOne = "www.amazon.com",
                UriTwo = "www.microsoft.com"
            };

            var scenarioThree = new Scenario
            {
                Id       = Guid.NewGuid(),
                UriOne   = "www.greatsite.com",
                UriTwo   = "www.nosuchsite.com",
                UriThree = "www.neverheardofsite.com"
            };

            scenarios.Add(scenarioOne);
            scenarios.Add(scenarioTwo);
            scenarios.Add(scenarioThree);
            context.Scenarios.AddRange(scenarios);

            var loadtests = new List <Loadtest>();
            var ltOne     = new Loadtest
            {
                Id             = Guid.NewGuid(),
                AgentId        = amazon.Id,
                CustomerId     = niceCustomer.Id,
                EngineerId     = john.Id,
                LoadtestTypeId = stressTest.Id,
                Parameters     = new LoadtestParameters {
                    DurationSec = 60, StartDateUtc = DateTime.UtcNow, UserCount = 10
                },
                ProjectId  = firstProject.Id,
                ScenarioId = scenarioOne.Id
            };

            var ltTwo = new Loadtest
            {
                Id             = Guid.NewGuid(),
                AgentId        = azure.Id,
                CustomerId     = greatCustomer.Id,
                EngineerId     = mary.Id,
                LoadtestTypeId = capacityTest.Id,
                Parameters     = new LoadtestParameters
                {
                    DurationSec  = 120,
                    StartDateUtc = DateTime.UtcNow.AddMinutes(20),
                    UserCount    = 40
                },
                ProjectId  = secondProject.Id,
                ScenarioId = scenarioThree.Id
            };

            var ltThree = new Loadtest
            {
                Id             = Guid.NewGuid(),
                AgentId        = rackspace.Id,
                CustomerId     = okCustomer.Id,
                EngineerId     = fred.Id,
                LoadtestTypeId = stressTest.Id,
                Parameters     = new LoadtestParameters
                {
                    DurationSec  = 180,
                    StartDateUtc = DateTime.UtcNow.AddMinutes(30),
                    UserCount    = 50
                },
                ProjectId  = thirdProject.Id,
                ScenarioId = scenarioTwo.Id
            };

            loadtests.Add(ltOne);
            loadtests.Add(ltTwo);
            loadtests.Add(ltThree);
            context.Loadtests.AddRange(loadtests);

            context.SaveChanges();
        }
        public IList <LoadtestViewModel> ConvertToViewModels(IEnumerable <Loadtest> domains)
        {
            LoadTestingContext       context    = new LoadTestingContext();
            List <LoadtestViewModel> viewModels = new List <LoadtestViewModel>();

            foreach (Loadtest lt in domains)
            {
                LoadtestViewModel vm = new LoadtestViewModel();
                vm.Id = lt.Id;
                Agent agent = (from a in context.Agents where a.Id == lt.AgentId select a).FirstOrDefault();
                if (agent == null)
                {
                    throw new ArgumentException("There is no load test agent with the given ID.");
                }
                vm.AgentCountry = agent.Location.Country;
                vm.AgentCity    = agent.Location.City;

                Customer customer = (from c in context.Customers where c.Id == lt.CustomerId select c).FirstOrDefault();
                if (customer == null)
                {
                    throw new ArgumentException("There is no customer with the given ID.");
                }
                vm.CustomerName = customer.Name;

                if (lt.EngineerId.HasValue)
                {
                    Engineer engineer = (from e in context.Engineers where e.Id == lt.EngineerId.Value select e).FirstOrDefault();
                    if (engineer == null)
                    {
                        throw new ArgumentException("There is no engineer with the given ID.");
                    }
                    vm.EngineerName = engineer.Name;
                }

                LoadtestType loadtestType = (from t in context.LoadtestTypes where t.Id == lt.LoadtestTypeId select t).FirstOrDefault();
                if (loadtestType == null)
                {
                    throw new ArgumentException("There is no load test type with the given ID.");
                }
                vm.LoadtestTypeShortDescription = loadtestType.Description.ShortDescription;

                Project project = (from p in context.Projects where p.Id == lt.ProjectId select p).FirstOrDefault();
                if (project == null)
                {
                    throw new ArgumentException("There is no project with the given ID.");
                }
                vm.ProjectName = project.Description.ShortDescription;

                Scenario scenario = (from s in context.Scenarios where s.Id == lt.ScenarioId select s).FirstOrDefault();
                if (scenario == null)
                {
                    throw new ArgumentException("There is no scenario with the given ID.");
                }
                vm.ScenarioUriOne   = scenario.UriOne;
                vm.ScenarioUriTwo   = scenario.UriTwo;
                vm.ScenarioUriThree = scenario.UriThree;

                vm.UserCount    = lt.Parameters.UserCount;
                vm.StartDateUtc = lt.Parameters.StartDateUtc;
                vm.DurationSec  = lt.Parameters.DurationSec;

                viewModels.Add(vm);
            }
            return(viewModels);
        }