Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 private static void TestInsertion()
 {
     LoadTestingContext context = LoadTestingContext.Create(new WebConfigConnectionStringRepository());
     CustomerMongoDb newCustomer = new CustomerMongoDb()
     {
         DomainId = Guid.NewGuid(),
         DbObjectId = ObjectId.GenerateNewId(),
         Name = "Brand new customer"
     };
     Task insertionTask = context.Customers.InsertOneAsync(newCustomer);
     Task.WaitAll(insertionTask);
 }