public void PrintPersonPrintsCorrectly()
        {
            // Extended MSTest
            Person person = new Person()
            {
                FirstName = "Adam",
                LastName  = "Smith",
                Age       = 36
            };
            PersonPrinter printer = new PersonPrinter();

            ConsoleAssert.WritesOut(
                () => printer.PrintPerson(person),
                "Adam Smith (36)");

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <Person>        _person  = test.CreateVariable <Person>(nameof(_person));
            TestVariable <PersonPrinter> _printer = test.CreateVariable <PersonPrinter>(nameof(_printer));

            test.Arrange(_person, Expr(() => new Person()
            {
                FirstName = "Adam", LastName = "Smith", Age = 36
            }));
            test.Arrange(_printer, Expr(() => new PersonPrinter()));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_printer, _person, (p1, p2) => p1.PrintPerson(p2))),
                Const("Adam Smith (36)"));
            test.Execute();
        }
Ejemplo n.º 2
0
        public void ExecuteProcess_PingLocalhost_Success()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.Inconclusive("Platforms other than windows have not been tested.");

                /* Try the following:
                 * Command: ping.exe -c 4 localhost                 (the '-c 4' limits the ping to 4 times)
                 * PING localhost (104.24.0.68) 56(84) bytes of data.
                 *  64 bytes from 104.24.0.68: icmp_seq=1 ttl=58 time=47.3 ms
                 *  64 bytes from 104.24.0.68: icmp_seq=2 ttl=58 time=51.9 ms
                 *  64 bytes from 104.24.0.68: icmp_seq=3 ttl=58 time=57.4 ms
                 *  64 bytes from 104.24.0.68: icmp_seq=4 ttl=58 time=57.4 ms
                 */
            }
            else
            {
                ConsoleAssert.ExecuteProcess(
                    $@"
Pinging * ?::1? with 32 bytes of data:
Reply from ::1: time*",
                    "ping.exe", "-n 4 localhost", out string standardOutput, out _);
                Assert.IsTrue(standardOutput.ToLower().IsLike($"*{ Environment.MachineName.ToLower()}*"));
            }
        }
Ejemplo n.º 3
0
        public void ProjectionToAnAnonymousType()
        {
            // Required due to defect in MSTest that has the current directory
            // set to the MSTest executable directory, rather than the
            // assembly directory.
            Directory.SetCurrentDirectory(Path.GetDirectoryName(
                                              typeof(Program).GetTypeInfo().Assembly.Location));

            string expectedPattern   = "{ FileName = *, Size = * }";
            int    expectedItemCount = Directory.EnumerateFiles(
                Directory.GetCurrentDirectory(), "*").Count();

            string output = ConsoleAssert.Execute(null, () =>
            {
                Program.Main();
            });

            IEnumerable <string> outputItems = output.Split(
                new string [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.AreEqual(expectedItemCount, outputItems.Count());
            foreach (string item in outputItems)
            {
                Assert.IsTrue(item.IsLike(expectedPattern),
                              $"{item} is not like {expectedPattern}");
            }
        }
        public void Listing14_15_Test()
        {
            // Required due to defect in MSTest that has the current directory
            // set to the MSTest executable directory, rather than the
            // assembly directory.
            Directory.SetCurrentDirectory(Path.GetDirectoryName(
                                              typeof(Program).GetTypeInfo().Assembly.Location));

            //string expectedPattern = $@"{ Directory.GetCurrentDirectory() }{Path.DirectorySeparatorChar}*";
            string expectedPattern   = $@"{ Directory.GetCurrentDirectory() }{ 
                $"{Path.DirectorySeparatorChar}"}*";
            int    expectedItemCount = Directory.EnumerateFiles(
                Directory.GetCurrentDirectory(), "*").Count();
            string output = ConsoleAssert.Execute(null, () =>
            {
                Program.Main();
            });

            IEnumerable <string> outputItems = output.Split(
                new string[] { Environment.NewLine }, StringSplitOptions.None);

            Assert.AreEqual <int>(
                expectedItemCount, outputItems.Count());
            foreach (string item in outputItems)
            {
                Assert.IsTrue(item.IsLike(expectedPattern, '?'));
            }
        }
Ejemplo n.º 5
0
        public void MainRunsEventManager()
        {
            ConsoleAssert.Expect(@"What do you want to do?
1. Create a course
2. Create an event
3. List events
4. Exit<<4", Program.Main);
        }
Ejemplo n.º 6
0
        public void Main_Input10_AnswerTooHigh()
        {
            const string expected =
                @"Tic-tac-toe has less than 10 maximum turns.";

            ConsoleAssert.Expect(
                expected, () => Program.Main("10"));
        }
Ejemplo n.º 7
0
        public void Main_Input5_AnswerTooLow()
        {
            const string expected =
                @"Tic-tac-toe has more than 5 maximum turns.";

            ConsoleAssert.Expect(
                expected, () => Program.Main("5"));
        }
Ejemplo n.º 8
0
        public void Main_Input9_CorrectAnswer()
        {
            const string expected =
                @"Correct, tic-tac-toe has a maximum of 9 turns.";

            ConsoleAssert.Expect(
                expected, () => Program.Main("9"));
        }
Ejemplo n.º 9
0
        public void Main_InputOfNegative1_Exit()
        {
            const string expected =
                @"Exiting...";

            ConsoleAssert.Expect(
                expected, () => Program.Main("-1"));
        }
Ejemplo n.º 10
0
        public void Main_Input8_ExitProgram()
        {
            const string expected =
                @"Exiting";

            ConsoleAssert.Expect(
                expected, () => Program.Main("8"));
        }
Ejemplo n.º 11
0
        public void Main_Input10_ProgramDoesNotExit()
        {
            const string expected =
                "";

            ConsoleAssert.Expect(
                expected, () => Program.Main("10"));
        }
Ejemplo n.º 12
0
        public void ConsoleTester_HelloWorld_TrimLF()
        {
            string view = "Hello World\n";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.WriteLine("Hello World");
            }, true);
        }
