summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorLuca Matei Pintilie <luca@lucamatei.com>2024-10-30 20:59:53 +0000
committerLuca Matei Pintilie <luca@lucamatei.com>2024-10-30 20:59:53 +0000
commitdc1938dbb98dc9edf16558e505b2961246c83e6e (patch)
tree7953186976085ceca6c03a208d1ffd9596f745be /Tests
parentfc3c7e3b3c955cc274d4668768466fecb8fb727b (diff)
downloadwikiwaka-master.tar
wikiwaka-master.tar.gz
wikiwaka-master.tar.bz2
wikiwaka-master.tar.lz
wikiwaka-master.tar.xz
wikiwaka-master.tar.zst
wikiwaka-master.zip
Add API and TestHEADmaster
Diffstat (limited to '')
-rw-r--r--Tests/GlobalUsings.cs1
-rw-r--r--Tests/Tests.csproj23
-rw-r--r--Tests/UnitTest1.cs52
3 files changed, 76 insertions, 0 deletions
diff --git a/Tests/GlobalUsings.cs b/Tests/GlobalUsings.cs
new file mode 100644
index 0000000..ab67c7e
--- /dev/null
+++ b/Tests/GlobalUsings.cs
@@ -0,0 +1 @@
+global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
new file mode 100644
index 0000000..5c37b71
--- /dev/null
+++ b/Tests/Tests.csproj
@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+
+ <IsPackable>false</IsPackable>
+ <IsTestProject>true</IsTestProject>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
+ <PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
+ <PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
+ <PackageReference Include="coverlet.collector" Version="6.0.0" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Api\Api.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/Tests/UnitTest1.cs b/Tests/UnitTest1.cs
new file mode 100644
index 0000000..3e4dc64
--- /dev/null
+++ b/Tests/UnitTest1.cs
@@ -0,0 +1,52 @@
+using Microsoft.Data.Sqlite;
+using Microsoft.EntityFrameworkCore;
+using WikiWaka.Api.Controllers;
+using WikiWaka.Api.Models;
+
+namespace Tests;
+
+[TestClass]
+public class UnitTest1
+{
+ private ContentApiController controller;
+ private DbWikiWakaContext dbContext;
+
+ [TestInitialize]
+ public async Task TestInit()
+ {
+ SqliteConnection connection = new SqliteConnection("Filename=:memory:");
+ connection.Open();
+
+ var _contextOptions = new DbContextOptionsBuilder<DbWikiWakaContext>()
+ .UseSqlite(connection)
+ .Options;
+
+ dbContext = new(_contextOptions);
+ await dbContext.Database.EnsureCreatedAsync();
+ await DbInit.InitializeLanguages(dbContext);
+ controller = new(dbContext);
+ }
+
+ [TestCleanup]
+ public async Task TestClean()
+ {
+ await dbContext.Database.EnsureDeletedAsync();
+ await dbContext.DisposeAsync();
+ }
+
+ [TestMethod]
+ public async Task TestMethod1()
+ {
+ WikiWaka.Api.Contract.NewContent parameter = new()
+ {
+ Text = "Hello, world",
+ LanguageCode = "en-US",
+ };
+ Content newContent = await controller.PostContents(parameter);
+ IAsyncEnumerable<Content> contents = controller.GetContents();
+ Content newGetContent = contents.ToBlockingEnumerable().Single();
+
+ Assert.AreEqual(parameter.Text, newContent.Properties.Single().Text);
+ Assert.AreEqual(parameter.Text, newGetContent.Properties.Single().Text);
+ }
+}