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; }
public void TestLoadtestingContext() { /* ITimetableRepository timetableRepo = new TimetableRepository(); IList<Loadtest> loadtests = timetableRepo.GetLoadtestsForTimePeriod(DateTime.UtcNow.AddDays(-10), DateTime.UtcNow.AddDays(10)); Timetable tt = new Timetable(loadtests); Loadtest newLoadtest = new Loadtest(Guid.Parse("8c928a5e-d038-44f3-a8ff-70f64a651155"), new LoadtestParameters(DateTime.UtcNow.AddDays(3), 120, 900), Guid.Parse("751ec485-437d-4bae-9ff1-1923203a87b1") , Guid.Parse("99f4dc94-718c-450d-87b6-3153bb8db622"), Guid.Parse("471119e2-2b3c-4545-97a2-5f52d1fa7954") , Guid.Parse("a868a7c5-2f4a-43f7-9a8c-a597793fdc56"), Guid.Parse("96877388-ce4d-4ea8-ae93-438a696386b9") , Guid.Parse("73e25716-7622-4af6-99a0-0638efb1c8cc")); List<Loadtest> allChanges = new List<Loadtest>() { newLoadtest }; AddOrUpdateLoadtestsValidationResult res = tt.AddOrUpdateLoadtests(allChanges); Debug.WriteLine(res.OperationResultSummary); timetableRepo.AddOrUpdateLoadtests(res); timetableRepo.DeleteById(Guid.Parse("4e880392-5497-4c9e-a3de-38f66348fe8e"));*/ ITimetableRepository timetableRepo = new TimetableRepository(); ITimetableViewModelRepository viewModelRepo = new TimetableViewModelRepository(); /* IList<Loadtest> loadtests = timetableRepo.GetLoadtestsForTimePeriod(DateTime.UtcNow.AddDays(-10), DateTime.UtcNow.AddDays(10)); IList<LoadtestViewModel> vms = viewModelRepo.ConvertToViewModels(loadtests);*/ LoadtestViewModel vm = new LoadtestViewModel(); vm.Id = Guid.NewGuid(); vm.AgentCity = "Tokyo"; vm.AgentCountry = "Japan"; vm.CustomerName = "Great customer"; vm.DurationSec = 300; vm.EngineerName = "Fred"; vm.LoadtestTypeShortDescription = "stress test"; vm.ProjectName = "Second project"; vm.ScenarioUriOne = "http://www.hello.com"; vm.ScenarioUriTwo = "http://www.seeyou.com"; vm.StartDateUtc = DateTime.UtcNow.AddDays(2); vm.UserCount = 60; IList<LoadtestViewModel> vms = new List<LoadtestViewModel>() { vm }; IList<Loadtest> loadtests = viewModelRepo.ConvertToDomain(vms); }
public IList<LoadtestViewModel> ConvertToViewModels(IEnumerable<Loadtest> domains) { List<LoadtestViewModel> viewModels = new List<LoadtestViewModel>(); LoadTestingContext context = LoadTestingContext.Create(base.ConnectionStringRepository); foreach (Loadtest lt in domains) { LoadtestViewModel vm = new LoadtestViewModel(); vm.Id = lt.Id; AgentMongoDb agentDb = context.Agents.Find<AgentMongoDb>(a => a.DomainId == lt.AgentId).SingleOrDefault(); if (agentDb == null) throw new ArgumentException("There is no load test agent with the given ID."); vm.AgentCountry = agentDb.Location.Country; vm.AgentCity = agentDb.Location.City; CustomerMongoDb custDb = context.Customers.Find<CustomerMongoDb>(c => c.DomainId == lt.CustomerId).SingleOrDefault(); if (custDb == null) throw new ArgumentException("There is no customer with the given ID."); vm.CustomerName = custDb.Name; if (lt.EngineerId.HasValue) { EngineerMongoDb engDb = context.Engineers.Find<EngineerMongoDb>(e => e.DomainId == lt.EngineerId.Value).SingleOrDefault(); if (engDb == null) throw new ArgumentException("There is no engineer with the given ID."); vm.EngineerName = engDb.Name; } LoadtestTypeMongoDb loadtestTypeDb = context.LoadtestTypes.Find(l => l.DomainId == lt.LoadtestTypeId).SingleOrDefault(); if (loadtestTypeDb == null) throw new ArgumentException("There is no load test type with the given ID."); vm.LoadtestTypeShortDescription = loadtestTypeDb.Description.ShortDescription; ProjectMongoDb projectDb = context.Projects.Find(p => p.DomainId == lt.ProjectId).SingleOrDefault(); if (projectDb == null) throw new ArgumentException("There is no project with the given ID."); vm.ProjectName = projectDb.Description.ShortDescription; ScenarioMongoDb scenarioDb = context.Scenarios.Find(s => s.DomainId == lt.ScenarioId).SingleOrDefault(); if (scenarioDb == null) throw new ArgumentException("There is no scenario with the given ID."); vm.ScenarioUriOne = scenarioDb.UriOne; vm.ScenarioUriTwo = scenarioDb.UriTwo; vm.ScenarioUriThree = scenarioDb.UriThree; vm.UserCount = lt.Parameters.UserCount; vm.StartDateUtc = lt.Parameters.StartDateUtc; vm.DurationSec = lt.Parameters.DurationSec; viewModels.Add(vm); } return viewModels; }