public void ReportRunTest_TestExecutionTimeInDays(MutantStatus status)
        {
            var progressBarMock = new Mock <IProgressBar>(MockBehavior.Strict);

            progressBarMock.Setup(x => x.Start(It.IsAny <int>(), It.IsAny <string>()));
            progressBarMock.Setup(x => x.Tick(It.IsAny <string>()));

            var progressBarReporter = new ProgressBarReporter(progressBarMock.Object, new FixedClock());

            var mutantTestResult = new Mutant()
            {
                ResultStatus = status
            };

            progressBarReporter.ReportInitialState(100000000);
            progressBarReporter.ReportRunTest(mutantTestResult);

            string expected = string.Empty;

            switch (status)
            {
            case MutantStatus.Killed:
                expected = "│ Testing mutant 1 / 100000000 │ K 1 │ S 0 │ T 0 │ ~11d 13h │";
                break;

            case MutantStatus.Survived:
                expected = "│ Testing mutant 1 / 100000000 │ K 0 │ S 1 │ T 0 │ ~11d 13h │";
                break;

            case MutantStatus.Timeout:
                expected = "│ Testing mutant 1 / 100000000 │ K 0 │ S 0 │ T 1 │ ~11d 13h │";
                break;
            }
        }
        public void ShouldSupportWhenNoMutants()
        {
            var progressBarMock = new ProgressBar();

            var progressBarReporter = new ProgressBarReporter(progressBarMock, new FixedClock());

            // the progress bar was never initialized
            progressBarMock.Ticks().ShouldBe(-1);
            progressBarReporter.ReportFinalState();
            // the progress bar was never initialized
            progressBarMock.Ticks().ShouldBe(-1);
        }
        public void ReportInitialState_ShouldReportTestProgressAs0PercentageDone_WhenTotalNumberOfTestsIsTwo()
        {
            var progressBarMock = new Mock <IProgressBar>(MockBehavior.Strict);

            progressBarMock.Setup(x => x.Start(It.IsAny <int>(), It.IsAny <string>()));

            var progressBarReporter = new ProgressBarReporter(progressBarMock.Object, new FixedClock());

            progressBarReporter.ReportInitialState(3);

            progressBarMock.Verify(x => x.Start(
                                       It.Is <int>(a => a == 3),
                                       It.Is <string>(b => b == "│ Testing mutant 0 / 3 │ K 0 │ S 0 │ T 0 │ NA │")
                                       ));
        }
Пример #4
0
        private static ProgressReporter CreateProgressReporter()
        {
            var consoleOneLineLoggerFactory = new ConsoleOneLineLoggerFactory();
            var progressBarReporter         =
                new ProgressBarReporter(consoleOneLineLoggerFactory.Create(), new StopWatchProvider());
            var mutantKilledLogger   = consoleOneLineLoggerFactory.Create();
            var mutantSurvivedLogger = consoleOneLineLoggerFactory.Create();
            var mutantTimeoutLogger  = consoleOneLineLoggerFactory.Create();

            var mutantsResultReporter = new MutantsResultReporter(
                mutantKilledLogger,
                mutantSurvivedLogger,
                mutantTimeoutLogger);

            return(new ProgressReporter(mutantsResultReporter, progressBarReporter));
        }
        public void ReportRunTest_ShouldReportTestProgressAs50PercentageDone_And_FirstTestExecutionTime_WhenHalfOfTestsAreDone(MutantStatus status)
        {
            var progressBarMock = new Mock <IProgressBar>(MockBehavior.Strict);

            progressBarMock.Setup(x => x.Start(It.IsAny <int>(), It.IsAny <string>()));
            progressBarMock.Setup(x => x.Tick(It.IsAny <string>()));

            var progressBarReporter = new ProgressBarReporter(progressBarMock.Object, new FixedClock());

            var mutantTestResult = new Mutant()
            {
                ResultStatus = status
            };

            progressBarReporter.ReportInitialState(2);
            progressBarReporter.ReportRunTest(mutantTestResult);

            string expected = string.Empty;

            switch (status)
            {
            case MutantStatus.Killed:
                expected = "│ Testing mutant 1 / 2 │ K 1 │ S 0 │ T 0 │ ~0m 00s │";
                break;

            case MutantStatus.Survived:
                expected = "│ Testing mutant 1 / 2 │ K 0 │ S 1 │ T 0 │ ~0m 00s │";
                break;

            case MutantStatus.Timeout:
                expected = "│ Testing mutant 1 / 2 │ K 0 │ S 0 │ T 1 │ ~0m 00s │";
                break;
            }

            progressBarMock.Verify(x => x.Tick(
                                       It.Is <string>(b => b == expected)
                                       ));
        }
