public static LoadtestMongoDb PrepareForInsertion(this Loadtest domain)
        {
            LoadtestMongoDb ltDb = new LoadtestMongoDb();

            ltDb.DomainId       = domain.Id;
            ltDb.DbObjectId     = ObjectId.GenerateNewId();
            ltDb.AgentId        = domain.AgentId;
            ltDb.CustomerId     = domain.CustomerId;
            ltDb.EngineerId     = domain.EngineerId;
            ltDb.LoadtestTypeId = domain.LoadtestTypeId;

            int      duration = domain.Parameters.DurationSec;
            DateTime start    = domain.Parameters.StartDateUtc;

            ltDb.Parameters = new LoadtestParametersMongoDb()
            {
                DbObjectId         = ObjectId.GenerateNewId(),
                DurationSec        = duration,
                ExpectedEndDateUtc = start.AddSeconds(duration),
                StartDateUtc       = start,
                UserCount          = domain.Parameters.UserCount
            };
            ltDb.ProjectId  = domain.ProjectId;
            ltDb.ScenarioId = domain.ScenarioId;
            return(ltDb);
        }
Example #2
0
        static void Main(string[] args)
        {
            ITimetableRepository repo = new TimetableRepository(new WebConfigConnectionStringRepository());
            IList <Loadtest>     loadtestsInPeriod = repo.GetLoadtestsForTimePeriod(DateTime.UtcNow.AddYears(-1), DateTime.UtcNow.AddYears(1));
            List <Loadtest>      toBeInserted      = new List <Loadtest>();
            List <Loadtest>      toBeUpdated       = new List <Loadtest>();
            Loadtest             ltNewOne          = new Loadtest
                                                         (Guid.NewGuid(),
                                                         new LoadtestParameters(DateTime.UtcNow.AddDays(1), 100, 90),
                                                         Guid.Parse("52d4e276-193d-4ff3-a40e-c45381969d24"),
                                                         Guid.Parse("cb5c3463-d1cb-4c1c-b667-f1c6a065edd1"),
                                                         Guid.Parse("c1cf1179-98a7-4c58-bcaa-a0e7c697293f"),
                                                         Guid.Parse("612cf872-3967-41e7-a30d-28e26df66dcc"),
                                                         Guid.Parse("c3d79996-7045-4bce-a6cd-fcf398717ae5"),
                                                         Guid.Parse("4d27ad00-14d8-4c1c-98b9-64556e957daf"));
            Loadtest ltNewTwo = new Loadtest
                                    (Guid.NewGuid(),
                                    new LoadtestParameters(DateTime.UtcNow.AddDays(5), 500, 300),
                                    Guid.Parse("b9b42875-414f-46b9-8dd2-417668e23e83"),
                                    Guid.Parse("f966ccf4-7802-4796-8767-637611b611de"),
                                    Guid.Parse("a4ae54f4-e662-4922-a2ce-4df9af9d23c8"),
                                    Guid.Parse("95202f85-0c8e-426b-b0ea-ed74f4d1ccbc"),
                                    Guid.Parse("1e4871ba-de8b-4e2c-98f4-3364b9d82558"),
                                    Guid.Parse("4d27ad00-14d8-4c1c-98b9-64556e957daf"));

            toBeInserted.Add(ltNewOne);
            toBeInserted.Add(ltNewTwo);

            Loadtest ltUpdOne = new Loadtest
                                    (Guid.Parse("71b29573-8f67-49ab-8ee0-f8dd0bbceefd"),
                                    new LoadtestParameters(DateTime.UtcNow.AddDays(14), 50, 300),
                                    Guid.Parse("52d4e276-193d-4ff3-a40e-c45381969d24"),
                                    Guid.Parse("5b16880e-b0dd-4d66-bff9-f79eba6490ec"),
                                    Guid.Parse("40ccb6aa-c9a6-466d-be02-c73122d6edca"),
                                    Guid.Parse("612cf872-3967-41e7-a30d-28e26df66dcc"),
                                    Guid.Parse("e2caa1f0-2ee9-4e8f-86a0-51de8aba4eca"),
                                    Guid.Parse("4d27ad00-14d8-4c1c-98b9-64556e957daf"));

            toBeUpdated.Add(ltUpdOne);

            AddOrUpdateLoadtestsValidationResult validationRes = new AddOrUpdateLoadtestsValidationResult(toBeInserted, toBeUpdated,
                                                                                                          new List <Loadtest>(), "Validation summary");

            repo.AddOrUpdateLoadtests(validationRes);

            //TestSelectWithWhereClause();
            //TestReplacement();
            //Seed();

            /*
             * string mongoDbConnectionString = "mongodb://localhost:27017";
             * MongoClient mongoClient = new MongoClient(mongoDbConnectionString);
             * IMongoDatabase testDatabase = mongoClient.GetDatabase("Cartoons");
             * Task t = testDatabase.CreateCollectionAsync("Disney");
             * Task.WaitAll(t);
             * //Task.Run(() => testDatabase.CreateCollectionAsync("Disney"));*/
        }
        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;
        }
