Esempio n. 1
0
        public void OnStateChangedTest()
        {
            var mock  = new AppWorkerMock();
            var start = false;
            var stop  = false;

            mock.StateChanged += (s, e) =>
            {
                switch (e.NewState)
                {
                case AppWorkerState.Running:
                    start = true;
                    break;

                case AppWorkerState.Stopped:
                    stop = true;
                    break;
                }
            };

            mock.Start();
            mock.Stop();
            Assert.IsTrue(start);
            Assert.IsTrue(stop);
        }
Esempio n. 2
0
        public async Task WorkingTest()
        {
            var mock = new AppWorkerMock();

            mock.Start();
            // Mock increase count by one every 100 ms, wait a little bit
            await Task.Delay(TimeSpan.FromMilliseconds(600));

            Assert.GreaterOrEqual(mock.Count, 5);
        }
Esempio n. 3
0
        public async Task AppWorkerExceptionTest()
        {
            var mock = new AppWorkerMock();

            mock.Start();
            // Mock increase count by one every 100 ms, wait a little bit
            await Task.Delay(TimeSpan.FromSeconds(2));

            Assert.IsFalse(mock.IsBusy, "The AppWorker is not busy");
            Assert.IsFalse(mock.ExitBecauseCancellation, "The AppWorker doesn't exit because cancellation");
            Assert.IsNotNull(mock.Exception, "The AppWorker had an exception");
        }
Esempio n. 4
0
        public async Task AppWorkerExceptionTest()
        {
            var mock = new AppWorkerMock();
            await mock.StartAsync();

            // Mock increase count by one every 100 ms, wait a little bit
            await Task.Delay(TimeSpan.FromSeconds(2));

            Assert.AreEqual(WorkerState.Waiting, mock.WorkerState);
            Assert.IsFalse(mock.ExitBecauseCancellation, "The AppWorker doesn't exit because cancellation");
            Assert.IsNotNull(mock.Exception, "The AppWorker had an exception");
        }
Esempio n. 5
0
        public async Task WorkingTest()
        {
            if (Runtime.OS == Swan.OperatingSystem.Osx)
            {
                Assert.Inconclusive("OSX is wrong");
            }

            var mock = new AppWorkerMock();

            mock.Start();

            // Mock increase count by one every 100 ms, wait a little bit
            await Task.Delay(TimeSpan.FromSeconds(1));

            Assert.GreaterOrEqual(mock.Count, 5);
        }
Esempio n. 6
0
        public async Task CanStartAndStopTest()
        {
            var mock = new AppWorkerMock();
            var exit = false;

            mock.OnExit = () => exit = true;
            Assert.AreEqual(WorkerState.Created, mock.WorkerState);
            await mock.StartAsync();

            Assert.AreEqual(WorkerState.Waiting, mock.WorkerState);
            await mock.StopAsync();

            Assert.AreEqual(WorkerState.Stopped, mock.WorkerState);

            Assert.IsTrue(mock.ExitBecauseCancellation, "Exit because cancellation");
            Assert.IsTrue(exit, "Exit event was fired");
        }
Esempio n. 7
0
        public async Task CanStartAndStopTest()
        {
            var mock = new AppWorkerMock();
            var exit = false;

            mock.OnExit = () => exit = true;
            Assert.AreEqual(AppWorkerState.Stopped, mock.State);
            mock.Start();
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            Assert.IsTrue(mock.IsBusy, "Worker is busy");
            Assert.AreEqual(AppWorkerState.Running, mock.State);
            mock.Stop();
            Assert.AreEqual(AppWorkerState.Stopped, mock.State);

            Assert.IsTrue(mock.ExitBecauseCancellation, "Exit because cancellation");
            Assert.IsTrue(exit, "Exit event was fired");
        }
Esempio n. 8
0
        public void OnStateChangedTest()
        {
            var mock  = new AppWorkerMock();
            var start = false;
            var stop  = false;

            mock.StateChanged += (s, e) =>
            {
                if (e.NewState == AppWorkerState.Running)
                {
                    start = true;
                }
                if (e.NewState == AppWorkerState.Stopped)
                {
                    stop = true;
                }
            };

            mock.Start();
            mock.Stop();
            Assert.IsTrue(start);
            Assert.IsTrue(stop);
        }