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();
        }
示例#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()}*"));
            }
        }
示例#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, '?'));
            }
        }
示例#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);
        }
        public void Main_Input10_AnswerTooHigh()
        {
            const string expected =
                @"Tic-tac-toe has less than 10 maximum turns.";

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

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

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

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

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

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

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

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

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

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

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

            const string expected =
                "";

            ConsoleAssert.Expect(
                expected, Program.Main);
        }
示例#19
0
        public void Main_Input8_ExitProgram()
        {
            Program.input = 8;

            const string expected =
                @"Exiting";

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

            ConsoleAssert.Expect(expected, () =>
            {
                System.Console.Write(input);
            }, NormalizeOptions.StripAnsiEscapeCodes);
        }
示例#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);
        }
示例#22
0
        public void Main_InputOfNegative1_Exit()
        {
            Program.input = -1;

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

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

            ConsoleAssert.Expect(view, () =>
            {
                System.Console.WriteLine("Hello World");
            }, NormalizeOptions.None);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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"
            }));
        }