Example #4
0
        public void DeleteById(Guid guid)
        {
            LoadTestingContext context  = new LoadTestingContext(_options);
            Loadtest           loadtest = (from l in context.Loadtests where l.Id == guid select l).FirstOrDefault();

            if (loadtest == null)
            {
                throw new ArgumentException(string.Format("There's no load test by ID {0}", guid));
            }
            context.Entry <Loadtest>(loadtest).State = EntityState.Deleted;
            context.SaveChanges();
        }
        static void Main(string[] args)
        {
            ITimetableRepository repo = new TimetableRepository(new WebConfigConnectionStringRepository());
            IList<Loadtest> loadtestsInPeriod = repo.GetLoadtestsForTimePeriod(DateTime.UtcNow.AddYears(-1), DateTime.UtcNow.AddYears(1));
            List<Loadtest> toBeInserted = new List<Loadtest>();
            List<Loadtest> toBeUpdated = new List<Loadtest>();
            Loadtest ltNewOne = new Loadtest
                (Guid.NewGuid(),
                new LoadtestParameters(DateTime.UtcNow.AddDays(1), 100, 90),
                Guid.Parse("52d4e276-193d-4ff3-a40e-c45381969d24"),
                Guid.Parse("cb5c3463-d1cb-4c1c-b667-f1c6a065edd1"),
                Guid.Parse("c1cf1179-98a7-4c58-bcaa-a0e7c697293f"),
                Guid.Parse("612cf872-3967-41e7-a30d-28e26df66dcc"),
                Guid.Parse("c3d79996-7045-4bce-a6cd-fcf398717ae5"),
                Guid.Parse("4d27ad00-14d8-4c1c-98b9-64556e957daf"));
            Loadtest ltNewTwo = new Loadtest
                (Guid.NewGuid(),
                new LoadtestParameters(DateTime.UtcNow.AddDays(5), 500, 300),
                Guid.Parse("b9b42875-414f-46b9-8dd2-417668e23e83"),
                Guid.Parse("f966ccf4-7802-4796-8767-637611b611de"),
                Guid.Parse("a4ae54f4-e662-4922-a2ce-4df9af9d23c8"),
                Guid.Parse("95202f85-0c8e-426b-b0ea-ed74f4d1ccbc"),
                Guid.Parse("1e4871ba-de8b-4e2c-98f4-3364b9d82558"),
                Guid.Parse("4d27ad00-14d8-4c1c-98b9-64556e957daf"));
            toBeInserted.Add(ltNewOne);
            toBeInserted.Add(ltNewTwo);

            Loadtest ltUpdOne = new Loadtest
            (Guid.Parse("71b29573-8f67-49ab-8ee0-f8dd0bbceefd"),
            new LoadtestParameters(DateTime.UtcNow.AddDays(14), 50, 300),
            Guid.Parse("52d4e276-193d-4ff3-a40e-c45381969d24"),
            Guid.Parse("5b16880e-b0dd-4d66-bff9-f79eba6490ec"),
            Guid.Parse("40ccb6aa-c9a6-466d-be02-c73122d6edca"),
            Guid.Parse("612cf872-3967-41e7-a30d-28e26df66dcc"),
            Guid.Parse("e2caa1f0-2ee9-4e8f-86a0-51de8aba4eca"),
            Guid.Parse("4d27ad00-14d8-4c1c-98b9-64556e957daf"));
            toBeUpdated.Add(ltUpdOne);

            AddOrUpdateLoadtestsValidationResult validationRes = new AddOrUpdateLoadtestsValidationResult(toBeInserted, toBeUpdated,
                new List<Loadtest>(), "Validation summary");
            repo.AddOrUpdateLoadtests(validationRes);

            //TestSelectWithWhereClause();
            //TestReplacement();
            //Seed();
            /*
            string mongoDbConnectionString = "mongodb://localhost:27017";
            MongoClient mongoClient = new MongoClient(mongoDbConnectionString);
            IMongoDatabase testDatabase = mongoClient.GetDatabase("Cartoons");
            Task t = testDatabase.CreateCollectionAsync("Disney");
            Task.WaitAll(t);
            //Task.Run(() => testDatabase.CreateCollectionAsync("Disney"));*/
        }
