Skip to content

Commit b5f48ff

Browse files
committed
Add unit tests
1 parent da72028 commit b5f48ff

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<LangVersion>latest</LangVersion>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="coverlet.collector" Version="6.0.2" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
12+
<PackageReference Include="xunit" Version="2.9.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<ProjectReference Include="..\SQLiteSharp\SQLiteSharp.csproj" />
17+
</ItemGroup>
18+
<ItemGroup>
19+
<Using Include="Xunit" />
20+
</ItemGroup>
21+
</Project>

SQLiteSharp.Tests/UnitTest1.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace SQLiteSharp.Tests;
2+
3+
public class UnitTest1 {
4+
[Fact]
5+
public void Test1() {
6+
// Open a database connection
7+
using SQLiteConnection Connection = new("database.db");
8+
9+
// Create a table for a class
10+
Connection.CreateTable<ShopItem>();
11+
12+
// Delete all existing items in the table
13+
Connection.DeleteAll<ShopItem>();
14+
15+
// Insert items into the table
16+
Connection.Insert(new ShopItem() {
17+
ItemName = "Apple",
18+
Count = 10,
19+
});
20+
Connection.Insert(new ShopItem() {
21+
ItemName = "Banana",
22+
Count = 5,
23+
});
24+
25+
// Find one item in the table matching a predicate
26+
ShopItem? Apple = Connection.Find<ShopItem>(ShopItem => ShopItem.ItemName == "Apple");
27+
Assert.NotNull(Apple);
28+
29+
// Delete an item from the table
30+
Connection.Delete(Apple);
31+
32+
// Find several items in the table
33+
List<ShopItem> Bananas = Connection.Table<ShopItem>().Where(ShopItem => ShopItem.ItemName == "Banana").ToList();
34+
Assert.Single(Bananas);
35+
}
36+
}
37+
38+
public class ShopItem {
39+
[PrimaryKey, AutoIncrement]
40+
public long Id { get; set; }
41+
42+
[NotNull]
43+
public string? ItemName { get; set; }
44+
45+
public long Count { get; set; }
46+
47+
[Ignore]
48+
public int SomethingToIgnore { get; set; }
49+
}

SQLiteSharp.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.12.35521.163 d17.12
4+
VisualStudioVersion = 17.12.35521.163
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLiteSharp", "SQLiteSharp\SQLiteSharp.csproj", "{7BC2F0B1-3903-4D25-B65F-52D5C23D6B21}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLiteSharp.Tests", "SQLiteSharp.Tests\SQLiteSharp.Tests.csproj", "{61A33B8B-5810-4970-8C09-28E773ABE40F}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{7BC2F0B1-3903-4D25-B65F-52D5C23D6B21}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{7BC2F0B1-3903-4D25-B65F-52D5C23D6B21}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{7BC2F0B1-3903-4D25-B65F-52D5C23D6B21}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{61A33B8B-5810-4970-8C09-28E773ABE40F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{61A33B8B-5810-4970-8C09-28E773ABE40F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{61A33B8B-5810-4970-8C09-28E773ABE40F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{61A33B8B-5810-4970-8C09-28E773ABE40F}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)