Reputation: 315
I'm pretty new to this, and I'm trying to make a test where I can create and delete an object in a mock Database but I have no idea where to start now or how to create that Mock database and read/write to it.
[Fact]
public void CreateCommentaar()
{
//arrange
Commentaar commentaar = new Commentaar
{
CommentaarId = 0,
StadId = 0,
UserId = "testId",
CommentaarText = "text",
Tijdstip = DateTime.Now
};
string queryString = "INSERT INTO Commentaar(UserId, StadId, CommentaarText, Tijdstip) VALUES("
+ commentaar.CommentaarId + " ,"
+ commentaar.UserId + " ,"
+ commentaar.StadId + " ,"
+ commentaar.CommentaarText + " ,"
+ commentaar.Tijdstip + " ,";
//act
//Run Mock sql query
//assert
//1 commentaar object should exist in mock DB now
}
[Fact]
public void DeleteCommentaar()
{
//arrange
Commentaar commentaar = new Commentaar
{
CommentaarId = 0,
StadId = 0,
UserId = "testId",
CommentaarText = "text",
Tijdstip = DateTime.Now
};
string queryString = "INSERT INTO Commentaar(UserId, StadId, CommentaarText, Tijdstip) VALUES("
+ commentaar.CommentaarId + " ,"
+ commentaar.UserId + " ,"
+ commentaar.StadId + " ,"
+ commentaar.CommentaarText + " ,"
+ commentaar.Tijdstip + " ,";
//act
//Run Mock sql query
//assert
//1 commentaar object should be deleted
}
I'm not really sure how to continue from here though.
Upvotes: 1
Views: 898
Reputation: 527
Can't you just start a
string queryString = "SELECT COUNT(id) FROM Commentaar where id = 0"
If that query return 0 it means that your Commentaar has been deleted.
ONE PROBLEM It will only works if your first UT worked and inserted a line with 0 as ID.
Upvotes: 0
Reputation: 2262
There really isn't anything to test here. Testing if something would be inserted in the mock database would be testing your mock logic.
Testing if your sql queries are correct is best done using integration tests and a test database.
Upvotes: 3