public void Handle(SimpleProto data) { if (null != data) { int positionHandler = data.Ins[0]; Contexts contexts = SingletonManager.Get <FreeUiManager>().Contexts1; if (positionHandler == (int)EPositionHandler.EPosition_Init) { string type = data.Ss[0]; int mapId = contexts.session.commonSession.RoomInfo.MapId; Clear(); TestPositionManager.IniTable(mapId, type); List <TestPosition> testPositions = TestPositionManager.GetTestPositions(); for (int i = 0, maxi = (null == testPositions ? 0 : testPositions.Count); i < maxi; i++) { TestPosition testPosition = testPositions[i]; Vector3 position = new Vector3(testPosition.x, testPosition.y, testPosition.z); float rotation = testPosition.rotation; string timeStamp = testPosition.time; CreateGameObject(position, rotation, timeStamp); } } else if (positionHandler == (int)EPositionHandler.EPosition_Add) { Vector3 position = contexts.player.flagSelfEntity.position.Value; GameObject rootGo = contexts.player.flagSelfEntity.RootGo(); string timeStamp = TimeStamp(); CreateGameObject(position, rootGo.transform.eulerAngles.y, timeStamp); TestPositionManager.Add(position, rootGo.transform.eulerAngles.y, timeStamp); } else if (positionHandler == (int)EPositionHandler.EPosition_Remove) { Vector3 position = contexts.player.flagSelfEntity.position.Value; GameObject rootGo = contexts.player.flagSelfEntity.RootGo(); Bounds bounds = new Bounds(position, Vector3.one); ObjectTag[] objectTags = GameObject.FindObjectsOfType <ObjectTag>(); for (int i = 0, maxi = (null == objectTags ? 0 : objectTags.Length); i < maxi; i++) { ObjectTag objectTag = objectTags[i]; if (null == objectTag) { continue; } if (bounds.Contains(objectTag.transform.position)) { TestPositionManager.Delete(objectTag.gameObject.name); GameObject.DestroyImmediate(objectTag.gameObject); objectTags[i] = null; } } } } }
public virtual void visitFork(ForkElement element, TestPosition position) { if (_runContext.PositionIsAncestorOfContext(position)) { element.Action(); } }
private async Task InitOnce() { if (_app != null) return; _app = new DefaultWebApplicationFactory(); var options = new WebApplicationFactoryClientOptions() { AllowAutoRedirect = false }; _httpClient = _app.CreateClient(options); _apiClient = new ApiClient(_httpClient, _app.GetLogger<ApiClient>()); // create tenants here await _apiClient.AsSiteAdminAsync(_httpClient); _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse); await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse); await TestDepartment.SeedDefaultDepartments(_apiClient, _gryffindorHouse); await TestPosition.SeedDefaultPosition(_apiClient, _gryffindorHouse); await TestEmployees.SeedDefaultEmployees(_apiClient, _gryffindorHouse); _gryffindorEmployees = (await _apiClient.GetEmployeesAsync()).ToList(); await _apiClient.AsSiteAdminAsync(_httpClient); _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse); await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse); await TestDepartment.SeedDefaultDepartments(_apiClient, _slytherinHouse); await TestPosition.SeedDefaultPosition(_apiClient, _slytherinHouse); await TestEmployees.SeedDefaultEmployees(_apiClient, _slytherinHouse); }
public Exception RunActionWithVisitor(TestPosition position, Action action, ISpecPositionVisitor visitor) { Exception exception = null; TestPosition firstChildPosition = position; var originalVisitor = _fixtureInstanceForDiscovery.Visitor; _fixtureInstanceForDiscovery.CurrentPosition = firstChildPosition; _fixtureInstanceForDiscovery.Visitor = visitor; try { action(); } catch (Exception e) { exception = e; } finally { _fixtureInstanceForDiscovery.Visitor = originalVisitor; } return exception; }
public Exception PrepareForTestPosition(TestPosition position) { Exception existingError = null; if (position == null) { throw new ArgumentException("Parameter is required", "position"); } _targetPosition = position; if (_visitor.SetTargetPosition(position, out existingError)) { return(existingError); } do { if (_thread == null) { _thread = new Thread(ThreadProc); _thread.Start(); } _runMutex.PassAndWaitForTurn(); } while (!_visitor.SetTargetPosition(position, out existingError)); return(existingError); }
public void visitWaitUntil(WaitUntilElement element, TestPosition position) { if (_executingPastDiscovery != null) { Expect.Eventually(element.Expectation, element.WaitMaxMS, element.WaitIncrementMS); } }
public void UnwindForPosition(TestPosition position, Action<Exception> errorHandler) { List<Action> toRun = new List<Action>(); for (var i = _cleanupActions.Count() - 1; i >= 0; i--) { var kvp = _cleanupActions[i]; if (!kvp.Key.IsOnPathTo(position)) { toRun.Add(kvp.Value); _cleanupActions.RemoveAt(i); } } try { foreach (var action in toRun) action(); } catch (Exception e) { errorHandler(e); } for(var i = _setupResults.Count() - 1; i >= 0; i--) { var kvp = _setupResults[i]; if (!kvp.Key.IsOnPathTo(position)) { _setupResults.RemoveAt(i); } } }
public void visitTest(TestElement element, TestPosition position) { if (element.Action == null) { var testContext = new TestContext() { Name = _fixtureContext.NameReservations.GetReservedTestName(element.Description, _parent.Name), Position = position, FixtureContext = _fixtureContext }; var test = _fixtureContext.NativeTestFactory.ForTest(_fixtureContext, testContext); test.MarkTestInvalid("Specification is not implemented."); ApplyCategoryAndIgnoreIfSet(test); _accumulatedDescendants.Add(test); } else { var buildResult = _fixtureContext.CreateTest(_parent, position, element.Description); ApplyCategoryAndIgnoreIfSet(buildResult); _accumulatedDescendants.Add(buildResult); } }
public void duplicated_runs_dont_accidentally_accumulate_afterEach_calls() { AFixture fixture = new AFixture(); var fakeGlobalSetupManager = new FakeGlobalSetupManager(); TestPosition testPosition = TestPosition.At(1, 3, 2); var traceMessages = new List <string>(); SpecificationRunner.RunTest(new TestContext() { FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager), Name = new TestName(), Position = testPosition }, traceMessages); fixture.ResetObservations(); var traceMessages1 = new List <string>(); SpecificationRunner.RunTest(new TestContext() { FixtureContext = new FixtureContext(null, () => fixture, null, fakeGlobalSetupManager), Name = new TestName(), Position = testPosition }, traceMessages1); expect_observation_matches(fixture.Observations, 1, 2, 3, 4, 5, 6, -2, -3, -4, 7, 8); }
public TestBuilder CreateTest(GlobalSetupManager globalSetupManager, TestBuilder parentTest, TestPosition position, string description) { var test = new TestBuilder(_nativeTestFactory.ForTest(_fixtureFactory, position, globalSetupManager)); NameGenator.NameTest(description, parentTest, test); return test; }
public Exception GetErrorForPosition(TestPosition position) { if (_existingError != null && _existingErrorPosition != null && _existingErrorPosition.IsOnPathTo(position)) return _existingError; else return null; }
public void visitFork(ForkElement element, TestPosition position) { if (element.Action == null) { var testContext = new TestContext() { Name = _fixtureContext.NameReservations.GetReservedTestName(element.Description, _parent.Name), Position = position, FixtureContext = _fixtureContext }; var result = _fixtureContext.NativeTestFactory.ForTest(_fixtureContext, testContext); result.MarkTestInvalid("Specification is not implemented."); ApplyCategoryAndIgnoreIfSet(result); _accumulatedDescendants.Add(result); } else { var testContext = new TestContext() { Name = _fixtureContext.NameReservations.GetSharedTestName(element.Description, _parent.Name), Position = position, FixtureContext = _fixtureContext }; var suiteResuilt = SpecificationBuilder.BuildSuiteForTextContext(_fixtureContext, testContext, element.Action, false); ApplyCategoryAndIgnoreIfSet(suiteResuilt); _accumulatedDescendants.Add(suiteResuilt); } }
public void Cleanup(TestPosition position) { if (_thread != null) { PrepareForTestPosition(position); } }
public void visitExpect(ExpectElement element, TestPosition position) { if (_executingPastDiscovery != null) { Expect.That(element.Expectation); } }
public NJasmineTestMethod CreateTest(GlobalSetupManager globalSetupManager, NJasmineTestSuite parentTest, TestPosition position, string description) { var test = new NJasmineTestMethod(_fixtureFactory, position, globalSetupManager); NameGenator.NameTest(description, parentTest, test); return test; }
public bool SetTargetPosition(TestPosition position, out Exception existingError) { _targetPosition = position; existingError = _errorAccumulator.GetErrorForPosition(position); return(existingError != null || _targetPosition.Equals(_currentTestPosition)); }
public void AddTraceEntry(TestPosition position, string message) { _top = new TraceEntry() { Position = position, Message = message, Next = _top }; }
public void test_IsAncestorOf() { var position = TestPosition.At(1, 2, 3); expect(() => position.IsAncestorOf(TestPosition.At(1, 2, 3, 4))); expect(() => position.IsAncestorOf(TestPosition.At(1, 2, 3, 4, 0, 1, 2))); expect(() => !position.IsAncestorOf(TestPosition.At(1, 2))); expect(() => !position.IsAncestorOf(TestPosition.At(3, 2, 1, 4))); }
public object GetSetupResultAt(TestPosition position) { if (!position.IsOnPathTo(_targetPosition)) { throw new InvalidProgramException(); } return(_setupResultAccumulator.InternalGetSetupResultAt(position)); }
public virtual void visitTest(TestElement element, TestPosition position) { if (_runContext.TestIsAtPosition(position)) { _runContext.whileInState(new ActState(_runContext, element), element.Action); _runContext.GotoStateFinishing(); } }
public void UnwindToPosition(TestPosition position) { while (_top != null) { if (!_top.Position.IsOnPathTo(position)) _top = _top.Next; else break; } }
public NJasmineTestRunContext(TestPosition targetTestPosition, IGlobalSetupManager globalSetup, List <string> traceMessages) { _targetTestPosition = targetTestPosition; _globalSetup = globalSetup; _allTeardowns = new List <Action>(); _traces = traceMessages; _leakedDisposables = new List <IDisposable>(); State = new DiscoveryState(this); }
public INativeTest CreateTest(INativeTest parentTest, TestPosition position, string description) { var testContext = new TestContext() { Name = NameReservations.GetReservedTestName(description, parentTest.Name), Position = position, FixtureContext = this }; return NativeTestFactory.ForTest(this, testContext); }
public void visitIgnoreBecause(IgnoreElement element, TestPosition position) { if (_accumulatedDescendants.Count > 0) { _ignoreReason = element.Reason; } else { _parent.MarkTestIgnored(element.Reason); } }
protected void ReportError(TestPosition position, Exception error) { _errorAccumulator.AddError(position, error); while (error != null && position != null && position.IsOnPathTo(_targetPosition)) { _runningLock.PassAndWaitForTurn(); } }
public void FinishCleanup() { _setupResultAccumulator.UnwindAll(e => { ReportError(TestPosition.At(0), e); }); _traceTracker.UnwindAll(); _currentTestPosition = TestPosition.At(); }
public Exception GetErrorForPosition(TestPosition position) { if (_existingError != null && _existingErrorPosition != null && _existingErrorPosition.IsOnPathTo(position)) { return(_existingError); } else { return(null); } }
public object InternalGetSetupResultAt(TestPosition position) { try { return _setupResults.First(kvp => kvp.Key != null && kvp.Key.Equals(position)).Value; } catch (Exception e) { throw new InvalidProgramException(String.Format("Could not find setup result for position {0}, had results for {1}.", position.ToString() ?? "null", String.Join(", ", _setupResults.Select(sr => sr.Key.ToString()).ToArray())), e); } }
public void visitTrace(TraceElement element, TestPosition position) { if (_executingPastDiscovery != null) { _traceTracker.AddTraceEntry(position, element.Message); } if (_executingCleanup != null) { throw new Exception("Attempted to call " + element + "() from within " + _executingCleanup); } }
public object InternalGetSetupResultAt(TestPosition position) { try { return(_setupResults.First(kvp => kvp.Key != null && kvp.Key.Equals(position)).Value); } catch (Exception e) { throw new InvalidProgramException(String.Format("Could not find setup result for position {0}, had results for {1}.", position.ToString() ?? "null", String.Join(", ", _setupResults.Select(sr => sr.Key.ToString()).ToArray())), e); } }
public void RunFixture(SpecificationFixture fixture) { fixture.CurrentPosition = TestPosition.At(0); fixture.Visitor = this; try { fixture.Run(); } catch (Exception e) { ReportError(TestPosition.At(0), e); } }
public void visitAfterAll(AfterAllElement element, TestPosition position) { CheckNotAlreadyPastDiscovery(element); if (position.IsOnPathTo(_targetPosition)) { _setupResultAccumulator.AddCleanupAction(position, delegate { _executingCleanup = element; element.Action(); _executingCleanup = null; }); } }
public void can_run_tests_c() { expect_test_to_observe(TestPosition.At(4), new List <string>() { "1", "a1", "a2", "a3", "2", "5", "c" }); }
private async Task InitOnce() { if (_app != null) { return; } LogHelper.ConfigureConsoleLogger(); _app = new DefaultWebApplicationFactory(); var options = new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }; _httpClient = _app.CreateClient(options); var apiClient = new ApiClient(_httpClient, _app.GetLogger <ApiClient>()); apiClient.TraceResponseOnException = true; _apiClient = apiClient; // site admin creates 2 tenants await _apiClient.AsSiteAdminAsync(_httpClient); _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse); await _apiClient.AsSiteAdminAsync(_httpClient); _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse); // Slytherin House admin creates branch office and departments await _apiClient.AsSlytherinAdminAsync(_httpClient); TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse).Wait(); TestDepartment.SeedDefaultDepartments(_apiClient, _slytherinHouse).Wait(); TestPosition.SeedDefaultPosition(_apiClient, _slytherinHouse).Wait(); TestEmployees.SeedDefaultEmployees(_apiClient, _slytherinHouse).Wait(); // Gryffindor House admin creates branch office and departments await _apiClient.AsGryffindorAdminAsync(_httpClient); TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse).Wait(); TestDepartment.SeedDefaultDepartments(_apiClient, _gryffindorHouse).Wait(); TestPosition.SeedDefaultPosition(_apiClient, _gryffindorHouse).Wait(); TestEmployees.SeedDefaultEmployees(_apiClient, _gryffindorHouse).Wait(); _workDepartmentId = _gryffindorHouse.Department_1_2.Department.Id; }
public void AddSetupResult(TestPosition position, object value) { if (value is IDisposable) { AddCleanupAction( position, delegate { (value as IDisposable).Dispose(); }); } _setupResults.Add(new KeyValuePair<TestPosition, object>(position, value)); }
public void UnwindToPosition(TestPosition position) { while (_top != null) { if (!_top.Position.IsOnPathTo(position)) { _top = _top.Next; } else { break; } } }
void expect_test_to_observe(TestPosition testPosition, List <string> expected) { var fixture = new has_test_in_loop(); var traceMessages = new List <string>(); SpecificationRunner.RunTest(new TestContext() { FixtureContext = new FixtureContext(null, () => fixture, null, new FakeGlobalSetupManager()), Name = new TestName(), Position = testPosition }, traceMessages); Assert.That(fixture.Observations, Is.EquivalentTo(expected)); }
public void AddSetupResult(TestPosition position, object value) { if (value is IDisposable) { AddCleanupAction( position, delegate { var valueAsDisposable = value as IDisposable; if (!_disposablesToLeak.Contains(valueAsDisposable)) { valueAsDisposable.Dispose(); } }); } _setupResults.Add(new KeyValuePair<TestPosition, object>(position, value)); }
public void AddError(TestPosition position, Exception error) { _existingError = error; _existingErrorPosition = position; }
public override object Run(ISpecPositionVisitor visitor, TestPosition position) { visitor.visitFork(this, position); return ElementResultUnused; }
public void AddCleanupAction(TestPosition position, Action action) { _cleanupActions.Add(new KeyValuePair<TestPosition, Action>(position, action)); }
public abstract object Run(ISpecPositionVisitor visitor, TestPosition position);
public override object Run(ISpecPositionVisitor visitor, TestPosition position) { visitor.visitWaitUntil(this, position); return null; }
public override object Run(ISpecPositionVisitor visitor, TestPosition position) { visitor.visitAfterEach(this, _action, position); return ElementResultUnused; }