Пример #6
0
        void FileCopier(ManualResetEvent ProcessVerif, Work work, bool priorities)
        {
            differential.remainingfiles = differential.filecount;
            differential.remainingsize  = differential.totalsize;
            DirectoryInfo path = new DirectoryInfo(differential.source);

            FileInfo[] files = path.GetFiles();
            //Observer observable implementation
            ProgressBarReporter reporter = new ProgressBarReporter();
            ProgressBarTracker  provider = new ProgressBarTracker();

            reporter.Subscribe(provider);
            Console.WriteLine("Starting process...");

            //Initializating the timer and starting it
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            // Create subdirectory structure in destination
            foreach (string direction in System.IO.Directory.GetDirectories(differential.source, "*", System.IO.SearchOption.AllDirectories))
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.Combine(differential.destination, direction.Substring(differential.source.Length - 5)));
            }

            // Copy each file in its final direction
            foreach (string file in System.IO.Directory.GetFiles(differential.source, "*", System.IO.SearchOption.AllDirectories))
            {
                ProcessVerif.WaitOne();
                Console.WriteLine("copying " + file);
                differential.currentfiletocopy = file;

                //Create a FileInfo object "f" with its directory to get the f.Length object's size (in bytes)
                FileInfo fs    = new FileInfo(file);
                string   dfile = differential.destination + "/" + file.Remove(0, differential.source.Length);
                FileInfo fd    = new FileInfo(dfile);
                //We first save file with a priority
                if (priorities == true)
                {
                    foreach (string prio in work.priorities)
                    {
                        if (prio == (Path.Combine(differential.destination, file.Substring(differential.destination.Length - 5)).Split('.')[1]))
                        {
                            if (fs.LastWriteTime > fd.LastWriteTime)
                            {
                                //Copy File
                                Console.WriteLine("Source file is more recent ");
                                System.IO.File.Copy(file, System.IO.Path.Combine(differential.destination, file.Substring(differential.destination.Length - 5)), true);
                                Console.WriteLine("Copy has been to be executed");
                                CryptFile(Path.Combine(differential.destination, file.Substring(differential.destination.Length - 5)));
                            }
                            else
                            {
                                //Tellthe user no copy is needed
                                Console.WriteLine(" Destination file is the same than source file, no copy executed");
                            }
                            differential.remainingfiles--;
                            differential.remainingsize -= fs.Length;
                            differential.time           = stopwatch.Elapsed.Seconds;
                            differential.RefreshSaveStat(differential);
                            RunningTasks.AllTasks.Remove(work.informations);
                            work.informations.Progress = 100 - ((differential.remainingsize * 100) / differential.totalsize);
                            provider.TrackProgress(new TaskProgressBar(work.informations.Progress.ToString()));
                        }
                    }
                    provider.EndTransmission();
                }
                else //then we relaunch the method to save all other files
                {
                    foreach (string prio in work.priorities)
                    {
                        if (prio == (Path.Combine(differential.destination, file.Substring(differential.destination.Length - 5)).Split('.')[1]))
                        {
                            if (fs.LastWriteTime > fd.LastWriteTime)
                            {
                                //Copy File
                                Console.WriteLine("Source file is more recent ");
                                System.IO.File.Copy(file, System.IO.Path.Combine(differential.destination, file.Substring(differential.destination.Length - 5)), true);
                                Console.WriteLine("Copy has been to be executed");
                                CryptFile(Path.Combine(differential.destination, file.Substring(differential.destination.Length - 5)));
                            }
                            else
                            {
                                //Tellthe user no copy is needed
                                Console.WriteLine(" Destination file is the same than source file, no copy executed");
                            }
                            differential.remainingfiles--;
                            differential.remainingsize -= fs.Length;
                            differential.time           = stopwatch.Elapsed.Seconds;
                            differential.RefreshSaveStat(differential);
                            RunningTasks.AllTasks.Remove(work.informations);
                            //notifying observers
                            work.informations.Progress = 100 - ((differential.remainingsize * 100) / differential.totalsize);
                            provider.TrackProgress(new TaskProgressBar(work.informations.Progress.ToString()));
                        }
                    }
                    provider.EndTransmission();
                }
            }
        }