Example #6
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 = LoadTestingContext.Create(base.ConnectionStringRepository);
            foreach (LoadtestViewModel vm in viewModels)
            {
                Guid id = vm.Id;
                LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec);

                var agentQueryBuilder = Builders<AgentMongoDb>.Filter;
                var agentCityFilter = agentQueryBuilder.Eq<string>(a => a.Location.City.ToLower(), vm.AgentCity.ToLower());
                var agentCountryFilter = agentQueryBuilder.Eq<string>(a => a.Location.Country.ToLower(), vm.AgentCountry.ToLower());
                var agentCompleteFilter = agentQueryBuilder.And(agentCityFilter, agentCountryFilter);
                AgentMongoDb agentDb = context.Agents.Find(agentCompleteFilter).FirstOrDefault();
                if (agentDb == null) throw new ArgumentException("There is no agent with the given properties.");

                var customerQueryBuilder = Builders<CustomerMongoDb>.Filter;
                var customerQuery = customerQueryBuilder.Eq<string>(c => c.Name.ToLower(), vm.CustomerName.ToLower());
                CustomerMongoDb custDb = context.Customers.Find(customerQuery).SingleOrDefault();
                if (custDb == null) throw new ArgumentException("There is no customer with the given properties.");

                Guid? engineerId = null;
                if (!string.IsNullOrEmpty(vm.EngineerName))
                {
                    EngineerMongoDb engDb = context.Engineers.Find(e => e.Name.ToLower() == vm.EngineerName.ToLower()).SingleOrDefault();
                    if (engDb == null) throw new ArgumentException("There is no engineer with the given properties.");
                    engineerId = engDb.DomainId;
                }

                LoadtestTypeMongoDb ltTypeDb = context.LoadtestTypes.Find(t => t.Description.ShortDescription.ToLower() == vm.LoadtestTypeShortDescription.ToLower()).SingleOrDefault();
                if (ltTypeDb == null) throw new ArgumentException("There is no load test type with the given properties.");

                ProjectMongoDb projectDb = context.Projects.Find(p => p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower()).SingleOrDefault();
                if (projectDb == null) throw new ArgumentException("There is no project with the given properties.");

                var scenarioQueryBuilder = Builders<ScenarioMongoDb>.Filter;
                var scenarioUriOneFilter = scenarioQueryBuilder.Eq<string>(s => s.UriOne.ToLower(), vm.ScenarioUriOne.ToLower());
                var scenarioUriTwoFilter = scenarioQueryBuilder.Eq<string>(s => s.UriTwo.ToLower(), vm.ScenarioUriTwo.ToLower());
                var scenarioUriThreeFilter = scenarioQueryBuilder.Eq<string>(s => s.UriThree.ToLower(), vm.ScenarioUriThree.ToLower());
                var scenarioCompleteFilter = scenarioQueryBuilder.And(scenarioUriOneFilter, scenarioUriTwoFilter, scenarioUriThreeFilter);
                ScenarioMongoDb scenarioDb = context.Scenarios.Find(scenarioCompleteFilter).SingleOrDefault();
                if (scenarioDb == null)
                {
                    scenarioDb = new ScenarioMongoDb()
                    {
                        DbObjectId = ObjectId.GenerateNewId(),
                        DomainId = Guid.NewGuid()
                    };
                    if (!string.IsNullOrEmpty(vm.ScenarioUriOne))
                    {
                        scenarioDb.UriOne = vm.ScenarioUriOne;
                    }
                    if (!string.IsNullOrEmpty(vm.ScenarioUriTwo))
                    {
                        scenarioDb.UriTwo = vm.ScenarioUriTwo;
                    }
                    if (!string.IsNullOrEmpty(vm.ScenarioUriThree))
                    {
                        scenarioDb.UriThree = vm.ScenarioUriThree;
                    }
                    context.Scenarios.InsertOne(scenarioDb);
                }

                Loadtest converted = new Loadtest(id, ltParams, agentDb.DomainId, custDb.DomainId, engineerId, ltTypeDb.DomainId, projectDb.DomainId, scenarioDb.DomainId);
                loadtests.Add(converted);
            }
            return loadtests;
        }
        private LoadtestValidationSummary OkToAddOrModify(Loadtest loadtest)
        {
            LoadtestValidationSummary validationSummary = new LoadtestValidationSummary();
            validationSummary.OkToAddOrModify = true;
            validationSummary.ReasonForValidationFailure = string.Empty;
            List<Loadtest> loadtestsOnSameAgent = (from l in Loadtests
                                                   where l.AgentId == loadtest.AgentId
                                                   && DatesOverlap(l, loadtest)
                                                   select l).ToList();
            if (loadtestsOnSameAgent.Count >= 2)
            {
                validationSummary.OkToAddOrModify = false;
                validationSummary.ReasonForValidationFailure += " The selected load test agent is already booked for this period. ";
            }

            if (loadtest.EngineerId.HasValue)
            {
                List<Loadtest> loadtestsOnSameEngineer = (from l in Loadtests
                                                          where loadtest.EngineerId.HasValue &&
                                                          l.EngineerId.Value == loadtest.EngineerId.Value
                                                          && DatesOverlap(l, loadtest)
                                                          select l).ToList();
                if (loadtestsOnSameEngineer.Any())
                {
                    validationSummary.OkToAddOrModify = false;
                    validationSummary.ReasonForValidationFailure += " The selected load test engineer is already booked for this period. ";
                }
            }

            return validationSummary;
        }
 private bool DatesOverlap(Loadtest loadtestOne, Loadtest loadtestTwo)
 {
     return (loadtestOne.Parameters.StartDateUtc < loadtestTwo.Parameters.GetEndDateUtc()
         && loadtestTwo.Parameters.StartDateUtc < loadtestOne.Parameters.GetEndDateUtc());
 }
