コード例 #1
0
        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;
                        }
                    }
                }
            }
        }
コード例 #2
0
 public virtual void visitFork(ForkElement element, TestPosition position)
 {
     if (_runContext.PositionIsAncestorOfContext(position))
     {
         element.Action();
     }
 }
コード例 #3
0
    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);
    }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void visitWaitUntil(WaitUntilElement element, TestPosition position)
 {
     if (_executingPastDiscovery != null)
     {
         Expect.Eventually(element.Expectation, element.WaitMaxMS, element.WaitIncrementMS);
     }
 }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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;
        }
コード例 #12
0
 public Exception GetErrorForPosition(TestPosition position)
 {
     if (_existingError != null && _existingErrorPosition != null && _existingErrorPosition.IsOnPathTo(position))
         return _existingError;
     else
         return null;
 }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
 public void Cleanup(TestPosition position)
 {
     if (_thread != null)
     {
         PrepareForTestPosition(position);
     }
 }
コード例 #15
0
 public void visitExpect(ExpectElement element, TestPosition position)
 {
     if (_executingPastDiscovery != null)
     {
         Expect.That(element.Expectation);
     }
 }
コード例 #16
0
        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;
        }
コード例 #17
0
        public bool SetTargetPosition(TestPosition position, out Exception existingError)
        {
            _targetPosition = position;

            existingError = _errorAccumulator.GetErrorForPosition(position);

            return(existingError != null || _targetPosition.Equals(_currentTestPosition));
        }
コード例 #18
0
 public void AddTraceEntry(TestPosition position, string message)
 {
     _top = new TraceEntry()
     {
         Position = position,
         Message = message,
         Next = _top
     };
 }
コード例 #19
0
        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)));
        }
コード例 #20
0
        public object GetSetupResultAt(TestPosition position)
        {
            if (!position.IsOnPathTo(_targetPosition))
            {
                throw new InvalidProgramException();
            }

            return(_setupResultAccumulator.InternalGetSetupResultAt(position));
        }
コード例 #21
0
        public virtual void visitTest(TestElement element, TestPosition position)
        {
            if (_runContext.TestIsAtPosition(position))
            {
                _runContext.whileInState(new ActState(_runContext, element), element.Action);

                _runContext.GotoStateFinishing();
            }
        }
コード例 #22
0
 public void AddTraceEntry(TestPosition position, string message)
 {
     _top = new TraceEntry()
     {
         Position = position,
         Message  = message,
         Next     = _top
     };
 }
コード例 #23
0
 public void UnwindToPosition(TestPosition position)
 {
     while (_top != null)
     {
         if (!_top.Position.IsOnPathTo(position))
             _top = _top.Next;
         else
             break;
     }
 }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
 public void visitIgnoreBecause(IgnoreElement element, TestPosition position)
 {
     if (_accumulatedDescendants.Count > 0)
     {
         _ignoreReason = element.Reason;
     }
     else
     {
         _parent.MarkTestIgnored(element.Reason);
     }
 }
コード例 #27
0
        protected void ReportError(TestPosition position, Exception error)
        {
            _errorAccumulator.AddError(position, error);

            while (error != null &&
                   position != null &&
                   position.IsOnPathTo(_targetPosition))
            {
                _runningLock.PassAndWaitForTurn();
            }
        }
コード例 #28
0
        public void FinishCleanup()
        {
            _setupResultAccumulator.UnwindAll(e =>
            {
                ReportError(TestPosition.At(0), e);
            });

            _traceTracker.UnwindAll();

            _currentTestPosition = TestPosition.At();
        }
コード例 #29
0
        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);
        }
コード例 #30
0
 public Exception GetErrorForPosition(TestPosition position)
 {
     if (_existingError != null && _existingErrorPosition != null && _existingErrorPosition.IsOnPathTo(position))
     {
         return(_existingError);
     }
     else
     {
         return(null);
     }
 }
コード例 #31
0
 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);
     }
 }
コード例 #32
0
        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);
            }
        }
コード例 #33
0
 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);
     }
 }
コード例 #34
0
 public void RunFixture(SpecificationFixture fixture)
 {
     fixture.CurrentPosition = TestPosition.At(0);
     fixture.Visitor         = this;
     try
     {
         fixture.Run();
     }
     catch (Exception e)
     {
         ReportError(TestPosition.At(0), e);
     }
 }
コード例 #35
0
        public void visitAfterAll(AfterAllElement element, TestPosition position)
        {
            CheckNotAlreadyPastDiscovery(element);

            if (position.IsOnPathTo(_targetPosition))
            {
                _setupResultAccumulator.AddCleanupAction(position, delegate {
                    _executingCleanup = element;
                    element.Action();
                    _executingCleanup = null;
                });
            }
        }
コード例 #36
0
 public void can_run_tests_c()
 {
     expect_test_to_observe(TestPosition.At(4), new List <string>()
     {
         "1",
         "a1",
         "a2",
         "a3",
         "2",
         "5",
         "c"
     });
 }
コード例 #37
0
        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;
        }
コード例 #38
0
        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));
        }
コード例 #39
0
 public void UnwindToPosition(TestPosition position)
 {
     while (_top != null)
     {
         if (!_top.Position.IsOnPathTo(position))
         {
             _top = _top.Next;
         }
         else
         {
             break;
         }
     }
 }
コード例 #40
0
        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));
        }
コード例 #41
0
        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));
        }
コード例 #42
0
 public void AddError(TestPosition position, Exception error)
 {
     _existingError = error;
     _existingErrorPosition = position;
 }
コード例 #43
0
ファイル: ForkElement.cs プロジェクト: edwardt/DreamNJasmine
 public override object Run(ISpecPositionVisitor visitor, TestPosition position)
 {
     visitor.visitFork(this, position);
     return ElementResultUnused;
 }
コード例 #44
0
 public void AddCleanupAction(TestPosition position, Action action)
 {
     _cleanupActions.Add(new KeyValuePair<TestPosition, Action>(position, action));
 }
コード例 #45
0
 public abstract object Run(ISpecPositionVisitor visitor, TestPosition position);
コード例 #46
0
 public override object Run(ISpecPositionVisitor visitor, TestPosition position)
 {
     visitor.visitWaitUntil(this, position);
     return null;
 }
コード例 #47
0
 public override object Run(ISpecPositionVisitor visitor, TestPosition position)
 {
     visitor.visitAfterEach(this, _action, position);
     return ElementResultUnused;
 }