예제 #1
0
        private AddOrUpdateLoadtestsResponse AddOrUpdateLoadTests(AddOrUpdateLoadtestsRequest request)
        {
            AddOrUpdateLoadtestsResponse resp = new AddOrUpdateLoadtestsResponse();

            try
            {
                foreach (LoadTestViewModel vm in request.Loadtests)
                {
                    if (vm.Id == null || vm.Id == default(Guid))
                    {
                        vm.Id = Guid.NewGuid();
                    }
                }

                List <LoadTestViewModel> sortedByDate    = request.Loadtests.OrderBy(l => l.StartDateUtc).ToList();
                LoadTestViewModel        last            = sortedByDate.Last();
                IList <LoadTest>         loadtests       = _timetableRepository.GetLoadTestsForTimePeriod(sortedByDate.First().StartDateUtc, last.StartDateUtc.AddSeconds(last.DurationSec));
                Timetable        timetable               = new Timetable(loadtests);
                IList <LoadTest> loadtestsAddedOrUpdated = _timetableViewModelRepository.ConvertToDomain(request.Loadtests);
                AddOrUpdateLoadTestsValidationResult validationResult = timetable.AddOrUpdateLoadTests(loadtestsAddedOrUpdated);
                _timetableRepository.AddOrUpdateLoadTests(validationResult);
                resp.AddOrUpdateLoadtestsValidationResult = validationResult;
            }
            catch (Exception ex)
            {
                resp.Exception = ex;
            }

            return(resp);
        }
예제 #2
0
        public void CanExecuteIsTrueByDefault()
        {
            var viewModel = new LoadTestViewModel();

            var command = new RunLoadTestCommand(viewModel);

            Assert.IsTrue(command.CanExecute(null));
        }
예제 #3
0
        public LoadTestViewModel ConvertToViewModel()
        {
            LoadTestViewModel ltVm = new LoadTestViewModel();

            if (Id == null || Id == default(Guid))
            {
                Id = Guid.NewGuid();
            }
            if (string.IsNullOrEmpty(AgentCity))
            {
                throw new ArgumentNullException("Agent city must be provided.");
            }
            if (string.IsNullOrEmpty(AgentCountry))
            {
                throw new ArgumentNullException("Agent country must be provided.");
            }
            if (string.IsNullOrEmpty(CustomerName))
            {
                throw new ArgumentNullException("Customer name must be provided.");
            }
            if (string.IsNullOrEmpty(LoadtestTypeShortDescription))
            {
                throw new ArgumentNullException("Load test type must be provided.");
            }
            if (string.IsNullOrEmpty(ProjectName))
            {
                throw new ArgumentNullException("Project name must be provided.");
            }
            if (string.IsNullOrEmpty(ScenarioUriOne))
            {
                throw new ArgumentNullException("At least one URL must be provided for the scenario.");
            }
            ltVm.AgentCity    = AgentCity;
            ltVm.AgentCountry = AgentCountry;
            ltVm.CustomerName = CustomerName;
            ltVm.DurationSec  = DurationSec;
            ltVm.EngineerName = EngineerName;
            ltVm.Id           = Id;
            ltVm.LoadTestTypeShortDescription = LoadtestTypeShortDescription;
            ltVm.ProjectName      = ProjectName;
            ltVm.ScenarioUriOne   = ScenarioUriOne;
            ltVm.ScenarioUriTwo   = ScenarioUriTwo;
            ltVm.ScenarioUriThree = ScenarioUriThree;

            DateTime     customerDate     = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, StartDate.Hour, StartDate.Minute, 0);
            TimeZoneInfo customerTimeZone = TimeZoneInfo.FindSystemTimeZoneById(StartDate.Timezone);

            ltVm.StartDateUtc = TimeZoneInfo.ConvertTimeToUtc(customerDate, customerTimeZone);
            ltVm.UserCount    = UserCount;

            return(ltVm);
        }
예제 #4
0
        private static void WaitForLoadTestResult(LoadTestViewModel viewModel)
        {
            var start = DateTime.Now;

            while (viewModel.Result == null)
            {
                if (DateTime.Now.Subtract(start) > TimeSpan.FromSeconds(5))
                {
                    throw new TimeoutException();
                }

                Thread.Sleep(TimeSpan.FromMilliseconds(1));
            }
        }
예제 #5
0
파일: Program.cs 프로젝트: Jaxelr/NLoad
        static void Main()
        {
            var app = new Application();

            var loadTests = GetLoadTests(Assembly.GetExecutingAssembly());

            var viewModel = new LoadTestViewModel(loadTests);

            var window = new LoadTestWindow
            {
                DataContext = viewModel
            };

            app.Run(window);
        }
예제 #6
0
        public void ShouldUpdateViewModel()
        {
            var viewModel = new LoadTestViewModel
            {
                SelectedTestType = typeof(InMemoryTest100),
                Configuration    = new LoadTestConfiguration
                {
                    NumberOfThreads = 1,
                    Duration        = TimeSpan.FromSeconds(1)
                }
            };

            var runLoadTestCommand = new RunLoadTestCommand(viewModel);

            runLoadTestCommand.Execute(null);

            WaitForLoadTestResult(viewModel);

            Assert.IsNotNull(viewModel.Heartbeat);
            Assert.IsNotNull(viewModel.Heartbeats);
            Assert.IsTrue(viewModel.Heartbeats.Any());
        }
        public IList <LoadTestViewModel> ConvertToViewModel(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 = context.Agents.FirstOrDefault(a => a.Id == lt.Id);
                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 = context.Customers.FirstOrDefault(c => c.Id == lt.CustomerId);
                if (customer == null)
                {
                    throw new ArgumentException("There is no customer with the given ID.");
                }
                vm.CustomerName = customer.Name;

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

                LoadTestType loadTestType = context.LoadTestTypes.FirstOrDefault(t => t.Id == lt.LoadTestTypeId);
                if (loadTestType == null)
                {
                    throw new ArgumentException("There is no load test type with the given ID.");
                }
                vm.LoadTestTypeShortDescription = loadTestType.Description.ShortDescription;

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

                Scenario scenario = context.Scenarios.FirstOrDefault(s => s.Id == lt.ScenarioId);
                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);
        }