public void ContactUiTest_AddWithBadTaxIdThrowsException() { //Arrange var inputParms = new Queue <string>(new[] { "add", "friend", "name", "x" }); Func <string> consoledequeue = () => { if (inputParms.Count == 0) { return(string.Empty); } return(inputParms.Dequeue()); }; StringBuilder outputBuilder = new StringBuilder(string.Empty); mockConsole.Setup(x => x.ReadLine()).Returns(consoledequeue); mockConsole.Setup(x => x.WriteLine(It.IsAny <object>())).Callback((object x) => { outputBuilder.Append(x.ToString() + "\r\n"); }); var contactsUi = new ContactsUi(mockConsole.Object); //Act contactsUi.Run(); //Assert StringAssert.Contains(outputBuilder.ToString(), "FormatException: Input string was not in a correct format.\r\n"); }
public void ContactUiTest_ExitWritesGoodbye() { //Arrange StringBuilder outputBuilder = new StringBuilder(string.Empty); mockConsole.Setup(x => x.ReadLine()).Returns(new Queue <string>(new [] { "exit" }).Dequeue); mockConsole.Setup(x => x.WriteLine(It.IsAny <object>())).Callback((object x) => { outputBuilder.Append(x.ToString() + "\r\n"); }); var contactsUi = new ContactsUi(mockConsole.Object); //Act contactsUi.Run(); //Assert var output = outputBuilder.ToString(); StringAssert.Contains(output, "Goodbye!\r\n"); }