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);
        }
        public static Loadtest ConvertToDomain(this LoadtestMongoDb loadtestDbModel)
        {
            LoadtestParametersMongoDb ltParamsDb     = loadtestDbModel.Parameters;
            LoadtestParameters        ltParamsDomain = new LoadtestParameters(ltParamsDb.StartDateUtc, ltParamsDb.UserCount, ltParamsDb.DurationSec);

            return(new Loadtest(
                       loadtestDbModel.DomainId,
                       ltParamsDomain,
                       loadtestDbModel.AgentId,
                       loadtestDbModel.CustomerId,
                       loadtestDbModel.EngineerId,
                       loadtestDbModel.LoadtestTypeId,
                       loadtestDbModel.ProjectId,
                       loadtestDbModel.ScenarioId));
        }
        public void AddOrUpdateLoadtests(AddOrUpdateLoadtestsValidationResult addOrUpdateLoadtestsValidationResult)
        {
            LoadTestingContext context = LoadTestingContext.Create(base.ConnectionStringRepository);

            if (addOrUpdateLoadtestsValidationResult.ValidationComplete)
            {
                if (addOrUpdateLoadtestsValidationResult.ToBeInserted.Any())
                {
                    IEnumerable <LoadtestMongoDb> toBeInserted = addOrUpdateLoadtestsValidationResult.ToBeInserted.PrepareAllForInsertion();
                    context.Loadtests.InsertMany(toBeInserted);
                }

                if (addOrUpdateLoadtestsValidationResult.ToBeUpdated.Any())
                {
                    foreach (Loadtest toBeUpdated in addOrUpdateLoadtestsValidationResult.ToBeUpdated)
                    {
                        Guid            existingLoadtestId = toBeUpdated.Id;
                        var             loadtestInDbQuery  = context.Loadtests.Find <LoadtestMongoDb>(lt => lt.DomainId == existingLoadtestId);
                        LoadtestMongoDb loadtestInDb       = loadtestInDbQuery.SingleOrDefault();
                        loadtestInDb.AgentId        = toBeUpdated.AgentId;
                        loadtestInDb.CustomerId     = toBeUpdated.CustomerId;
                        loadtestInDb.EngineerId     = toBeUpdated.EngineerId;
                        loadtestInDb.LoadtestTypeId = toBeUpdated.LoadtestTypeId;
                        LoadtestParameters ltDomainParameters = toBeUpdated.Parameters;
                        loadtestInDb.Parameters.DurationSec        = ltDomainParameters.DurationSec;
                        loadtestInDb.Parameters.ExpectedEndDateUtc = ltDomainParameters.StartDateUtc.AddSeconds(ltDomainParameters.DurationSec);
                        loadtestInDb.Parameters.StartDateUtc       = ltDomainParameters.StartDateUtc;
                        loadtestInDb.Parameters.UserCount          = ltDomainParameters.UserCount;
                        loadtestInDb.ProjectId  = toBeUpdated.ProjectId;
                        loadtestInDb.ScenarioId = toBeUpdated.ScenarioId;
                        context.Loadtests.FindOneAndReplace <LoadtestMongoDb>(lt => lt.DbObjectId == loadtestInDb.DbObjectId, loadtestInDb);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Validation is not complete. You have to call the AddOrUpdateLoadtests method of the Timetable class first.");
            }
        }
Exemple #4
0
        private static void Seed()
        {
            LoadTestingContext  context = LoadTestingContext.Create(new WebConfigConnectionStringRepository());
            List <AgentMongoDb> agents  = new List <AgentMongoDb>();
            AgentMongoDb        amazon  = new AgentMongoDb();

            amazon.DomainId   = Guid.NewGuid();
            amazon.DbObjectId = ObjectId.GenerateNewId();
            amazon.Location   = new LocationMongoDb()
            {
                City       = "Seattle",
                Country    = "USA",
                DbObjectId = ObjectId.GenerateNewId()
            };
            AgentMongoDb rackspace = new AgentMongoDb();

            rackspace.DomainId   = Guid.NewGuid();
            rackspace.DbObjectId = ObjectId.GenerateNewId();
            rackspace.Location   = new LocationMongoDb()
            {
                City       = "Frankfurt",
                Country    = "Germany",
                DbObjectId = ObjectId.GenerateNewId()
            };
            AgentMongoDb azure = new AgentMongoDb();

            azure.DomainId   = Guid.NewGuid();
            azure.DbObjectId = ObjectId.GenerateNewId();
            azure.Location   = new LocationMongoDb()
            {
                City       = "Tokyo",
                Country    = "Japan",
                DbObjectId = ObjectId.GenerateNewId()
            };
            agents.Add(amazon);
            agents.Add(rackspace);
            agents.Add(azure);
            Task addManyAgentsTask = context.Agents.InsertManyAsync(agents);

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

            niceCustomer.DomainId   = Guid.NewGuid();
            niceCustomer.DbObjectId = ObjectId.GenerateNewId();
            niceCustomer.Name       = "Nice customer";

            CustomerMongoDb greatCustomer = new CustomerMongoDb();

            greatCustomer.DomainId   = Guid.NewGuid();
            greatCustomer.DbObjectId = ObjectId.GenerateNewId();
            greatCustomer.Name       = "Great customer";

            CustomerMongoDb okCustomer = new CustomerMongoDb();

            okCustomer.DomainId   = Guid.NewGuid();
            okCustomer.DbObjectId = ObjectId.GenerateNewId();
            okCustomer.Name       = "OK Customer";

            customers.Add(niceCustomer);
            customers.Add(greatCustomer);
            customers.Add(okCustomer);
            Task addManyCustomersTask = context.Customers.InsertManyAsync(customers);

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

            john.DomainId   = Guid.NewGuid();
            john.Name       = "John";
            john.DbObjectId = ObjectId.GenerateNewId();

            EngineerMongoDb mary = new EngineerMongoDb();

            mary.DomainId   = Guid.NewGuid();
            mary.Name       = "Mary";
            mary.DbObjectId = ObjectId.GenerateNewId();

            EngineerMongoDb fred = new EngineerMongoDb();

            fred.DomainId   = Guid.NewGuid();
            fred.Name       = "Fred";
            fred.DbObjectId = ObjectId.GenerateNewId();

            engineers.Add(john);
            engineers.Add(mary);
            engineers.Add(fred);
            Task addManyEngineersTask = context.Engineers.InsertManyAsync(engineers);

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

            stressTest.DomainId    = Guid.NewGuid();
            stressTest.DbObjectId  = ObjectId.GenerateNewId();
            stressTest.Description = new DescriptionMongoDb()
            {
                DbObjectId       = ObjectId.GenerateNewId(),
                ShortDescription = "Stress test",
                LongDescription  = "To determine or validate an application’s behavior when it is pushed beyond normal or peak load conditions."
            };

            LoadtestTypeMongoDb capacityTest = new LoadtestTypeMongoDb();

            capacityTest.DomainId    = Guid.NewGuid();
            capacityTest.DbObjectId  = ObjectId.GenerateNewId();
            capacityTest.Description = new DescriptionMongoDb()
            {
                DbObjectId       = ObjectId.GenerateNewId(),
                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);
            Task addManyLoadtestTypesTask = context.LoadtestTypes.InsertManyAsync(testTypes);

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

            firstProject.DomainId    = Guid.NewGuid();
            firstProject.DbObjectId  = ObjectId.GenerateNewId();
            firstProject.Description = new DescriptionMongoDb()
            {
                DbObjectId       = ObjectId.GenerateNewId(),
                ShortDescription = "First project",
                LongDescription  = "Long description of first project"
            };

            ProjectMongoDb secondProject = new ProjectMongoDb();

            secondProject.DomainId    = Guid.NewGuid();
            secondProject.DbObjectId  = ObjectId.GenerateNewId();
            secondProject.Description = new DescriptionMongoDb()
            {
                DbObjectId       = ObjectId.GenerateNewId(),
                ShortDescription = "Second project",
                LongDescription  = "Long description of second project"
            };

            ProjectMongoDb thirdProject = new ProjectMongoDb();

            thirdProject.DomainId    = Guid.NewGuid();
            thirdProject.DbObjectId  = ObjectId.GenerateNewId();
            thirdProject.Description = new DescriptionMongoDb()
            {
                DbObjectId       = ObjectId.GenerateNewId(),
                ShortDescription = "Third project",
                LongDescription  = "Long description of third project"
            };
            projects.Add(firstProject);
            projects.Add(secondProject);
            projects.Add(thirdProject);
            Task addManyProjectsTask = context.Projects.InsertManyAsync(projects);

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

            scenarioOne.DomainId   = Guid.NewGuid();
            scenarioOne.DbObjectId = ObjectId.GenerateNewId();
            scenarioOne.UriOne     = "www.bbc.co.uk";
            scenarioOne.UriTwo     = "www.cnn.com";

            ScenarioMongoDb scenarioTwo = new ScenarioMongoDb();

            scenarioTwo.DomainId   = Guid.NewGuid();
            scenarioTwo.DbObjectId = ObjectId.GenerateNewId();
            scenarioTwo.UriOne     = "www.amazon.com";
            scenarioTwo.UriTwo     = "www.microsoft.com";

            ScenarioMongoDb scenarioThree = new ScenarioMongoDb();

            scenarioThree.DomainId   = Guid.NewGuid();
            scenarioThree.DbObjectId = ObjectId.GenerateNewId();
            scenarioThree.UriOne     = "www.greatsite.com";
            scenarioThree.UriTwo     = "www.nosuchsite.com";
            scenarioThree.UriThree   = "www.neverheardofsite.com";

            scenarios.Add(scenarioOne);
            scenarios.Add(scenarioTwo);
            scenarios.Add(scenarioThree);
            Task addManyScenariosTask = context.Scenarios.InsertManyAsync(scenarios);

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

            ltOne.DomainId       = Guid.NewGuid();
            ltOne.DbObjectId     = ObjectId.GenerateNewId();
            ltOne.AgentId        = amazon.DomainId;
            ltOne.CustomerId     = niceCustomer.DomainId;
            ltOne.EngineerId     = john.DomainId;
            ltOne.LoadtestTypeId = stressTest.DomainId;
            DateTime ltOneStart = DateTime.UtcNow;

            ltOne.Parameters = new LoadtestParametersMongoDb()
            {
                DbObjectId         = ObjectId.GenerateNewId(),
                DurationSec        = 60,
                StartDateUtc       = ltOneStart,
                UserCount          = 10,
                ExpectedEndDateUtc = ltOneStart.AddSeconds(60)
            };
            ltOne.ProjectId  = firstProject.DomainId;
            ltOne.ScenarioId = scenarioOne.DomainId;

            LoadtestMongoDb ltTwo = new LoadtestMongoDb();

            ltTwo.DomainId       = Guid.NewGuid();
            ltTwo.DbObjectId     = ObjectId.GenerateNewId();
            ltTwo.AgentId        = azure.DomainId;
            ltTwo.CustomerId     = greatCustomer.DomainId;
            ltTwo.EngineerId     = mary.DomainId;
            ltTwo.LoadtestTypeId = capacityTest.DomainId;
            DateTime ltTwoStart = DateTime.UtcNow.AddMinutes(20);

            ltTwo.Parameters = new LoadtestParametersMongoDb()
            {
                DbObjectId         = ObjectId.GenerateNewId(),
                DurationSec        = 120,
                StartDateUtc       = ltTwoStart,
                UserCount          = 40,
                ExpectedEndDateUtc = ltTwoStart.AddSeconds(120)
            };
            ltTwo.ProjectId  = secondProject.DomainId;
            ltTwo.ScenarioId = scenarioThree.DomainId;

            LoadtestMongoDb ltThree = new LoadtestMongoDb();

            ltThree.DomainId       = Guid.NewGuid();
            ltThree.DbObjectId     = ObjectId.GenerateNewId();
            ltThree.AgentId        = rackspace.DomainId;
            ltThree.CustomerId     = okCustomer.DomainId;
            ltThree.EngineerId     = fred.DomainId;
            ltThree.LoadtestTypeId = stressTest.DomainId;
            DateTime ltThreeStart = DateTime.UtcNow.AddMinutes(30);

            ltThree.Parameters = new LoadtestParametersMongoDb()
            {
                DbObjectId         = ObjectId.GenerateNewId(),
                DurationSec        = 180,
                StartDateUtc       = ltThreeStart,
                UserCount          = 50,
                ExpectedEndDateUtc = ltThreeStart.AddSeconds(180)
            };
            ltThree.ProjectId  = thirdProject.DomainId;
            ltThree.ScenarioId = scenarioTwo.DomainId;

            loadtests.Add(ltOne);
            loadtests.Add(ltTwo);
            loadtests.Add(ltThree);
            Task addManyLoadtestsTask = context.Loadtests.InsertManyAsync(loadtests);

            Task.WaitAll(addManyAgentsTask, addManyCustomersTask, addManyEngineersTask, addManyLoadtestTypesTask
                         , addManyProjectsTask, addManyScenariosTask, addManyLoadtestsTask);
        }