/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The model to connect to</param> /// <param name="view">The view to connect to</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.grid = view as IGridView; this.grid.ContextItemsNeeded += GetContextItems; this.model = model as Model; this.explorerPresenter = explorerPresenter; // if the model is Testable, run the test method. ITestable testModel = model as ITestable; if (testModel != null) { testModel.Test(false, true); this.grid.ReadOnly = true; } this.grid.NumericFormat = "G6"; grid.CanGrow = false; this.childrenWithSameType = this.GetChildModelsWithSameType(this.model); this.FindAllPropertiesForChildren(); if (this.grid.DataSource == null) { this.PopulateGrid(this.model); } else { this.FormatTestGrid(); } this.grid.CellsChanged += this.OnCellValueChanged; this.grid.ButtonClick += this.OnFileBrowseClick; this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; }
private ITestable Build(string curr, string appname, Size viewport) { string jenkinsJobName = Environment.GetEnvironmentVariable("JOB_NAME"); string jenkinsApplitoolsBatchId = Environment.GetEnvironmentVariable("APPLITOOLS_BATCH_ID"); Batch jenkinsBatch = null; if ((jenkinsJobName != null) && (jenkinsApplitoolsBatchId != null)) { BatchInfo batch = new BatchInfo(jenkinsJobName); batch.Id = jenkinsApplitoolsBatchId; jenkinsBatch = new Batch(batch); } ITestable unit = Build(curr, appname, viewport, jenkinsBatch); if (unit is ImageStep) { ImageStep step = (ImageStep)unit; Test test = new Test(step.GetFile(), appname, this.viewport); test.AddStep(step); unit = test; } if (unit is Test && jenkinsBatch != null) { jenkinsBatch.AddTest((Test)unit); return(jenkinsBatch); } else { return(unit); } }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The model to connect to</param> /// <param name="view">The view to connect to</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public override void Attach(object model, object view, ExplorerPresenter explorerPresenter) { base.Attach(model, view, explorerPresenter); grid.ContextItemsNeeded += GetContextItems; grid.CanGrow = false; this.model = model as Model; intellisense = new IntellisensePresenter(grid as ViewBase); // The grid does not have control-space intellisense (for now). intellisense.ItemSelected += OnIntellisenseItemSelected; // if the model is Testable, run the test method. ITestable testModel = model as ITestable; if (testModel != null) { testModel.Test(false, true); grid.ReadOnly = true; } grid.NumericFormat = "G6"; FindAllProperties(this.model); if (grid.DataSource == null) { PopulateGrid(this.model); } else { FormatTestGrid(); } grid.CellsChanged += OnCellValueChanged; grid.ButtonClick += OnFileBrowseClick; this.presenter.CommandHistory.ModelChanged += OnModelChanged; }
public static TestResult Replay(ulong seed, int size, ITestable test) { Console.WriteLine( "Replaying test with seed: ({0}, {1})", seed, size); IRandom random = s_RandomFactory.NewRandom(seed); return(test.RunTest(random, size)); }
private ITestable GetTestable(WorkItem workItem, TestcaseProvider testcaseProvider) { object branchSpecificFileLock = _testFileLocker.GetLock(workItem.Testsystem.Name); lock (branchSpecificFileLock) { ITestable testable = testcaseProvider.GetTestableFromTypeName(workItem.Testcase.Type); return(testable); } }
public static void ValDesc(this ITestable ele, string choice) { if (choice == "ext def") { Console.WriteLine($"Base.Ext.Ext.GetDesc: {ele.GetDesc()}"); } else if (choice == "ext base" && ele is BaseTest b) { Console.WriteLine($"Base.Ext.Base.GetDesc: {b.BaseFunc()}"); } }
public static void RunTest(string testName, ITestable test, ResultWriter writer) { Console.WriteLine("{0} start", testName); var times = new long[NR_ITERATIONS]; for (int n = 0; n < NR_ITERATIONS; n++) { test.Setup(); Console.WriteLine("{0} iteration {1} start", testName, n); var stopwatch = Stopwatch.StartNew(); test.Perform(); stopwatch.Stop(); times[n] = stopwatch.ElapsedMilliseconds; GC.Collect(); } Console.WriteLine("{0} end", testName); long low = long.MaxValue, high = long.MinValue; int lowIndex = 0, highIndex = 0; for (int i = 0; i < NR_ITERATIONS; i++) { var time = times[i]; if (time > high) { high = time; highIndex = i; } if (time < low) { low = time; lowIndex = i; } } var finalTimes = new List <long>(); for (int i = 0; i < NR_ITERATIONS; i++) { if (i != lowIndex && i != highIndex) { finalTimes.Add(times[i]); } } var t1 = Math.Pow(4, 2); var mean = (double)finalTimes.Sum() / (double)finalTimes.Count; var stdv = Math.Sqrt(finalTimes.Sum(t => (t - mean) * (t - mean)) / (finalTimes.Count - 1)); writer.WriteResult(mean, stdv, testName); }
public static void SelectAddOp(string var, ITestable testable, Action updateAction, bool test = true) { if (var == null) { updateAction.Invoke(); return; } VarTests tests = testable.Tests; List <VarOperation> operations = testable.Operations; VarOperation op = new VarOperation(); op.var = var; op.operation = "="; if (test) { op.operation = ">"; } op.value = "0"; if (op.var.Equals("{NEW}")) { // Var name doesn localize var textEdit = new QuestEditorTextEdit(CommonStringKeys.VAR_NAME, "", s => NewVar(s, op, test, testable, updateAction)); textEdit.EditText(); } else { if (test) { if (tests.VarTestsComponents.Count == 0) { tests.Add(op); } else { tests.Add(new VarTestsLogicalOperator()); tests.Add(op); } } else { operations.Add(op); } updateAction.Invoke(); } }
/// <summary> /// Returns a new created ITestable for a given type /// </summary> /// <param name="typeName">type of testcase</param> /// <returns>a new ITestable or null on error</returns> public ITestable GetTestableFromTypeName(String typeName) { try { ITestableFactory testableFactory = (ITestableFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TestableFactory").Unwrap(); object[] constructArgs = new object[] { }; ITestable testable = testableFactory.Create(_testsFile, typeName, constructArgs); return(testable); } catch (Exception exception) { Console.WriteLine(exception.ToString()); return(null); } }
void IBuildTaskService.SendTestcaseFile(string testsystemName, byte[] data) { object _lock = _testFileLocker.GetLock(testsystemName); lock (_lock) { Testsystem testsystem = _testsystemRepository.GetByName(testsystemName); testsystem.LastUpdated = DateTime.Now; _testsystemRepository.Store(testsystem); string testFile = RegtestingServerConfiguration.Testsfolder + testsystem.Filename; Directory.CreateDirectory(Path.GetDirectoryName(testFile)); using (FileStream fileStream = new FileStream(testFile, FileMode.Create, FileAccess.Write)) { fileStream.Write(data, 0, data.Length); } Logger.Log("UPDATE branch: " + testsystemName); TestcaseProvider testcaseProvider = new TestcaseProvider(testFile); testcaseProvider.CreateAppDomain(); foreach (string testcaseType in testcaseProvider.Types) { ITestable testable = testcaseProvider.GetTestableFromTypeName(testcaseType); if (testable == null) { continue; } Testcase testcase = _testcaseRepository.GetByType(testcaseType); string testableName = testable.GetName(); if (testcase == null) { Logger.Log("New test: " + testableName); testcase = new Testcase { Name = testableName, Type = testcaseType }; _testcaseRepository.Store(testcase); } else if (!testcase.Name.Equals(testableName)) { Logger.Log("Renamed test: " + testcase.Name + " to " + testableName); testcase.Name = testableName; _testcaseRepository.Store(testcase); } } testcaseProvider.Unload(); } }
private bool IsWorkItemSupported(WorkItem workItem, ITestable testable) { string[] supportedLanguages = testable.GetSupportedLanguages(); if (supportedLanguages != null && !supportedLanguages.Contains(workItem.Language.Languagecode, StringComparer.InvariantCultureIgnoreCase)) { return(false); } string[] supportedBrowsers = testable.GetSupportedBrowsers(); if (supportedBrowsers != null && !supportedBrowsers.Contains(workItem.Browser.Name, StringComparer.InvariantCultureIgnoreCase)) { return(false); } return(true); }
/// <summary> /// Start a Test and throw exception in errorcase /// </summary> /// <param name="typeName">typename of testcase to load</param> /// <param name="testsystem">string with the testsystem</param> /// <param name="language">string with the language</param> /// <param name="browser"></param> internal void InitializeTest(string typeName, string testsystem, string language, Browser browser) { TestHeader = String.Format("Testcase: {0} ({1}, {2}) on {3}", typeName, language, browser, testsystem); _testable = _testcaseProvider.GetTestableFromTypeName(typeName); _testable.GetLogLastTime(); _testable.SetupTest(WebDriverInitStrategy.SeleniumLocal, browser, testsystem, language); try { _testable.Test(); } catch (TaskCanceledException) { //Test is canceled. Do normal teardown } _testable.TeardownTest(); }
public static void TestMethod(this ITestable item, string testString) { if (testString == "blue") { item.RunA(); } else if (testString == "red") { item.RunB(); } else if (testString == "orange") { item.RunA(); } else if (testString == "pink") { item.RunB(); } }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The model to connect to</param> /// <param name="view">The view to connect to</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.grid = view as IGridView; this.grid.ContextItemsNeeded += GetContextItems; this.model = model as Model; this.explorerPresenter = explorerPresenter; this.intellisense = new IntellisensePresenter(grid as ViewBase); // The grid does not have control-space intellisense (for now). intellisense.ItemSelected += (sender, e) => grid.InsertText(e.ItemSelected); // if the model is Testable, run the test method. ITestable testModel = model as ITestable; if (testModel != null) { testModel.Test(false, true); this.grid.ReadOnly = true; } string[] split; this.grid.NumericFormat = "G6"; this.FindAllProperties(this.model); if (this.grid.DataSource == null) { this.PopulateGrid(this.model); } else { this.grid.ResizeControls(); this.FormatTestGrid(); } this.grid.CellsChanged += this.OnCellValueChanged; this.grid.ButtonClick += this.OnFileBrowseClick; this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; if (model != null) { split = this.model.GetType().ToString().Split('.'); this.grid.ModelName = split[split.Length - 1]; this.grid.LoadImage(); } }
public static void RunTest(this ITestable testable) { Condition.Requires(testable).IsNotNull(); var tests = testable.GetTests(); var testStore = testable.GenerateTestInput(); IStore testResultsStore = NaturalInMemoryStore.New(); tests.HandleOperations(testStore, testResultsStore); var errors = tests.GetErrors(testResultsStore); if (errors != null && errors.Count > 0) { //output the stores testResultsStore.JoinStore(testStore); var dump = StoreSerializer.SerializeStore(testResultsStore, ValueManagerChainOfResponsibility.NewDefault()); Debug.WriteLine(dump); throw new InvalidOperationException("test failure"); } }
/// <summary> /// Times the action passed in and sets status in case of exceptions. /// </summary> /// <param name="action">The method that is being timed.</param> /// <param name="timeVal">The holder for the timing</param> /// <param name="status">The status to set in the event of an exception.</param> /// <param name="testable">The testable object that provides message buffers.</param> /// <returns></returns> public static bool Time( Func<bool> action, ref long timeVal, ref TestStatus status, ITestable testable) { try { Stopwatch stopwatch = Stopwatch.StartNew(); bool success = action.Invoke(); timeVal = stopwatch.Elapsed.Seconds; //TODO - log Milliseconds; or seconds switch. return success; } catch (Exception e) { new MsgBufferWriter(testable).Write(e.Message); VerboseMsgWriter writer = new VerboseMsgWriter(testable); writer.Write(e.GetType().Name); DumpStackTrace(e, writer); status = TestStatus.FAIL_BY_EXCEPTION; return false; } }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The model to connect to</param> /// <param name="view">The view to connect to</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.grid = view as IGridView; this.model = model as Model; this.explorerPresenter = explorerPresenter; // if the model is Testable, run the test method. ITestable testModel = model as ITestable; if (testModel != null) { testModel.Test(false, true); this.grid.ReadOnly = true; } string[] split; grid.NumericFormat = "G6"; this.FindAllProperties(this.model); if (this.grid.DataSource == null) { this.PopulateGrid(this.model); } else { this.grid.ResizeControls(); FormatTestGrid(); } this.grid.CellsChanged += this.OnCellValueChanged; this.grid.ButtonClick += OnFileBrowseClick; this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; if (model != null) { split = this.model.GetType().ToString().Split('.'); this.grid.ModelName = split[split.Length - 1]; this.grid.LoadImage(); } }
public static Result Test(ITestable test) { const int maxSuccess = 250; const int maxSize = 100; int i; for (i = 0; i < maxSuccess; i++) { ulong seed; IRandom random = s_RandomFactory.NewRandom(out seed); int size = i % maxSize + 1; TestResult result = test.RunTest(random, size); if (result.IsFailure) { return(Result.Failure(i + 1, seed, size, result.Args, result.Error)); } } return(Result.Success(i + 1)); }
private static void AddTestOp(ITestable testable, Action updateAction) { UIWindowSelectionListTraits select = new UIWindowSelectionListTraits( s => SelectAddOp(s, testable, updateAction), new StringKey("val", "SELECT", CommonStringKeys.VAR), true); Dictionary <string, IEnumerable <string> > traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { "Quest" }); @select.AddItem("{" + CommonStringKeys.NEW.Translate() + "}", "{NEW}", traits, true); AddQuestVars(@select); traits = new Dictionary <string, IEnumerable <string> >(); traits.Add(CommonStringKeys.TYPE.Translate(), new string[] { "#" }); @select.AddItem("#monsters", traits); @select.AddItem("#heroes", traits); @select.AddItem("#round", traits); @select.AddItem("#eliminated", traits); foreach (ContentData.ContentPack pack in Game.Get().cd.allPacks) { if (pack.id.Length > 0) { @select.AddItem("#" + pack.id, traits); } } foreach (HeroData hero in Game.Get().cd.Values <HeroData>()) { if (hero.sectionName.Length > 0) { @select.AddItem("#" + hero.sectionName, traits); } } @select.Draw(); }
private static void NewVar(string value, VarOperation op, bool test, ITestable testable, Action updateAction) { op.var = System.Text.RegularExpressions.Regex.Replace(value, "[^A-Za-z0-9_]", ""); if (op.var.Length > 0) { if (value[0] == '%') { op.var = '%' + op.var; } if (value[0] == '@') { op.var = '@' + op.var; } if (char.IsNumber(op.var[0]) || op.var[0] == '-' || op.var[0] == '.') { op.var = "var" + op.var; } if (test) { if (testable.Tests.VarTestsComponents.Count == 0) { testable.Tests.Add(op); } else { testable.Tests.Add(new VarTestsLogicalOperator()); testable.Tests.Add(op); } } else { testable.Operations.Add(op); } } updateAction.Invoke(); }
/// <summary>Write the line entry for the log output.</summary> /// <param name="testable">The test case object to log.</param> /// <returns></returns> protected abstract bool WriteEntry(ITestable testable);
/// <summary>Log the results of one test case across log outputs.</summary> /// <param name="testable">The test case to be logged.</param> private void LogResults(ITestable testable) { if (testable == null) { throw new ArgumentNullException("theCase", "theCase cannot be null"); } this.logEngine.Log(testable); }
/// <summary>Register a test case to the system for later recall.</summary> /// <param name="testable">The testable to register.</param> /// <exception cref="ArgumentNullException">On null testable.</exception> public void RegisterCase(ITestable testable) { // TODO Trace - if any of these exceptions are thrown we get an error that exception // thrown by target of an invokation. // The exception is being thrown in the same assembly and not the loaded dll so I // am not sure what is going on. // However, it is being thrown out of the TestHarness.dll and caught in the ConsoleTester.exe // so there may be something there. if (testable == null) { throw new ArgumentNullException( "newCase", "Param cannot be null" ); } else if (this.testCases.ContainsKey(testable.Id)) { throw new ArgumentException("Cannot register duplicate test ID", testable.Id); } this.testCases.Add(testable.Id, testable); }
private bool IsWorkItemSupported(WorkItem workItem, ITestable testable) { string[] supportedLanguages = testable.GetSupportedLanguages(); if (supportedLanguages != null && !supportedLanguages.Contains(workItem.Language.Languagecode, StringComparer.InvariantCultureIgnoreCase)) return false; string[] supportedBrowsers = testable.GetSupportedBrowsers(); if (supportedBrowsers != null && !supportedBrowsers.Contains(workItem.Browser.Name, StringComparer.InvariantCultureIgnoreCase)) return false; return true; }
protected virtual object RunTestCase(ITestable testable, TestCase test) { return(testable.RunTest(test.Parameter)); }
private TestResult HandleTest(WorkItem workItem) { TestResult testResult = new TestResult(); ITestable testable = null; List <string> log = new List <string>(); try { log.Add("Test on " + _nodename); /**1: Load Testclass **/ Console.WriteLine(@"Testing {0} {1} ({2}/{3})", workItem.Testcase.Name, workItem.Browser.Name, workItem.Testsystem.Name, workItem.Language.Languagecode); testable = LoadTestable(workItem); if (testable == null) { return new TestResult { TestState = TestState.NotAvailable } } ; /**2: Wait for branch get ready **/ WaitOnWebExceptions(workItem); /**3: Prepare Test **/ Browser browser = new Browser() { Browserstring = workItem.Browser.Browserstring, Versionsstring = workItem.Browser.Versionsstring }; testable.SetupTest(WebDriverInitStrategy.SeleniumLocal, browser, workItem.Testsystem.Url, workItem.Language.Languagecode); /**4: Run Test **/ testable.Test(); testResult.TestState = TestState.Success; } catch (NotSupportedException notSupportedException) { Error error = CreateErrorFromException(notSupportedException); testResult.TestState = TestState.NotSupported; testResult.Error = error; } catch (TaskCanceledException taskCanceledException) { Error error = CreateErrorFromException(taskCanceledException); testResult.TestState = TestState.Canceled; testResult.Error = error; } catch (Exception exception) { ServerErrorModel serverException = null; try { if (testable != null) { serverException = testable.CheckForServerError(); } } catch { //Error catching serverException } Error error = CreateErrorFromException(exception); if (serverException != null) { error.Type = serverException.Type; error.Message = serverException.Message; error.InnerException = serverException.InnerException; //objError.StackTrace = serverException.StackTrace; Keep error stacktrace. } testResult.TestState = TestState.Error; testResult.Error = error; if (testable != null) { testResult.Screenshot = testable.SaveScreenshot(""); } } finally { if (testable != null) { testable.TeardownTest(); log.AddRange(testable.GetLogLastTime()); } testResult.Log = log; } return(testResult); }
/// <summary>Log the test case information across all loggers.</summary> /// <param name="testable">The testable object to run and log.</param> /// <returns>true if successful, otherwise false.</returns> public bool Log(ITestable testable) { if (testable == null) { throw new ArgumentNullException("testable", "theCase cannot be null"); } foreach (ILogable log in this.logs) { log.LogTestable(testable); } return true; }
public void RegisterTest(ITestable testable) { TestEngine.GetInstance().RegisterCase(testable); }
private void AddTestJobImpl(ITestJobManager testJobManager, ICollection <WorkItem> workItems) { TestcaseProvider testcaseProvider; object branchSpecificFileLock = _testFileLocker.GetLock(testJobManager.TestJob.Testsystem.Name); lock (branchSpecificFileLock) { testcaseProvider = new TestcaseProvider(RegtestingServerConfiguration.Testsfolder + testJobManager.TestJob.Testsystem.Filename); testcaseProvider.CreateAppDomain(); } _testJobRepository.Store(testJobManager.TestJob); lock (_lockWorkItems) { List <WorkItem> alreadyFoundWorkItems = new List <WorkItem>(); List <Result> updatedResults = new List <Result>(); foreach (WorkItem workItem in workItems) { ITestable testable = GetTestable(workItem, testcaseProvider); if (testable == null) { updatedResults.Add(UpdateResultInfos(workItem, testJobManager.TestJob, TestState.NotAvailable)); continue; } if (!IsWorkItemSupported(workItem, testable)) { updatedResults.Add(UpdateResultInfos(workItem, testJobManager.TestJob, TestState.NotSupported)); continue; } WorkItem existingWorkItem = CheckForAlreadyQueyedWorkItems(workItem); if (existingWorkItem != null) { existingWorkItem.AddTestJobManager(testJobManager); alreadyFoundWorkItems.Add(existingWorkItem); } else { testJobManager.AddWorkItem(workItem); updatedResults.Add(UpdateResultInfos(workItem, testJobManager.TestJob, TestState.Pending)); } } //If there is nothing to test, don't add a testsuite if (testJobManager.Count == 0 && alreadyFoundWorkItems.Count == 0) { return; } _currentTestJobManagers.Add(testJobManager); //Add new workItems to waiting list testJobManager.WorkItems.ForEach(_waitingWorkItems.Add); //Add already found workItems back to alreadyFoundWorkItems.ForEach(testJobManager.AddWorkItem); _resultRepository.Store(updatedResults); } }
public SpeedTest(ITestable test) { this.test = test; stopWatch = new Stopwatch(); }
private static void SelectAddParenthesis(ITestable testable, Action updateAction) { testable.Tests.Add(new VarTestsParenthesis(")")); testable.Tests.Add(new VarTestsParenthesis("(")); updateAction.Invoke(); }
private void DoTest() { ITestable test = tvProjects.SelectedNode.Tag as ITestable; test.Test(); }
/// <see cref="Logs.LogTestable"/> public bool LogTestable(ITestable testable) { switch(testable.Status) { case TestStatus.SUCCESS: ++successCount; if (!this.logInfo.LogSuccessCases) { return true; } break; case TestStatus.FAIL_INIT: ++failInitCount; break; case TestStatus.FAIL_SETUP: ++failSetupCount; break; case TestStatus.FAIL_TEST: ++failTestCount; break; case TestStatus.FAIL_CLEANUP: ++failCleanupCount; break; case TestStatus.NOT_EXISTS: ++notExistCount; break; case TestStatus.FAIL_BY_EXCEPTION: ++exceptionCount; break; case TestStatus.FAIL_BY_ERROR: ++assertCount; break; default: throw new System.ArgumentException("Invalid Status", testable.Status.ToString()); } return this.WriteEntry(testable); }
private void tvProjects_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { tvProjects.SelectedNode = e.Node; menuProject.Items.Clear(); //判斷是否可以開啟 IEditorManager editorManager = e.Node.Tag as IEditorManager; if (editorManager != null) { if (editorManager.Editors.Count == 1) { IEditable editable = editorManager.Editors[0]; ToolStripItem item = menuProject.Items.Add(editable.DocumentTitle, actImgs.Images[editable.ImageKey], cmEdit_Click); item.Tag = editable; } else if (editorManager.Editors.Count > 0) { ToolStripMenuItem menuItem = new ToolStripMenuItem("開啟"); menuProject.Items.Add(menuItem); foreach (IEditable editable in editorManager.Editors) { ToolStripItem item = menuItem.DropDownItems.Add(editable.DocumentTitle, actImgs.Images[editable.ImageKey], cmEdit_Click); item.Tag = editable; } } } //判斷是否可以改名 ToolStripMenuItem cmRename = new ToolStripMenuItem("重新命名(&N)"); this.CheckMenuItemVisiable(typeof(IRenameable), cmRename); cmRename.Click += new EventHandler(cmRename_Click); cmRename.Image = actImgs.Images["rename"]; //判斷是否可以新增 IAddable addable = e.Node.Tag as IAddable; if (addable != null) { menuProject.Items.Add(addable.TitleOfAdd, actImgs.Images["add"], cmAdd_Click); } //判斷是否可以重新整理 ToolStripMenuItem cmReload = new ToolStripMenuItem("重新整理(&R)"); this.CheckMenuItemVisiable(typeof(IReloadable), cmReload); cmReload.Click += new EventHandler(cmReload_Click); cmReload.Image = actImgs.Images["reload"]; //判斷是否可以刪除 IDeleteable deleteable = e.Node.Tag as IDeleteable; if (deleteable != null) { menuProject.Items.Add(deleteable.TitleOfDelete, actImgs.Images["delete"], cmDelete_Click); } //判斷是否可以測試 ITestable testable = e.Node.Tag as ITestable; if (testable != null) { menuProject.Items.Add(testable.TitleOfTest, actImgs.Images[testable.TestImageKey], cmTest_Click); } //判斷是否可以匯出 ToolStripMenuItem cmExport = new ToolStripMenuItem("匯出(&E)"); this.CheckMenuItemVisiable(typeof(IExportable), cmExport); cmExport.Click += new EventHandler(cmExport_Click); cmExport.Image = actImgs.Images["export"]; //判斷是否可以匯入 ToolStripMenuItem cmImport = new ToolStripMenuItem("匯入(&I)"); this.CheckMenuItemVisiable(typeof(IImportable), cmImport); cmImport.Click += new EventHandler(cmImport_Click); cmImport.Image = actImgs.Images["import"]; //判斷是否可以加入專案 IJoinProject join = e.Node.Tag as IJoinProject; if (join != null) { menuProject.Items.Add("加入專案(&J)", actImgs.Images["join"], cmJoinProject_Click); } //判斷是否可以匯入 ILeaveProject leave = e.Node.Tag as ILeaveProject; if (leave != null) { menuProject.Items.Add("從專案卸載(&L)", actImgs.Images["leave"], cmLeaveProject_Click); } //判斷是否可以上傳 ISyncUpload upload = e.Node.Tag as ISyncUpload; if (upload != null) { menuProject.Items.Add("同步至伺服器(&U)", actImgs.Images["upload"], cmUpload_Click); } //判斷是否可以下載 ISyncDownload download = e.Node.Tag as ISyncDownload; if (download != null) { menuProject.Items.Add("自伺服器同步(&D)", actImgs.Images["download"], cmDownload_Click); } //判斷是否可以設定 ISetupable setup = e.Node.Tag as ISetupable; if (setup != null) { menuProject.Items.Add(setup.SetupTitle + "(&S)", actImgs.Images["setup"], cmSetup_Click); } //判斷是否可以佈署 IDeployable deploy = e.Node.Tag as IDeployable; if (deploy != null) { menuProject.Items.Add("佈署(&L)", actImgs.Images["deploy"], cmDeploy_Click); } //判斷是否可以佈署到實體 IDeployToPhysical deployToPhysical = e.Node.Tag as IDeployToPhysical; if (deployToPhysical != null) { menuProject.Items.Add("佈署到實體(&P)", actImgs.Images["deployToPhysical"], tsbtnDeployToPhysical_Click); } //判斷是否可以從實體 Service 載入 IImportFromPhysical importFromPhysical = e.Node.Tag as IImportFromPhysical; if (importFromPhysical != null) { menuProject.Items.Add("實體 Service 載入(&X)", actImgs.Images["importFromPhysical"], tsbtnImportFromPhysical_Click); } menuProject.Show(e.Location); } }
public static float AddEventVarConditionComponents(Transform parentTransform, float xOffset, float yOffset, ITestable testable, Action updateAction) { UIElement ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 18, 1); ui.SetText(new StringKey("val", "X_COLON", CommonStringKeys.TESTS)); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 18f, yOffset, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { AddTestOp(testable, updateAction); }); new UIElementBorder(ui, Color.green); if (testable.Tests.VarTestsComponents.Count > 0) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { SelectAddParenthesis(testable, updateAction); }); new UIElementBorder(ui, Color.green); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1.0f, yOffset, 2, 1); ui.SetText("(...)"); } yOffset++; int component_index = 0; foreach (VarTestsComponent tc in testable.Tests.VarTestsComponents) { if (tc is VarOperation) { int tmp_index = component_index; // only display arrows if item can be moved if (component_index != (testable.Tests.VarTestsComponents.Count - 1) && testable.Tests.VarTestsComponents.Count > 1 && testable.Tests.VarTestsComponents.FindIndex(component_index + 1, x => x.GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) != -1 ) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, false); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } if (component_index != 0 && testable.Tests.VarTestsComponents.FindLastIndex(component_index - 1, x => x.GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) != -1 ) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1.0f, yOffset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, true); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } VarOperation tmp = (VarOperation)tc; ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 2f, yOffset, 8.5f, 1); ui.SetText(tmp.var); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 10.5f, yOffset, 2, 1); ui.SetText(tmp.operation); ui.SetButton(delegate { SetTestOpp(tmp, updateAction); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 12.5f, yOffset, 5.5f, 1); ui.SetText(tmp.value); ui.SetButton(delegate { SetValue(tmp, updateAction); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 18f, yOffset++, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { RemoveOp(testable.Tests, tmp_index, updateAction); }); new UIElementBorder(ui, Color.red); } if (tc is VarTestsLogicalOperator) { VarTestsLogicalOperator tmp = (VarTestsLogicalOperator)tc; ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 9.5f, yOffset, 4, 1); if (tmp.op.Equals("AND")) { ui.SetText(CommonStringKeys.AND); } else if (tmp.op.Equals("OR")) { ui.SetText(CommonStringKeys.OR); } ui.SetButton(delegate { tmp.NextLogicalOperator(); updateAction.Invoke(); }); new UIElementBorder(ui); yOffset++; } if (tc is VarTestsParenthesis) { int tmp_index = component_index; VarTestsParenthesis tp = (VarTestsParenthesis)tc; if (component_index != (testable.Tests.VarTestsComponents.Count - 1) && testable.Tests.VarTestsComponents.FindIndex(component_index + 1, x => x.GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) != -1 ) { if (tp.parenthesis == "(") { int valid_index = testable.Tests.FindNextValidPosition(component_index, false); if (valid_index != -1 && testable.Tests.FindClosingParenthesis(valid_index) != -1) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, false); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } } else if (tp.parenthesis == ")") { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, false); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } } if (component_index != 0 && testable.Tests.VarTestsComponents.FindLastIndex(component_index - 1, x => x.GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) != -1 ) { if (tp.parenthesis == "(") { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1f, yOffset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, true); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } else if (tp.parenthesis == ")") { int valid_index = testable.Tests.FindNextValidPosition(component_index, true); if (valid_index != -1 && testable.Tests.FindOpeningParenthesis(valid_index) != -1) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1f, yOffset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, true); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } } } ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 2f, yOffset, 2, 1); ui.SetText(tp.parenthesis); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 4f, yOffset, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { testable.Tests.Remove(tmp_index); updateAction.Invoke(); }); new UIElementBorder(ui, Color.red); yOffset++; } component_index++; } return(yOffset + 1); }
public void UseTester(ITestable tester) { tester.Test(); }
public TestHelper(ITestable testable) { _testable = testable; }
public Result Check(object fixture) { ITestable testable = Reflection.Testable(fixture, m_Method); return(Quick.Test(testable)); }
private void tvProjects_AfterSelect(object sender, TreeViewEventArgs e) { INodeHandler handler = e.Node.Tag as INodeHandler; if (handler != null) { if (handler.IsFirstClick) { handler.OnFirstClick(); } else { handler.OnClick(); } } splitContainer1.Panel2.Controls.Clear(); IDeleteable del = handler as IDeleteable; tsbtnDelete.Enabled = false; if (del != null) { tsbtnDelete.Enabled = true; tsbtnDelete.ToolTipText = del.TitleOfDelete; menuProject.Items.Add(del.TitleOfDelete, actImgs.Images["delete"], cmDelete_Click); } IAddable add = handler as IAddable; tsbtnAdd.Enabled = false; if (add != null) { tsbtnAdd.Enabled = true; tsbtnAdd.ToolTipText = add.TitleOfAdd; menuProject.Items.Add(add.TitleOfAdd, actImgs.Images["add"], cmAdd_Click); } IReloadable reload = handler as IReloadable; tsbtnReload.Enabled = false; if (reload != null) { tsbtnReload.Enabled = true; } ITestable test = handler as ITestable; tsbtnTest.Enabled = false; if (test != null) { tsbtnTest.Image = actImgs.Images[test.TestImageKey]; tsbtnTest.Enabled = true; } IRenameable rename = handler as IRenameable; tsbtnRename.Enabled = false; if (rename != null) { tsbtnRename.Enabled = true; } IExportable export = handler as IExportable; tsbtnExport.Enabled = false; if (export != null) { tsbtnExport.Enabled = true; } ISetupable setup = handler as ISetupable; cmSetup.Enabled = false; if (setup != null) { cmSetup.Enabled = true; } IDeployable deploy = handler as IDeployable; cmDeploy.Enabled = false; if (deploy != null) { cmDeploy.Enabled = true; } IDeployToPhysical phyDeploy = handler as IDeployToPhysical; tsbtnDeployToPhysical.Enabled = false; if (phyDeploy != null) { tsbtnDeployToPhysical.Enabled = true; } IImportFromPhysical phyImport = handler as IImportFromPhysical; tsbtnImportFromPhysical.Enabled = false; if (phyImport != null) { tsbtnImportFromPhysical.Enabled = true; } IImportable import = handler as IImportable; tsbtnImport.Enabled = false; if (import != null) { tsbtnImport.Enabled = true; } IJoinProject joinProject = handler as IJoinProject; tsbtnJoinProject.Enabled = false; if (joinProject != null) { tsbtnJoinProject.Enabled = true; } ILeaveProject leaveProject = handler as ILeaveProject; tsbtnLeaveProject.Enabled = false; if (leaveProject != null) { tsbtnLeaveProject.Enabled = true; } ISyncUpload syncUplaod = handler as ISyncUpload; cmUpload.Enabled = false; if (syncUplaod != null) { cmUpload.Enabled = true; } ISyncUpload syncDownload = handler as ISyncUpload; cmDownload.Enabled = false; if (syncDownload != null) { cmDownload.Enabled = true; } tsEditMode.Items.Clear(); rsbtnSave.Enabled = false; IEditorManager manager = handler as IEditorManager; if (manager != null) { rsbtnSave.Enabled = false; foreach (IEditable editable in manager.Editors) { ToolStripItem item = tsEditMode.Items.Add(editable.ModeTitle, actImgs.Images[editable.ImageKey], cmEdit_Click); item.ToolTipText = editable.ModeTitle; item.Text = string.Empty; item.Tag = editable; } } }