Esempio n. 1
0
        public void Delayer_DelayWithNullTestKitBase_ThrowsArgumentNullException()
        {
            //arrange
            Delayer sut = CreateDelayer();

            //act
            Action act = () => sut.Delay(null, TimeSpan.Zero);

            //assert
            act.Should().Throw <ArgumentNullException>();
        }
Esempio n. 2
0
        void RunPhysics()
        {
            DateTime lastUpdate = DateTime.UtcNow;
            Delayer  delayer    = new Delayer(TimeSpan.FromMilliseconds(25));

            while (true)
            {
                delayer.Delay();

                DateTime now      = DateTime.UtcNow;
                TimeSpan duration = now - lastUpdate;
                lastUpdate = now;

                physics.DoPhysics(duration);
            }
        }
Esempio n. 3
0
    //
    // Click for pressDuration seconds
    //  a good visual pressDuration is 0.33f
    public virtual void Click(float pressDuration = 0)
    {
        if (!(isActiveAndEnabled && Interactable))
        {
            // button must be active and interactable to click
            return;
        }

        // show button as pressed
        _showAsPressed = true;
        UpdateButton();

        void unpressCallback()
        {
            //
            // invoke and unpress button

            onClickEvent?.Invoke(this);

            // SkipPointerUp skips returning to the normal ("Up") state after
            //  clicking, which is useful with tab menus or button toggles,
            //  otherwise you see the normal state flicker.
            _showAsPressed = SkipPointerUp;
            UpdateButton();
        }

        if (waitForClickSound && pressDuration == 0 && Enabled)
        {
            SoundHelper.Play(clickSound, unpressCallback);
        }
        else
        {
            if (clickSound && Enabled)
            {
                clickSound?.Play();
            }
            if (pressDuration > 0)
            {
                Delayer.Delay(pressDuration, unpressCallback);
            }
            else
            {
                unpressCallback();
            }
        }
    }
Esempio n. 4
0
    public void DoWork()
    {
        int snapshot = m_iSharedData;

        Delayer.Delay(Delayer.RandomShortDelay(m_rng));
        m_iSharedData++;
        Delayer.Delay(Delayer.RandomShortDelay(m_rng));
        if (m_iSharedData != snapshot + 1)
        {
            Error = true;
            Console.WriteLine("Failure!!!");
        }
        if (m_iSharedData == m_iRequestedEntries)
        {
            m_Event.Set();
        }
    }
Esempio n. 5
0
        public void Delayer_DelayWithNegativeDuration_DoesNotDelay()
        {
            //arrange
            TimeSpan duration = TimeSpan.FromSeconds(TestHelper.GenerateNumberBetween(-1000, -1));
            Delayer  sut      = CreateDelayer();

            //act
            Action act = () => sut.Delay(TestKit, duration);

            //assert
            TimeSpan  expected  = TimeSpan.Zero;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            act();
            stopwatch.Stop();
            stopwatch.Elapsed.Should().BeCloseTo(expected, 250);
        }
Esempio n. 6
0
        public void Delayer_DelayWithZeroDuration_DoesNotDelay()
        {
            //arrange
            TimeSpan duration = TimeSpan.Zero;
            Delayer  sut      = CreateDelayer();

            //act
            Action act = () => sut.Delay(TestKit, duration);

            //assert
            TimeSpan  expected  = TimeSpan.Zero;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            act();
            stopwatch.Stop();
            stopwatch.Elapsed.Should().BeCloseTo(expected, 250);
        }
Esempio n. 7
0
        public void Delayer_DelayWithPositiveDuration_DelaysForDilatedDuration()
        {
            //arrange
            TimeSpan duration = TimeSpan.FromSeconds(1);
            Delayer  sut      = CreateDelayer();

            //act
            Action act = () => sut.Delay(TestKit, duration);

            //assert
            TimeSpan  expected  = TimeSpan.FromSeconds(duration.TotalSeconds * TimeFactor);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            act();
            stopwatch.Stop();
            stopwatch.Elapsed.Should().BeCloseTo(expected, 250);
        }
Esempio n. 8
0
    public void DoWork()
    {
        int snapshot = m_iSharedData;

        Delayer.Delay(Delayer.RandomShortDelay(m_rng));
#if (DEBUG)
        Console.WriteLine("Entering Monitor: " + m_iSharedData);
#endif
        m_iSharedData++;
        Delayer.Delay(Delayer.RandomShortDelay(m_rng));
        if (m_iSharedData != snapshot + 1)
        {
            Error = true;
            Console.WriteLine("Failure!!!");
        }
#if (DEBUG)
        Console.WriteLine("Leaving Monitor: " + m_iSharedData);
#endif
        if (m_iSharedData == m_iRequestedEntries)
        {
            m_Event.Set();
        }
    }