Skip to content

Commit b57ca54

Browse files
Merge pull request #606 from sqlkata/feature_334_add_support_for_exists
add test for Exists/NotExists
2 parents 1d21d89 + 294ff51 commit b57ca54

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

QueryBuilder.Tests/MySqlExecutionTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ public void InlineTable()
164164
db.Drop("Transaction");
165165
}
166166

167+
[Fact]
168+
public void ExistsShouldReturnFalseForEmptyTable()
169+
{
170+
var db = DB().Create("Transaction", new[] {
171+
"Id INT PRIMARY KEY AUTO_INCREMENT",
172+
"Amount int NOT NULL",
173+
"Date DATE NOT NULL",
174+
});
175+
176+
var exists = db.Query("Transaction").Exists();
177+
Assert.Equal(false, exists);
178+
179+
db.Drop("Transaction");
180+
}
181+
182+
[Fact]
183+
public void ExistsShouldReturnTrueForNonEmptyTable()
184+
{
185+
var db = DB().Create("Transaction", new[] {
186+
"Id INT PRIMARY KEY AUTO_INCREMENT",
187+
"Amount int NOT NULL",
188+
"Date DATE NOT NULL",
189+
});
190+
191+
db.Query("Transaction").Insert(new
192+
{
193+
Date = "2022-01-01",
194+
Amount = 10
195+
});
196+
197+
var exists = db.Query("Transaction").Exists();
198+
Assert.Equal(true, exists);
199+
200+
db.Drop("Transaction");
201+
}
202+
167203
QueryFactory DB()
168204
{
169205
var host = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_HOST");

0 commit comments

Comments
 (0)