Example #1
0
        public void Run()
        {
            string result = "";

            io = new IOConsole();

            for (int i = 100; i <= MAXLENGTH; i--)
            {
                if (i < MINLENGTH)
                {
                    break;
                }
                if (i % 9 == 0)
                {
                    result += "Jazz";
                }
                if (i % 4 == 0)
                {
                    result += "Fuzz";
                }
                if (i % 9 != 0 && i % 4 != 0)
                {
                    result += i.ToString();
                }
                result += "\n";
            }
            io.writeConsoleLine(result);
        }
Example #2
0
        public void ShouldDisplayEventsFromCertainDate()
        {
            Events newEvents = new Events();
            IOConsole toDisplay = new IOConsole();

            string expectedConsole;
            var consoleOut = new StringWriter();

            string date = "2019/12/25";
            string title = "Christmas Day!";
            string description = "Santa Claus is comming in our house....";

            string date1 = "2015/10/25";
            string title1 = "Johana's Birtday!";
            string description1 = "Don't forget to call her...";

            SetExpectedResultToConsole(date1, title1,out expectedConsole, out consoleOut, description1);

            newEvents.EventsList.ShouldBeEmpty();
            newEvents.Add(date, title, description);
            newEvents.Add(date1, title1, description1);

            DateFilter eventsToDisplay = new DateFilter("=", "2015/10/25");
            Events filteredList = eventsToDisplay.ApplyFilter(newEvents);

            IOConsole newObj = new IOConsole(filteredList);
            newObj.DisplayEventsToConsole();
            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #3
0
        public void ShouldDisplayAllEvents()
        {
            Events newEvent = new Events();

            string expectedConsole;
            var consoleOut = new StringWriter();

            string date = "2015/12/25";
            string title = "Christmas Day!";
            string description = "Santa Claus is comming in our house....";

            newEvent.EventsList.ShouldBeEmpty();
            newEvent.Add(date, title, description);

            string date1 = "2015/10/25";
            string title1 = "Johana's Birtday!";
            string description1 = "Don't forget to call her...";
            newEvent.Add(date1, title1, description1);

            expectedConsole = " \nDate:" + Convert.ToDateTime(date1).ToString("yyyy/MM/dd") + " \nTitle:" + title1 + " \nDescription:" + description1 + "\n" +
                " \nDate:" + Convert.ToDateTime(date).ToString("yyyy/MM/dd") + " \nTitle:" + title + " \nDescription:" + description;

            Console.SetOut(consoleOut);
            IOConsole newObj = new IOConsole(newEvent);
            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #4
0
        public void ShouldDisplayEventsBeetwenTwoDate()
        {
            IOConsole toDisplay = new IOConsole();

            string expectedConsole;
            var    consoleOut = new StringWriter();

            Events newEvents = new Events {
                { new Event("2015/01/01", "one", "test") },
                { new Event("2015/11/15", "two") },
                { new Event("2015/07/01", "three") },
                { new Event("2015/12/03", "four", "test1") },
                { new Event("2015/03/04", "five", "test2") },
                { new Event("2015/09/08", "six") }
            };

            SetExpectedResultToConsole("2015/09/08", "six", out expectedConsole, out consoleOut);

            DateFilter firstFilter       = new DateFilter("<", "2015/10/25");
            Events     firstFilteredList = firstFilter.ApplyFilter((newEvents));
            DateFilter eventsToDisplay   = new DateFilter(">", "2015/02/25");
            Events     filteredList      = eventsToDisplay.ApplyFilter(firstFilteredList);

            IOConsole newObj = new IOConsole(filteredList);

            newObj.DisplayEventsToConsole();
            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #5
0
        public void ShouldDisplayAllEvents()
        {
            Events newEvent = new Events();

            string expectedConsole;
            var    consoleOut = new StringWriter();

            string date        = "2015/12/25";
            string title       = "Christmas Day!";
            string description = "Santa Claus is comming in our house....";

            newEvent.EventsList.ShouldBeEmpty();
            newEvent.Add(date, title, description);

            string date1        = "2015/10/25";
            string title1       = "Johana's Birtday!";
            string description1 = "Don't forget to call her...";

            newEvent.Add(date1, title1, description1);

            expectedConsole = " \nDate:" + Convert.ToDateTime(date1).ToString("yyyy/MM/dd") + " \nTitle:" + title1 + " \nDescription:" + description1 + "\n" +
                              " \nDate:" + Convert.ToDateTime(date).ToString("yyyy/MM/dd") + " \nTitle:" + title + " \nDescription:" + description;


            Console.SetOut(consoleOut);
            IOConsole newObj = new IOConsole(newEvent);

            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #6
0
        public void ShouldDisplayEventsBeetwenTwoDate()
        {
            IOConsole toDisplay = new IOConsole();

            string expectedConsole;
            var consoleOut = new StringWriter();

            Events newEvents = new Events {
                { new Event ( "2015/01/01", "one", "test") },
                {new Event("2015/11/15", "two") },
                { new Event("2015/07/01", "three") },
                { new Event("2015/12/03", "four", "test1") },
                { new Event("2015/03/04", "five", "test2") },
                { new Event("2015/09/08", "six") }
            };

               SetExpectedResultToConsole("2015/09/08", "six", out expectedConsole, out consoleOut);

            DateFilter firstFilter = new DateFilter( "<", "2015/10/25");
            Events firstFilteredList = firstFilter.ApplyFilter((newEvents));
            DateFilter eventsToDisplay = new DateFilter( ">", "2015/02/25");
            Events filteredList = eventsToDisplay.ApplyFilter(firstFilteredList);

            IOConsole newObj = new IOConsole(filteredList);
            newObj.DisplayEventsToConsole();
            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #7
0
        public void ShouldDisplayEventsFromCertainDate()
        {
            Events    newEvents = new Events();
            IOConsole toDisplay = new IOConsole();

            string expectedConsole;
            var    consoleOut = new StringWriter();

            string date        = "2019/12/25";
            string title       = "Christmas Day!";
            string description = "Santa Claus is comming in our house....";

            string date1        = "2015/10/25";
            string title1       = "Johana's Birtday!";
            string description1 = "Don't forget to call her...";

            SetExpectedResultToConsole(date1, title1, out expectedConsole, out consoleOut, description1);

            newEvents.EventsList.ShouldBeEmpty();
            newEvents.Add(date, title, description);
            newEvents.Add(date1, title1, description1);

            DateFilter eventsToDisplay = new DateFilter("=", "2015/10/25");
            Events     filteredList    = eventsToDisplay.ApplyFilter(newEvents);

            IOConsole newObj = new IOConsole(filteredList);

            newObj.DisplayEventsToConsole();
            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #8
0
        public void TestOverwrite()
        {
            var mockInput  = new Mock <IInput>();
            var mockOutput = new Mock <IOutput>();

            mockOutput.Setup((o) => o.Options)
            .Returns(OutputOptions.VerbosityNormal);

            mockOutput.Setup((o) => o.Formatter)
            .Returns(new OutputFormatter());

            var ioConsole = new IOConsole(mockInput.Object, mockOutput.Object);

            ioConsole.Write("something (<question>strlen = 23</question>)");
            ioConsole.Overwrite("shorter (<comment>12</comment>)", false);
            ioConsole.Overwrite("something longer than initial (<info>34</info>)", false);

            mockOutput.Verify((o) => o.Write("something (<question>strlen = 23</question>)", true, OutputOptions.VerbosityNormal), Times.Once());
            mockOutput.Verify((o) => o.Write(Str.Repeat("\x08", 23), false, OutputOptions.VerbosityNormal), Times.Once());
            mockOutput.Verify((o) => o.Write("shorter (<comment>12</comment>)", false, OutputOptions.VerbosityNormal), Times.Once());
            mockOutput.Verify((o) => o.Write(Str.Repeat(11), false, OutputOptions.VerbosityNormal), Times.Once());
            mockOutput.Verify((o) => o.Write(Str.Repeat("\x08", 11), false, OutputOptions.VerbosityNormal), Times.Once());
            mockOutput.Verify((o) => o.Write(Str.Repeat("\x08", 12), false, OutputOptions.VerbosityNormal), Times.Once());
            mockOutput.Verify((o) => o.Write("something longer than initial (<info>34</info>)", false, OutputOptions.VerbosityNormal), Times.Once());
        }
Example #9
0
 public static void AddEvents(string[] args)
 {
     IOConsole newEvent = new IOConsole();
     string date = args[1]; ;
     string title = Utils.CodingNewLineChar(args[2]);
     string description = "";
     if (args.Length == 4)
     {
         description = Utils.CodingNewLineChar(args[3]);
     }
     newEvent.AddDataFromConsole(date, title, description);
 }
Example #10
0
        public void TestIsVeryVerbose()
        {
            var mockInput  = new Mock <IInput>();
            var mockOutput = new Mock <IOutput>();

            mockOutput.SetupSequence((o) => o.IsVeryVerbose)
            .Returns(true)
            .Returns(false);

            var ioConsole = new IOConsole(mockInput.Object, mockOutput.Object);

            Assert.IsTrue(ioConsole.IsVeryVerbose);
            Assert.IsFalse(ioConsole.IsVeryVerbose);
        }
Example #11
0
        public void TestWrite()
        {
            var mockInput  = new Mock <IInput>();
            var mockOutput = new Mock <IOutput>();

            mockOutput.Setup((o) => o.Options)
            .Returns(OutputOptions.VerbosityNormal);

            var ioConsole = new IOConsole(mockInput.Object, mockOutput.Object);

            ioConsole.Write("foo bar menghanyu zzz", true);

            mockOutput.Verify((o) => o.Write("foo bar menghanyu zzz", true, OutputOptions.VerbosityNormal));
        }
Example #12
0
        public void TestWriteWithDebugging()
        {
            var mockInput  = new Mock <IInput>();
            var mockOutput = new Mock <IOutput>();

            mockOutput.Setup((o) => o.Options)
            .Returns(OutputOptions.VerbosityNormal);

            var ioConsole = new IOConsole(mockInput.Object, mockOutput.Object);
            var stopwatch = new Stopwatch();

            ioConsole.SetDebugging(stopwatch);
            stopwatch.Start();
            ioConsole.Write("hello world", true);

            mockOutput.Verify((o) => o.Write(It.IsRegex(@"^\[(.*)/(.*)\] hello world$"), true, OutputOptions.VerbosityNormal));
        }
Example #13
0
 public static void ExportEvents(string[] args)
 {
     TXTFile files = new TXTFile();
     Events eventsList = files.LoadEventsFromFile();
     eventsList.Sort();
     if (args.Length == 2)
     {
         ExportToHTMLFile(@args[1], eventsList);
     }
     else
     {
         IOConsole evTools = new IOConsole();
         string criteria = Utils.ParseFilteringCriteria(args[1]);
         Events eventsToExport = SimpleDateFiltering(eventsList, criteria, DateTime.Today.ToShortDateString());
         ExportToHTMLFile(@args[2], eventsToExport);
     }
 }
Example #14
0
        public static void DisplayEvents(string parameter)
        {
            TXTFile files = new TXTFile();
            Events eventsList = files.LoadEventsFromFile();
            IOConsole display = new IOConsole(eventsList);

            if (parameter == "all")
            {
                display.DisplayEventsToConsole();
            }
            else
            {
                string criteria = Utils.ParseFilteringCriteria(parameter);
                Events eventsToDisplay = SimpleDateFiltering(eventsList, criteria, DateTime.Today.ToShortDateString());
                IOConsole toDisplay = new IOConsole(eventsToDisplay);
                toDisplay.DisplayEventsToConsole();
            }
        }
Example #15
0
        public void ShouldNotDisplayEventsForEmptyCalendar()
        {
            Events newEvent = new Events();

            newEvent.EventsList.ShouldBeEmpty();

            string expectedConsole = "";

            var consoleOut = new StringWriter();

            Console.SetOut(consoleOut);

            IOConsole newObj = new IOConsole(newEvent);

            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #16
0
        public void ShouldDisplayOneEventWithoutDescription()
        {
            Events       newEvent = new Events();
            string       expectedConsole;
            StringWriter consoleOut;

            string date  = "2015/12/25";
            string title = "Christmas Day!";

            SetExpectedResultToConsole(date, title, out expectedConsole, out consoleOut);

            newEvent.EventsList.ShouldBeEmpty();
            newEvent.Add(date, title);

            IOConsole newObj = new IOConsole(newEvent);

            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #17
0
        /// <summary>
        /// Track specified intput/output.
        /// </summary>
        /// <param name="io">The specified intput/output.</param>
        /// <param name="options">The option with <see cref="AbstractTester"/>.</param>
        /// <returns>Tracked intput/output.</returns>
        public IOConsole Track(IOConsole io, params Mixture[] options)
        {
            var input = new InputArgs();

            if (options.TryGet("interactive", out Mixture exists))
            {
                input.SetInteractive(exists);
            }

            if (inputs != null && inputs.Length > 0)
            {
                input.SetInputStream(CreateStream(inputs));
            }

            Initialize(options);
            io.SetInput(input);
            io.SetOutput(Output);

            return(io);
        }
Example #18
0
        public void ShouldDisplayMulytiLineOneEvent()
        {
            Events       newEvent = new Events();
            string       expectedConsole;
            StringWriter consoleOut;

            string date        = "2015/12/25";
            string title       = "Christmas \n Day!";
            string description = "Santa Claus is comming in our house....\n";

            SetExpectedResultToConsole(date, title, out expectedConsole, out consoleOut, description);

            newEvent.EventsList.ShouldBeEmpty();
            newEvent.Add(date, title, description);

            IOConsole newObj = new IOConsole(newEvent);

            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #19
0
        public void TestNonSatisfiedVerbosityWriteNotRecordLastMessage()
        {
            var mockInput       = new Mock <IInput>();
            var mockErrorOutput = new Mock <IOutput>();
            var mockOutput      = new Mock <IOutputConsole>();

            mockOutput.Setup((o) => o.Options)
            .Returns(OutputOptions.VerbosityNormal | OutputOptions.OutputPlain);

            mockOutput.Setup((o) => o.GetErrorOutput())
            .Returns(mockErrorOutput.Object);

            var ioConsole = new IOConsole(mockInput.Object, mockOutput.Object);

            ioConsole.WriteError("foo", false);
            ioConsole.WriteError("foo bar baz", true, Verbosities.Debug);
            ioConsole.OverwriteError("bar", false);

            mockErrorOutput.Verify((o) => o.Write("foo", false, OutputOptions.VerbosityNormal), Times.Once());
            mockErrorOutput.Verify((o) => o.Write("foo bar baz", true, OutputOptions.VerbosityDebug), Times.Once());
            mockErrorOutput.Verify((o) => o.Write("\x08\x08\x08", false, OutputOptions.VerbosityNormal), Times.Once());
            mockErrorOutput.Verify((o) => o.Write("bar", false, OutputOptions.VerbosityNormal), Times.Once());
        }
Example #20
0
        public void Run()
        {
            string result = "";

            io = new IOConsole();

            for (int i = 1; i <= MAXLENGTH; i++)
            {
                if (i % 3 == 0)
                {
                    result += "Fizz";
                }
                if (i % 5 == 0)
                {
                    result += "Buzz";
                }
                if (i % 3 != 0 && i % 5 != 0)
                {
                    result += i.ToString();
                }
                result += "\n";
            }
            io.writeConsoleLine(result);
        }
Example #21
0
        public static Events SearchEvents(Events eventsList, string field, string op, string[] values)
        {
            Events filteredList = FilterEvents(eventsList, field, op, values);

            IOConsole toDisplay = new IOConsole(filteredList);
            toDisplay.DisplayEventsToConsole();
            return filteredList;
        }
Example #22
0
        public void ShouldNotDisplayEventsForEmptyCalendar()
        {
            Events newEvent = new Events();

            newEvent.EventsList.ShouldBeEmpty();

            string expectedConsole = "";

            var consoleOut = new StringWriter();
            Console.SetOut(consoleOut);

            IOConsole newObj = new IOConsole(newEvent);
            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #23
0
        public void ShouldDisplayOneEventWithoutDescription()
        {
            Events newEvent = new Events();
            string expectedConsole;
            StringWriter consoleOut;

            string date = "2015/12/25";
            string title = "Christmas Day!";
            SetExpectedResultToConsole(date, title, out expectedConsole, out consoleOut);

            newEvent.EventsList.ShouldBeEmpty();
            newEvent.Add(date, title);

            IOConsole newObj = new IOConsole(newEvent);
            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #24
0
        public void ShouldDisplayOneEvent()
        {
            Events newEvent = new Events();
            string expectedConsole;
            StringWriter consoleOut;

            string date = "2015/12/25";
            string title = "Santa Claus";
            string description = "Santa Claus is comming in our house....";
            SetExpectedResultToConsole(date, title,out expectedConsole, out consoleOut,description);

            newEvent.EventsList.ShouldBeEmpty();
            newEvent.Add(date, title,description);

            IOConsole newObj = new IOConsole(newEvent);
            newObj.DisplayEventsToConsole();

            consoleOut.ToString().ShouldContain(expectedConsole);
        }
Example #25
0
 public Research()
 {
     _console = new IOConsole();
     CounterReset();
 }
Example #26
0
        /// <inheritdoc />
        protected override int DoRun(IInput input, IOutput output)
        {
            disablePluginsByDefault = input.HasRawOption("--no-plugins");
            var ioConsole = new IOConsole(input, output);

            io = ioConsole;

            var commandName = GetCommandName(input);

            TryGetCommand(commandName, out BaseCommand command);

            LoadPluginCommands(command);

            var isProxyCommand = false;

            if (!string.IsNullOrEmpty(commandName) || command != null)
            {
                // Maybe the command is provided by the plugin. If we can't find
                // us again, we will stop intercepting the exception.
                if (command == null)
                {
                    command = Find(commandName);
                }

                isProxyCommand = command is Command.BaseCommand baseCommand && baseCommand.IsProxyCommand;
            }

            if (!isProxyCommand)
            {
                io.WriteError(
                    $"Running {Bucket.GetVersionPretty()} ({Bucket.GetVersion()},{Bucket.GetReleaseDataPretty()}) on {Platform.GetOSInfo()}",
                    verbosity: Verbosities.Debug);

                if (!(command is CommandSelfUpdate) && Bucket.IsDev && (DateTime.Now - Bucket.GetReleaseData()) > new TimeSpan(60, 0, 0, 0, 0))
                {
                    io.WriteError(
                        "<warning>Warning: This development build of bucket is over 60 days old. It is recommended to update it by running \"self-update\" to get the latest version.</warning>");
                }
            }

            Stopwatch stopWatch = null;

            try
            {
                if (input.HasRawOption("--profile"))
                {
                    stopWatch = new Stopwatch();
                    ioConsole.SetDebugging(stopWatch);
                }

                stopWatch?.Start();
                var exitCode = base.DoRun(input, output);
                stopWatch?.Stop();

                if (stopWatch != null)
                {
                    var memoryUsage = AbstractHelper.FormatMemory(Environment.WorkingSet);
                    var timeSpent   = stopWatch.Elapsed;
                    io.WriteError(string.Empty);
                    io.WriteError($"<info>Memory usage: {memoryUsage}, total time: {timeSpent.TotalSeconds.ToString("0.00")}s</info>");
                    io.WriteError(string.Empty);
                }

                return(exitCode);
            }
            catch (ScriptExecutionException ex)
            {
                return(ex.ExitCode);
            }
        }