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();
        }
        public void ConsoleLoggerWritesToConsole()
        {
            ConsoleLogger logger = new ConsoleLogger();

            string expectedWriteout = "Customer Ryan Johnson was deleted";

            ConsoleAssert.WritesOut(() => logger.Log("Customer Ryan Johnson was deleted"), expectedWriteout);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <ConsoleLogger> _logger = test.CreateVariable <ConsoleLogger>();

            test.Arrange(_logger, Expr(() => new ConsoleLogger()));
            test.ConsoleAssert.WritesOut(Lambda(Expr(_logger, l => l.Log("Customer Ryan Johnson was deleted"))), Const(expectedWriteout));
            test.Execute();
        }
예제 #3
0
        public void ConsoleControllerHandleInputGreets()
        {
            // MSTest Extended
            ConsoleController controller = new ConsoleController();

            ConsoleAssert.WritesOut(() => controller.HandleInput("Greet World"), "Hello World");

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <ConsoleController> _controller = test.CreateVariable <ConsoleController>();

            test.Arrange(_controller, Expr(() => new ConsoleController()));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_controller, c => c.HandleInput("Greet World"))),
                Const("Hello World"));
            test.Execute();
        }
예제 #4
0
        public void ConsoleControllerHandleInputErrors()
        {
            ConsoleController controller = new ConsoleController();

            ConsoleAssert.WritesOut(
                () => controller.HandleInput("NonExistentCommand Hello World"),
                "Command NonExistentCommand not found");

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <ConsoleController> _controller = test.CreateVariable <ConsoleController>();

            test.Arrange(_controller, Expr(() => new ConsoleController()));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_controller, c => c.HandleInput("NonExistentCommand Hello World"))),
                Const("Command NonExistentCommand not found"));
            test.Execute();
        }
예제 #5
0
        public void FileExplorerPrintTreePrintsCorrectOutput()
        {
            DirectoryInfo directoryInfo = new DirectoryInfo("../../../directory/");
            FileExplorer  explorer      = new FileExplorer();

            string expectedOutput = ProduceExpectedPrintTreeOutput(directoryInfo, 0);

            ConsoleAssert.WritesOut(() => explorer.PrintTree(directoryInfo), expectedOutput);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <FileExplorer> _explorer = test.CreateVariable <FileExplorer>();

            test.Arrange(_explorer, Expr(() => new FileExplorer()));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_explorer, e => e.PrintTree(directoryInfo))),
                Const(expectedOutput));
            test.Execute();
        }
예제 #6
0
        public void ConsoleControllerHandleInputErrors3()
        {
            // MSTest Extended
            ConsoleController controller = new ConsoleController();

            ConsoleAssert.WritesOut(
                () => controller.HandleInput(""),
                "Please provide a command");

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <ConsoleController> _controller = test.CreateVariable <ConsoleController>();

            test.Arrange(_controller, Expr(() => new ConsoleController()));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_controller, c => c.HandleInput(""))),
                Const("Please provide a command"));
            test.Execute();
        }
예제 #7
0
        public void ConsoleConstrollerAddCommandAddsCommand()
        {
            // MSTest Extended
            ConsoleController controller = new ConsoleController();

            controller.AddCommand("SayGoodbye", s => Console.WriteLine("Goodbye " + s));

            ConsoleAssert.WritesOut(
                () => controller.HandleInput("SayGoodbye World"),
                "Goodbye World");

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <ConsoleController> _controller = test.CreateVariable <ConsoleController>();

            test.Arrange(_controller, Expr(() => new ConsoleController()));
            test.Act(Expr(_controller, (c) => c.AddCommand("SayGoodbye", s => Console.WriteLine("Goodbye " + s))));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_controller, c => c.HandleInput("SayGoodbye World"))),
                Const("Goodbye World"));
            test.Execute();
        }
        public void PrintFamilyPrintsCorrectly()
        {
            // Extended MSTest
            Person person = new Person()
            {
                FirstName = "Robin",
                LastName  = "Rich",
                Age       = 10,
                Mother    = new Person()
                {
                    FirstName = "Anna",
                    LastName  = "Smith",
                    Age       = 38
                },
                Father = new Person()
                {
                    FirstName = "Warren",
                    LastName  = "Rich",
                    Age       = 36,
                    Mother    = new Person()
                    {
                        FirstName = "Elsa",
                        LastName  = "Johnson",
                        Age       = 65
                    },
                    Father = new Person()
                    {
                        FirstName = "Gustav",
                        LastName  = "Rich",
                        Age       = 66
                    }
                }
            };
            PersonPrinter printer = new PersonPrinter();

            string expectedOutput = string.Join(
                Environment.NewLine,
                "Robin Rich (10)",
                "Warren Rich (36)",
                "Gustav Rich (66)",
                "Elsa Johnson (65)",
                "Anna Smith (38)");

            ConsoleAssert.WritesOut(() => printer.PrintFamily(person), expectedOutput);

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

            test.Arrange(_person, Expr(() => new Person()
            {
                FirstName = "Robin",
                LastName  = "Rich",
                Age       = 10,
                Mother    = new Person()
                {
                    FirstName = "Anna",
                    LastName  = "Smith",
                    Age       = 38
                },
                Father = new Person()
                {
                    FirstName = "Warren",
                    LastName  = "Rich",
                    Age       = 36,
                    Mother    = new Person()
                    {
                        FirstName = "Elsa",
                        LastName  = "Johnson",
                        Age       = 65
                    },
                    Father = new Person()
                    {
                        FirstName = "Gustav",
                        LastName  = "Rich",
                        Age       = 66
                    }
                }
            }));
            test.ConsoleAssert.WritesOut(
                Lambda(Expr(_printer, _person, (p1, p2) => p1.PrintFamily(p2))),
                Const(expectedOutput));
            test.Execute();
        }