Ejemplo n.º 13
0
        public void ConsoleTester_HelloWorld_NoInput()
        {
            string view = @"Hello World";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.Write("Hello World");
            });
        }
Ejemplo n.º 14
0
        public void ConsoleTester_HelloWorld_NoInput()
        {
            const string view = "Hello World";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.Write("Hello World");
            }, NormalizeOptions.None);
        }
Ejemplo n.º 15
0
 public void ConsoleTester_StringWithVT100Characters_VT100Stripped(string input,
                                                                   string expected,
                                                                   bool stripVT100)
 {
     ConsoleAssert.Expect(expected, () =>
     {
         System.Console.WriteLine(input);
     });
 }
Ejemplo n.º 16
0
        public void ConsoleTester_HelloWorld_TrimCRLF()
        {
            const string view = "Hello World";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.Write("Hello World");
            });
        }
Ejemplo n.º 17
0
        public void ConsoleTester_HelloWorld_MissingNewline()
        {
            string view = @"Hello World
";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.WriteLine("Hello World");
            });
        }
Ejemplo n.º 18
0
        public void Main_Input10_ProgramDoesNotExit()
        {
            Program.input = 10;

            const string expected =
                "";

            ConsoleAssert.Expect(
                expected, Program.Main);
        }
Ejemplo n.º 19
0
        public void Main_Input8_ExitProgram()
        {
            Program.input = 8;

            const string expected =
                @"Exiting";

            ConsoleAssert.Expect(
                expected, Program.Main);
        }
Ejemplo n.º 20
0
        public void ConsoleTester_ExplicitStrippingExplicitly_VT100Stripped()
        {
            string input    = "\u001b[49mMontoya";
            string expected = "Montoya";

            ConsoleAssert.Expect(expected, () =>
            {
                System.Console.Write(input);
            }, NormalizeOptions.StripAnsiEscapeCodes);
        }
Ejemplo n.º 21
0
        public void ConsoleTester_OutputIncludesPluses_PlusesAreNotStripped(string consoleInput)
        {
            Exception exception = Assert.ThrowsException <Exception>(() => {
                ConsoleAssert.Expect(consoleInput, () => {
                    System.Console.Write(""); // Always fail
                }, NormalizeOptions.None);
            });

            StringAssert.Contains(exception.Message, consoleInput);
        }
Ejemplo n.º 22
0
        public void Main_InputOfNegative1_Exit()
        {
            Program.input = -1;

            const string expected =
                @"Exiting...";

            ConsoleAssert.Expect(
                expected, Program.Main);
        }
Ejemplo n.º 23
0
        public void ConsoleTester_HelloWorld_MissingNewline()
        {
            const string view = @"Hello World
";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.WriteLine("Hello World");
            }, NormalizeOptions.None);
        }
Ejemplo n.º 24
0
        public void Main_EnterOther_TwoPlayerPathSelected()
        {
            const string expected =
                @"1 - Play against the computer
2 - Play against another player.
Choose:<<9
>>Play against another player.";

            ConsoleAssert.Expect(
                expected, TicTacToe.Main);
        }
Ejemplo n.º 25
0
        public void Main_Enter1TryToPlayAgainstComputer_ComputerPathSelected()
        {
            const string expected =
                @"1 - Play against the computer
2 - Play against another player.
Choose:<<1
>>Play against computer selected.";

            ConsoleAssert.Expect(
                expected, TicTacToe.Main);
        }
Ejemplo n.º 26
0
        public void ConsoleTester_HelloWorld_DontNormalizeCRLF()
        {
            const string view = "Hello World\r\n";

            Assert.ThrowsException <Exception>(() =>
            {
                ConsoleAssert.Expect(view, () =>
                {
                    System.Console.Write("Hello World\r");
                }, NormalizeOptions.None);
            });
        }
        public string DisplayDigits(int n)
        {
            _test.Method(
                "DisplayDigits",
                BindingFlags.Public | BindingFlags.Instance,
                new Param <int>("n")
                );

            string output = ConsoleAssert.Run(() => _object.DisplayDigits(n));

            return(output);
        }
Ejemplo n.º 28
0
        public void GivenStringLiteral_ExpectedOutputNormalized_OutputMatches()
        {
            const string view = @"Begin
Middle
End";

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.WriteLine("Begin");
                System.Console.WriteLine("Middle");
                System.Console.WriteLine("End");
            });
        }
        public string DisplayBox(int rows, int columns, char fills)
        {
            _test.Method(
                "DisplayBox",
                BindingFlags.Public | BindingFlags.Instance,
                new Param <int>("row"),
                new Param <int>("column"),
                new Param <char>("fillCharacter")
                );

            string output = ConsoleAssert.Run(() => _object.DisplayBox(rows, columns, fills));

            return(output);
        }
Ejemplo n.º 30
0
        public void Main_HospitalEmergencyCodes_DisplaysCodes()
        {
            const string expected =
                @"info: Console[0]
      Hospital Emergency Codes: = 'black', 'blue', 'brown', 'CBR', 'orange', 'purple', 'red', 'yellow'
warn: Console[0]
      This is a test of the emergency...
";

            ConsoleAssert.Expect(expected, () => Program.Main(new[]
            {
                "black", "blue", "brown", "CBR",
                "orange", "purple", "red", "yellow"
            }));
        }