private static void Main(string[] args) { var person = new Person(args[0], args[1]); var printer = new PersonPrinter(System.Console.Out); printer.Print(person); }
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 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(); }