private TestSuite(string testEnginePath, TestSuiteInstallation testSuiteInstallation, IStorageNode storageRoot) { TestEnginePath = testEnginePath; Id = testSuiteInstallation.Id; Name = testSuiteInstallation.Name; Description = testSuiteInstallation.Description; Removed = testSuiteInstallation.Removed; InstallMethod = testSuiteInstallation.InstallMethod; Version = testSuiteInstallation.Version; StorageRoot = storageRoot; // check if Plugin/config.xml can be found in TestSuite, if not then throw a new exception. string configXmlPath = Path.Combine(StorageRoot.GetNode(TestSuiteConsts.PluginFolderName).AbsolutePath, TestSuiteConsts.PluginConfigXml); if (!File.Exists(configXmlPath)) { throw new Exception($"TestSuite requires plugin xml:{configXmlPath}!"); } this.TestSuiteConfigFilePath = configXmlPath; }
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 async Task AddOne() { // Add by pool1 var repo1 = pool1.Get <TestSuiteInstallation>(); var item = new TestSuiteInstallation { Name = "Test", }; repo1.Insert(item); await pool1.Save(); // Get by pool2 var repo2 = pool2.Get <TestSuiteInstallation>(); var result = repo2.Get(q => q.Where(t => t.Id == item.Id)); Assert.AreEqual(1, result.Count()); Assert.AreEqual(item.Id, result.First().Id); Assert.AreEqual(item.Name, result.First().Name); }
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; } }
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]); }