public void Test_Performs_MakeListBookCommand_Execute_WithCorrectArgument() { //arrange string namespaceURI = String.Empty; string expectedTitle = "Expected Title"; string expectedAuthor = "Expected Author"; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(String.Format( "<books><book><title>{0}</title><author>{1}</author></book></books>", expectedTitle, expectedAuthor)); //needed for the mock setup XmlElement rootElement = xmlDocument.DocumentElement; XmlNode testNode = rootElement.SelectSingleNode(String.Format(@"/books")); Mock <IMakeList <Book> > mockMakeListBookCommand = new Mock <IMakeList <Book> >(); mockMakeListBookCommand.Setup(c => c.ExecuteMakeListBook(testNode)); GetAllBooksCommand cmd = new GetAllBooksCommand(xmlDocument, mockMakeListBookCommand.Object); //act var actual = cmd.ExecuteGetAllBooks(); //assert - prove mockMakeListBookCommand.Verify(c => c.ExecuteMakeListBook(testNode), Times.Once()); }
static void Main() { string fileLocation = "books.xml"; GetAllBooksCommandFactory fac = new GetAllBooksCommandFactory( fileLocation, new XmlDocument()); GetAllBooksCommand cmd = fac.GetCommand(); List <Book> list = cmd.ExecuteGetAllBooks(); }
public void GetAllBooksCommand_When_NoXmlDocumentProvided_Throws_MissingXmlDocumentInXMLCommandException() { //Arrange int exceptions = 0; //Act try { GetAllBooksCommand cmd = new GetAllBooksCommand(null, new MakeListBookCommand()); var actual = cmd.ExecuteGetAllBooks(); } catch (MissingXmlDocumentInXmlCommandException) { exceptions++; } //Assert Assert.AreEqual(1, exceptions); }