public void TestDbHelperForInsertViaTableName() { // Prepare var dbHelper = new Mock <IDbHelper>(); var connection = new CustomDbConnectionForDbHelper(); // Setup dbHelper.Setup(builder => builder.GetFields( It.Is <IDbConnection>(s => s == connection), It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>()), It.IsAny <IDbTransaction>()) ).Returns(GetDbFields()); // Act CommandTextCache.Flush(); DbFieldCache.Flush(); StatementBuilderMapper.Add(typeof(CustomDbConnectionForDbHelper), new SqlServerStatementBuilder(), true); DbHelperMapper.Add(typeof(CustomDbConnectionForDbHelper), dbHelper.Object, true); // Act connection.Insert(ClassMappedNameCache.Get <DataEntityForDbHelper>(), new { Id = 1, Name = "Name" }); // Assert dbHelper.Verify(builder => builder.GetFields( It.Is <IDbConnection>(s => s == connection), It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>()), It.IsAny <IDbTransaction>()), Times.Exactly(1)); }
public void TestDbHelperForInsert() { // Prepare var dbHelper = new Mock <IDbHelper>(); var connection = new CustomDbConnectionForDbHelper(); // Act CommandTextCache.Flush(); DbFieldCache.Flush(); StatementBuilderMapper.Add(typeof(CustomDbConnectionForDbHelper), new SqlStatementBuilder(), true); DbHelperMapper.Add(typeof(CustomDbConnectionForDbHelper), dbHelper.Object, true); // Act connection.Insert <DataEntityForDbHelper>(new DataEntityForDbHelper { Id = 1, Name = "Name" }); // Assert dbHelper.Verify(builder => builder.GetFields( It.Is <string>(s => s == connection.ConnectionString), It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>())), Times.Exactly(1)); }