I have try to test PostgreSQL [Does PostgreSQL work properly ?]. I have read a little bit about Moq when we have to do unit testing. So I have 3 questions.
1 When we do Arrange [AAA pattern] Do we have to moq configuration database and input before testing SQL execution?
2 Based on first question. If it required for moq then What is different if i just set up normally like this
DumpDatabase databaseSetting = new DumpDatabase();
databaseSetting.Host = "***.***.*.*.*";
databaseSetting.Port = "****";
databaseSetting.Database = "*****";
databaseSetting.UserName = "****";
databaseSetting.Password = **********";
instead of
var mockdb = new Mock<DumpDatabase>();
mockdb.Setup(x => x.dumpDatabase).Returns(
new DumpDatabase()
{
Host = "***.***.*.*.*",
Port = "****",
Database = "*******",
UserName = "*****",
Password = "***********"
}
);
3 If Query has been passed, i have to roll back original in every single test right ?
For example
string query = "INSERT INTO pictures (id, created, width, height, device_id, user_id, modified, checksum, file_path, file_extension, file_size, mime_type, thumbnail, title, classification, description)" +
" VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12::mime, @p13, @p14, @p15::classification, @p16); ";
then i need to roll back original After Assert [AAA pattern] by doing this
string sqlDelete = "DELETE FROM public.pictures WHERE id = @p1;";