Skip to content

Commit

Permalink
Merge pull request sqlkata#606 from sqlkata/feature_334_add_support_f…
Browse files Browse the repository at this point in the history
…or_exists

add test for Exists/NotExists
  • Loading branch information
ahmad-moussawi authored Sep 10, 2022
2 parents 1d21d89 + 294ff51 commit b57ca54
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions QueryBuilder.Tests/MySqlExecutionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ public void InlineTable()
db.Drop("Transaction");
}

[Fact]
public void ExistsShouldReturnFalseForEmptyTable()
{
var db = DB().Create("Transaction", new[] {
"Id INT PRIMARY KEY AUTO_INCREMENT",
"Amount int NOT NULL",
"Date DATE NOT NULL",
});

var exists = db.Query("Transaction").Exists();
Assert.Equal(false, exists);

db.Drop("Transaction");
}

[Fact]
public void ExistsShouldReturnTrueForNonEmptyTable()
{
var db = DB().Create("Transaction", new[] {
"Id INT PRIMARY KEY AUTO_INCREMENT",
"Amount int NOT NULL",
"Date DATE NOT NULL",
});

db.Query("Transaction").Insert(new
{
Date = "2022-01-01",
Amount = 10
});

var exists = db.Query("Transaction").Exists();
Assert.Equal(true, exists);

db.Drop("Transaction");
}

QueryFactory DB()
{
var host = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_HOST");
Expand Down

0 comments on commit b57ca54

Please sign in to comment.