public void TestInsert() { //Arrange var commandMock = new Mock <IDbCommand>(); commandMock .Setup(m => m.ExecuteNonQuery()) .Verifiable(); var connectionMock = new Mock <IDbConnection>(); connectionMock .Setup(m => m.CreateCommand()) .Returns(commandMock.Object); var connectionFactoryMock = new Mock <IDbConnectionFactory>(); connectionFactoryMock .Setup(m => m.CreateConnection()) .Returns(connectionMock.Object); var sut = new MyDataAccessClass(connectionFactoryMock.Object); var firstName = "John"; var lastName = "Doe"; //Act sut.Insert(firstName, lastName); //Assert commandMock.Verify(); }
public void TestInsert() { //Arrange var commandMock = new Mock <IDbCommand>(); commandMock .Setup(m => m.ExecuteNonQuery()) .Verifiable(); var connectionMock = new Mock <IDbConnection>(); connectionMock .Setup(m => m.CreateCommand()) .Returns(commandMock.Object); var connectionFactoryMock = new Mock <IDbConnectionFactory>(); connectionFactoryMock .Setup(m => m.CreateConnection()) .Returns(connectionMock.Object); var sut = new MyDataAccessClass(connectionFactoryMock.Object); var name = "Apple Pie"; var numServe = 8; var category = "dessert"; var prepTime = 50; var ingredient = "apple, butter, flour"; var methods = "Not available"; //Act sut.Insert(name, numServe, category, prepTime, ingredient, methods); //Assert commandMock.Verify(); }