public ITestRun[] QueryTestRuns(int pageSize, int pageIndex, Func <TestResult, bool> queryFunc, out int totalPage) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestResult>(); var all = repo.Get(q => q.Where(queryFunc).OrderByDescending(item => item.Id).AsQueryable()).Select(item => GetTestRunInternal(item.Id, item)); int count = all.Count(); if (count % pageSize == 0) { totalPage = count / pageSize; } else { totalPage = count / pageSize + 1; } var result = all.Skip(pageSize * pageIndex).Take(pageSize); return(result.ToArray()); }
public int CreateTestRun(int configurationId, string[] selectedTestCases) { var configuration = GetConfiguration(configurationId); using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestResult>(); var testResult = new TestResult { TestSuiteConfigurationId = configurationId, State = TestResultState.Created, }; repo.Insert(testResult); pool.Save().Wait(); int id = testResult.Id; var testRun = TestRun.Create(Options.TestEnginePath, testResult, configuration, StoragePool, Update); repo.Update(testResult); pool.Save().Wait(); testRun.Run(selectedTestCases); TestRunPool.AddOrUpdate(id, _ => testRun, (_, _) => testRun); return(id); }
public void UpdateTestSuite(int id, string name, string packageName, Stream package, string description) { var extractNode = ExtractPackage(packageName, package, StoragePool); var version = GetTestSuiteVersion(extractNode); if (!CheckTestSuiteVersion(version)) { extractNode.DeleteNode(); throw new NotSupportedException($"PTMService only supports version {TestSuiteConsts.SupportedMinVersion} or above version, you could try use PTMGUI to run previous versions"); } using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteInstallation>(); var testSuiteInstallation = repo.Get(q => q.Where(item => item.Id == id)).First(); testSuiteInstallation.Name = name; testSuiteInstallation.InstallMethod = TestSuiteInstallMethod.UploadPackage; testSuiteInstallation.Description = description; var testSuite = TestSuite.Update(Options.TestEnginePath, testSuiteInstallation, extractNode, StoragePool, version); repo.Update(testSuiteInstallation); pool.Save().Wait(); TestSuitePool.AddOrUpdate(id, _ => testSuite, (_, _) => testSuite); }
public void RemoveTestSuite(int id) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteInstallation>(); var testSuite = GetTestSuite(id); testSuite.Removed = true; var removedTestSuiteInstallation = new TestSuiteInstallation { Id = id, Name = testSuite.Name, Version = testSuite.Version, InstallMethod = testSuite.InstallMethod, Description = testSuite.Description, Path = testSuite.StorageRoot.AbsolutePath, Removed = testSuite.Removed, }; repo.Update(removedTestSuiteInstallation); pool.Save().Wait(); TestSuitePool.AddOrUpdate(id, _ => testSuite, (_, _) => testSuite); ThreadPool.QueueUserWorkItem(_ => { var flagFilePath = Path.Combine(testSuite.StorageRoot.AbsolutePath, "removed"); File.WriteAllText(flagFilePath, $"Removed at {DateTime.Now}"); }); }
public bool IsTestSuiteRunning() { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestResult>(); return(repo.Get(q => q.Where(r => r.State == TestResultState.Running)).Any()); }
public int InstallTestSuite(string name, string packageName, Stream package, string description) { var extractNode = ExtractPackage(packageName, package, StoragePool); var version = GetTestSuiteVersion(extractNode); if (!CheckTestSuiteVersion(version)) { extractNode.DeleteNode(); throw new NotSupportedException($"PTMService only supports version {TestSuiteConsts.SupportedMinVersion} or above version, you could try use PTMGUI to run previous versions"); } using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteInstallation>(); var testSuiteInstallation = new TestSuiteInstallation { Name = name, InstallMethod = TestSuiteInstallMethod.UploadPackage, Description = description, Version = version }; try { repo.Insert(testSuiteInstallation); pool.Save().Wait(); int id = testSuiteInstallation.Id; var testSuiteNode = StoragePool.GetKnownNode(KnownStorageNodeNames.TestSuite).CreateNode(id.ToString()); testSuiteNode.CopyFromNode(extractNode, true); testSuiteInstallation.Path = testSuiteNode.AbsolutePath; var testSuite = TestSuite.Create(Options.TestEnginePath, testSuiteInstallation, testSuiteNode); repo.Update(testSuiteInstallation); pool.Save().Wait(); TestSuitePool.AddOrUpdate(id, _ => testSuite, (_, _) => testSuite); return(id); } catch { repo.Remove(testSuiteInstallation); pool.Save().Wait(); throw; } }
public ITestSuite[] QueryTestSuites() { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteInstallation>(); var result = repo.Get(q => q).Select(item => GetTestSuiteInternal(item.Id, item)).ToArray(); return(result); }
private void Update(int id, Action <TestResult> updater) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestResult>(); var testResult = repo.Get(q => q.Where(item => item.Id == id)).First(); updater(testResult); repo.Update(testResult); pool.Save().Wait(); }
private ITestSuite GetTestSuiteInternal(int id, TestSuiteInstallation testSuiteInstallation) { if (!TestSuitePool.ContainsKey(id)) { if (testSuiteInstallation == null) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteInstallation>(); testSuiteInstallation = repo.Get(q => q.Where(item => item.Id == id)).First(); } var testSuite = TestSuite.Open(Options.TestEnginePath, testSuiteInstallation, StoragePool); TestSuitePool.AddOrUpdate(id, _ => testSuite, (_, _) => testSuite); } return(TestSuitePool[id]); }
private IConfiguration GetConfigurationInternal(int id, TestSuiteConfiguration testSuiteConfiguration) { if (!ConfigurationPool.ContainsKey(id)) { if (testSuiteConfiguration == null) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteConfiguration>(); testSuiteConfiguration = repo.Get(q => q.Where(i => i.Id == id)).First(); } var configuration = Configuration.Open(testSuiteConfiguration, GetTestSuite(testSuiteConfiguration.TestSuiteId), StoragePool); ConfigurationPool.AddOrUpdate(id, _ => configuration, (_, _) => configuration); } return(ConfigurationPool[id]); }
public int CreateConfiguration(string name, int testSuiteId, string description) { var tesSuite = GetTestSuite(testSuiteId); using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteConfiguration>(); var testSuiteConfiguration = new TestSuiteConfiguration { Name = name, TestSuiteId = testSuiteId, Description = description, }; repo.Insert(testSuiteConfiguration); pool.Save().Wait(); int id = testSuiteConfiguration.Id; try { var configuration = Configuration.Create(testSuiteConfiguration, tesSuite, StoragePool); repo.Update(testSuiteConfiguration); ConfigurationPool.AddOrUpdate(id, _ => configuration, (_, _) => configuration); } catch { repo.Remove(testSuiteConfiguration); throw; } finally { pool.Save().Wait(); } return(id); }
private ITestRun GetTestRunInternal(int id, TestResult testResult) { if (!TestRunPool.ContainsKey(id)) { if (testResult == null) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestResult>(); testResult = repo.Get(q => q.Where(item => item.Id == id)).First(); } var configuration = GetConfiguration(testResult.TestSuiteConfigurationId); var testRun = TestRun.Open(Options.TestEnginePath, testResult, configuration, StoragePool, Update); TestRunPool.AddOrUpdate(id, _ => testRun, (_, _) => testRun); } return(TestRunPool[id]); }
public IConfiguration[] QueryConfigurations(int?testSuiteId) { using var instance = ScopedServiceFactory.GetInstance(); var pool = instance.ScopedServiceInstance; var repo = pool.Get <TestSuiteConfiguration>(); var result = repo.Get(q => { if (testSuiteId == null) { return(q); } else { return(q.Where(i => i.TestSuiteId == testSuiteId.Value)); } }).Select(item => GetConfigurationInternal(item.Id, item)); return(result.ToArray()); }