-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
Copy pathSqliteConditionsTests.cs
91 lines (74 loc) · 2.75 KB
/
SqliteConditionsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) Microsoft. All rights reserved.
using System;
using Microsoft.SemanticKernel.Connectors.Sqlite;
using Xunit;
namespace SemanticKernel.Connectors.Sqlite.UnitTests;
/// <summary>
/// Unit tests for SQLite condition classes.
/// </summary>
public sealed class SqliteConditionsTests
{
[Fact]
public void SqliteWhereEqualsConditionWithoutParameterNamesThrowsException()
{
// Arrange
var condition = new SqliteWhereEqualsCondition("Name", "Value");
// Act & Assert
Assert.Throws<ArgumentException>(() => condition.BuildQuery([]));
}
[Theory]
[InlineData(null, "[Name] = @Name0")]
[InlineData("", "[Name] = @Name0")]
[InlineData("TableName", "[TableName].[Name] = @Name0")]
public void SqliteWhereEqualsConditionBuildsValidQuery(string? tableName, string expectedQuery)
{
// Arrange
var condition = new SqliteWhereEqualsCondition("Name", "Value") { TableName = tableName };
// Act
var query = condition.BuildQuery(["@Name0"]);
// Assert
Assert.Equal(expectedQuery, query);
}
[Fact]
public void SqliteWhereInConditionWithoutParameterNamesThrowsException()
{
// Arrange
var condition = new SqliteWhereInCondition("Name", ["Value1", "Value2"]);
// Act & Assert
Assert.Throws<ArgumentException>(() => condition.BuildQuery([]));
}
[Theory]
[InlineData(null, "[Name] IN (@Name0, @Name1)")]
[InlineData("", "[Name] IN (@Name0, @Name1)")]
[InlineData("TableName", "[TableName].[Name] IN (@Name0, @Name1)")]
public void SqliteWhereInConditionBuildsValidQuery(string? tableName, string expectedQuery)
{
// Arrange
var condition = new SqliteWhereInCondition("Name", ["Value1", "Value2"]) { TableName = tableName };
// Act
var query = condition.BuildQuery(["@Name0", "@Name1"]);
// Assert
Assert.Equal(expectedQuery, query);
}
[Fact]
public void SqliteWhereMatchConditionWithoutParameterNamesThrowsException()
{
// Arrange
var condition = new SqliteWhereMatchCondition("Name", "Value");
// Act & Assert
Assert.Throws<ArgumentException>(() => condition.BuildQuery([]));
}
[Theory]
[InlineData(null, "[Name] MATCH @Name0")]
[InlineData("", "[Name] MATCH @Name0")]
[InlineData("TableName", "[TableName].[Name] MATCH @Name0")]
public void SqliteWhereMatchConditionBuildsValidQuery(string? tableName, string expectedQuery)
{
// Arrange
var condition = new SqliteWhereMatchCondition("Name", "Value") { TableName = tableName };
// Act
var query = condition.BuildQuery(["@Name0"]);
// Assert
Assert.Equal(expectedQuery, query);
}
}