Пример #7
0
 public ProgressBarReporterTests()
 {
     _testsProgressLogger = new Mock <IConsoleOneLineLogger>();
     _progressBarReporter = new ProgressBarReporter(_testsProgressLogger.Object, new FixedClock());
 }
Пример #8
0
        private ProgressReporter CreateProgressReporter()
        {
            var progressBarReporter = new ProgressBarReporter(new ProgressBar(), new StopWatchProvider());

            return(new ProgressReporter(progressBarReporter));
        }
Пример #9
0
        //Copying files one by one from source to destination

        void FileCopier(ManualResetEvent ProcessVerif, Work work, bool priorities)
        {
            mirror.remainingfiles = mirror.filecount;
            mirror.remainingsize  = mirror.totalsize;
            DirectoryInfo path = new DirectoryInfo(mirror.source);

            FileInfo[] files = path.GetFiles();
            Console.WriteLine("Starting process...");

            //Initializating the timer and starting it
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            //Implementing observer and observable
            ProgressBarReporter reporter = new ProgressBarReporter();
            ProgressBarTracker  provider = new ProgressBarTracker();

            reporter.Subscribe(provider);

            // Create subdirectory structure in destination
            foreach (string direction in System.IO.Directory.GetDirectories(mirror.source, "*", System.IO.SearchOption.AllDirectories))
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.Combine(mirror.destination, direction.Substring(mirror.source.Length - 5)));
            }
            //We first save file with a priority
            if (priorities)
            {
                foreach (string file in System.IO.Directory.GetFiles(mirror.source, "*", System.IO.SearchOption.AllDirectories))
                {
                    if (work.informations.IsRunning == false)
                    {
                        work.informations.RunningState.WaitOne();
                    }

                    foreach (string prio in work.priorities)
                    {
                        if (prio == (Path.Combine(mirror.destination, file.Substring(mirror.destination.Length - 5)).Split('.')[1]))
                        {
                            ProcessVerif.WaitOne();
                            Console.WriteLine("copying " + file);
                            mirror.currentfiletocopy = file;
                            System.IO.File.Copy(file, System.IO.Path.Combine(mirror.destination, file.Substring(mirror.destination.Length - 5)), true);
                            mirror.remainingfiles--;
                            //Create a FileInfo object "f" with its directory to get the f.Length object's size (in bytes)
                            FileInfo f = new FileInfo(file);
                            work.informations.Progress = 100 - ((mirror.remainingsize * 100) / mirror.totalsize);
                            //notifying progress to the observer
                            provider.TrackProgress(new TaskProgressBar(work.informations.Progress.ToString()));
                            mirror.remainingsize -= f.Length;
                            mirror.time           = stopwatch.Elapsed.Seconds;
                            CryptFile(Path.Combine(mirror.destination, file.Substring(mirror.destination.Length - 5)));
                            mirror.RefreshSaveStat(mirror);
                        }
                    }
                }
                provider.TrackProgress(new TaskProgressBar("100"));
                provider.EndTransmission();
            }
            //Then we save all other files
            else
            {
                foreach (string file in System.IO.Directory.GetFiles(mirror.source, "*", System.IO.SearchOption.AllDirectories))
                {
                    if (work.informations.IsRunning == false)
                    {
                        work.informations.RunningState.WaitOne();
                    }

                    foreach (string prio in work.priorities)
                    {
                        if (prio != (Path.Combine(mirror.destination, file.Substring(mirror.destination.Length - 5)).Split('.')[1]))
                        {
                            ProcessVerif.WaitOne();
                            Console.WriteLine("copying " + file);
                            mirror.currentfiletocopy = file;
                            System.IO.File.Copy(file, System.IO.Path.Combine(mirror.destination, file.Substring(mirror.destination.Length - 5)), true);
                            mirror.remainingfiles--;
                            //Create a FileInfo object "f" with its directory to get the f.Length object's size (in bytes)
                            FileInfo f = new FileInfo(file);
                            work.informations.Progress = 100 - ((mirror.remainingsize * 100) / mirror.totalsize);
                            provider.TrackProgress(new TaskProgressBar(work.informations.Progress.ToString()));
                            mirror.remainingsize -= f.Length;
                            mirror.time           = stopwatch.Elapsed.Seconds;
                            CryptFile(Path.Combine(mirror.destination, file.Substring(mirror.destination.Length - 5)));
                            mirror.RefreshSaveStat(mirror);
                        }
                    }
                }
                provider.TrackProgress(new TaskProgressBar("100"));
                provider.EndTransmission();
            }
        }