Пример #1
0
        public void MonitorSimpleWork()
        {
            const int wait = 10;

            var monitor = new Twill.Processes.Tracking.Monitor();

            monitor.StartWatch();

            var time           = monitor.TimeUpdate;
            var upDateCount    = 0;
            var processesCount = new List <int>();

            monitor.Event += (obj, e) =>
            {
                var @this = obj as Twill.Processes.Tracking.Monitor;

                upDateCount++;
                processesCount.Add(@this.ProcessMonitor.Processes?.Count ?? 0);
                TestContext.WriteLine(@this.ProcessMonitor.Lead?.Name ?? string.Empty);
            };

            Thread.Sleep(TimeSpan.FromSeconds(time.Seconds * wait));

            Assert.IsTrue(processesCount.Sum() != 0, "Not work");
        }
Пример #2
0
        public void MonitorFilterTest()
        {
            using (var token = new ManualResetEvent(false))
            {
                var monitor = new Twill.Processes.Tracking.Monitor();

                monitor.StartWatch();

                monitor.FilterProcessNames.Clear();

                var processNames = new List <string>();

                monitor.Event += (obj, e) =>
                {
                    var @this = obj as Twill.Processes.Tracking.Monitor;

                    if (processNames.Count == 0)
                    {
                        processNames.AddRange(@this.FilterProcessMonitor.Processes.Select(p => p.Name));
                    }

                    TestContext.WriteLine("");
                    TestContext.WriteLine("--------start list-------");

                    @this.FilterProcessMonitor.Processes.Select(p => p.Name).ToList().ForEach(p => TestContext.WriteLine(p ?? string.Empty));

                    TestContext.WriteLine("--------end list-------");
                    TestContext.WriteLine("");

                    token.Set();
                };

                token.WaitOne();

                Assert.IsTrue(processNames.Count != 0, "No desktop process");

                var deleteName = processNames.First();
                monitor.FilterProcessNames.Add(deleteName);
                TestContext.WriteLine($"Add to filter {deleteName}");
                processNames.Clear();

                token.Reset();
                token.WaitOne();

                Assert.IsTrue(processNames.Count != 0, "CollectionClear. Isn't updated.");
                Assert.IsFalse(processNames.Contains(deleteName), "Not delete name");
            }
        }