Example #10
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();
        }
Example #11
0
        public IList <Loadtest> ConvertToDomain(IEnumerable <LoadtestViewModel> viewModels)
        {
            List <Loadtest>    loadtests = new List <Loadtest>();
            LoadTestingContext context   = LoadTestingContext.Create(base.ConnectionStringRepository);

            foreach (LoadtestViewModel vm in viewModels)
            {
                Guid id = vm.Id;
                LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec);

                var          agentQueryBuilder   = Builders <AgentMongoDb> .Filter;
                var          agentCityFilter     = agentQueryBuilder.Eq <string>(a => a.Location.City.ToLower(), vm.AgentCity.ToLower());
                var          agentCountryFilter  = agentQueryBuilder.Eq <string>(a => a.Location.Country.ToLower(), vm.AgentCountry.ToLower());
                var          agentCompleteFilter = agentQueryBuilder.And(agentCityFilter, agentCountryFilter);
                AgentMongoDb agentDb             = context.Agents.Find(agentCompleteFilter).FirstOrDefault();
                if (agentDb == null)
                {
                    throw new ArgumentException("There is no agent with the given properties.");
                }

                var             customerQueryBuilder = Builders <CustomerMongoDb> .Filter;
                var             customerQuery        = customerQueryBuilder.Eq <string>(c => c.Name.ToLower(), vm.CustomerName.ToLower());
                CustomerMongoDb custDb = context.Customers.Find(customerQuery).SingleOrDefault();
                if (custDb == null)
                {
                    throw new ArgumentException("There is no customer with the given properties.");
                }

                Guid?engineerId = null;
                if (!string.IsNullOrEmpty(vm.EngineerName))
                {
                    EngineerMongoDb engDb = context.Engineers.Find(e => e.Name.ToLower() == vm.EngineerName.ToLower()).SingleOrDefault();
                    if (engDb == null)
                    {
                        throw new ArgumentException("There is no engineer with the given properties.");
                    }
                    engineerId = engDb.DomainId;
                }

                LoadtestTypeMongoDb ltTypeDb = context.LoadtestTypes.Find(t => t.Description.ShortDescription.ToLower() == vm.LoadtestTypeShortDescription.ToLower()).SingleOrDefault();
                if (ltTypeDb == null)
                {
                    throw new ArgumentException("There is no load test type with the given properties.");
                }

                ProjectMongoDb projectDb = context.Projects.Find(p => p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower()).SingleOrDefault();
                if (projectDb == null)
                {
                    throw new ArgumentException("There is no project with the given properties.");
                }

                var             scenarioQueryBuilder   = Builders <ScenarioMongoDb> .Filter;
                var             scenarioUriOneFilter   = scenarioQueryBuilder.Eq <string>(s => s.UriOne.ToLower(), vm.ScenarioUriOne.ToLower());
                var             scenarioUriTwoFilter   = scenarioQueryBuilder.Eq <string>(s => s.UriTwo.ToLower(), vm.ScenarioUriTwo.ToLower());
                var             scenarioUriThreeFilter = scenarioQueryBuilder.Eq <string>(s => s.UriThree.ToLower(), vm.ScenarioUriThree.ToLower());
                var             scenarioCompleteFilter = scenarioQueryBuilder.And(scenarioUriOneFilter, scenarioUriTwoFilter, scenarioUriThreeFilter);
                ScenarioMongoDb scenarioDb             = context.Scenarios.Find(scenarioCompleteFilter).SingleOrDefault();
                if (scenarioDb == null)
                {
                    scenarioDb = new ScenarioMongoDb()
                    {
                        DbObjectId = ObjectId.GenerateNewId(),
                        DomainId   = Guid.NewGuid()
                    };
                    if (!string.IsNullOrEmpty(vm.ScenarioUriOne))
                    {
                        scenarioDb.UriOne = vm.ScenarioUriOne;
                    }
                    if (!string.IsNullOrEmpty(vm.ScenarioUriTwo))
                    {
                        scenarioDb.UriTwo = vm.ScenarioUriTwo;
                    }
                    if (!string.IsNullOrEmpty(vm.ScenarioUriThree))
                    {
                        scenarioDb.UriThree = vm.ScenarioUriThree;
                    }
                    context.Scenarios.InsertOne(scenarioDb);
                }

                Loadtest converted = new Loadtest(id, ltParams, agentDb.DomainId, custDb.DomainId, engineerId, ltTypeDb.DomainId, projectDb.DomainId, scenarioDb.DomainId);
                loadtests.Add(converted);
            }
            return(loadtests);
        }
        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);
        }