cleaned up tests

This commit is contained in:
QkoSad
2024-12-09 19:36:12 +02:00
parent 1054889c65
commit 98e689bfc5
5 changed files with 144 additions and 241 deletions
-26
View File
@@ -1,26 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/backendCs.Test.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
-41
View File
@@ -1,41 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/backendCs.Test.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/backendCs.Test.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/backendCs.Test.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
+70 -122
View File
@@ -9,202 +9,150 @@ public class UnitTest1
[TestMethod]
public async Task TestMethodReset()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync("http://localhost:5000/api/reset");
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync("http://localhost:5000/api/reset");
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodGetall1()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getall?offset=10"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getall?offset=10"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodGetall2()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getall?offset="
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getall?offset="
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 400);
}
Assert.AreEqual((int)response.StatusCode, 400);
}
[TestMethod]
public async Task TestMethodGetall3()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getall?offset=10&from=2020-01-01&to=2024-01-01&orderby=time&order=true"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getall?offset=10&from=2020-01-01&to=2024-01-01&orderby=time&order=true"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodGettopten1()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&to=2024-01-01&filterby=project"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&to=2024-01-01&filterby=project"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodGettopten2()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&to=2024-01-01&filterby=user"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&to=2024-01-01&filterby=user"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodGettopten3()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?to=2024-01-01&filterby=project"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?to=2024-01-01&filterby=project"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 400);
}
Assert.AreEqual((int)response.StatusCode, 400);
}
[TestMethod]
public async Task TestMethodGettopten4()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&filterby=project"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&filterby=project"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 400);
}
Assert.AreEqual((int)response.StatusCode, 400);
}
[TestMethod]
public async Task TestMethodGettopten5()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&to=2024-01-01"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/gettopten?from=2000-01-01&to=2024-01-01"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 400);
}
Assert.AreEqual((int)response.StatusCode, 400);
}
[TestMethod]
public async Task TestMethodGetuser1()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getuser?userid=1"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getuser?userid=1"
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodGetuser2()
{
using (HttpClient client = new HttpClient())
{
// Make a GET request to a URL
HttpResponseMessage response = await client.GetAsync(
"http://localhost:5000/api/getuser"
);
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync("http://localhost:5000/api/getuser");
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 400);
}
Assert.AreEqual((int)response.StatusCode, 400);
}
[TestMethod]
public async Task TestMethodRegister1()
{
using (HttpClient client = new())
{
// Make a GET request to a URL
var jsonData =
"{ \"f_name\": \"donna\", \"l_name\": \"cow\", \"mail\": \"tombo@mail.com\", \"password\": \"1234567890\" }";
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
using HttpClient client = new();
// Make a GET request to a URL
var jsonData =
"{ \"f_name\": \"donna\", \"l_name\": \"cow\", \"mail\": \"tombo@mail.com\", \"password\": \"1234567890\" }";
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(
"http://localhost:5000/api/register",
content
);
HttpResponseMessage response = await client.PostAsync(
"http://localhost:5000/api/register",
content
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
public async Task TestMethodLogin()
{
using (HttpClient client = new())
{
// Make a GET request to a URL
var jsonData = "{ \"mail\": \"tombo@mail.com\", \"password\": \"1234567890\" }";
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
using HttpClient client = new();
// Make a GET request to a URL
var jsonData = "{ \"mail\": \"tombo@mail.com\", \"password\": \"1234567890\" }";
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(
"http://localhost:5000/api/login",
content
);
HttpResponseMessage response = await client.PostAsync(
"http://localhost:5000/api/login",
content
);
// Ensure we have a successful response
Assert.AreEqual<Int32>((int)response.StatusCode, 200);
}
Assert.AreEqual((int)response.StatusCode, 200);
}
}
+4
View File
@@ -16,4 +16,8 @@
<PackageReference Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\backendCS\TimelogBackend.csproj" />
</ItemGroup>
</Project>
+70 -52
View File
@@ -5,17 +5,6 @@ namespace TimelogBackend;
class Program
{
static void HandleMissingPath(HttpListenerResponse response)
{
response.StatusCode = 404;
string errorMessage = "Not Found";
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
response.ContentType = "text/plain";
response.ContentLength64 = buffer.Length;
response.OutputStream.Write(buffer, 0, buffer.Length);
response.OutputStream.Write(buffer, 0, buffer.Length);
}
static void Main()
{
// create server
@@ -51,49 +40,10 @@ class Program
switch (request.HttpMethod)
{
case "GET":
switch (uri)
{
case "/api/reset":
Reset.HandleRequest(response);
break;
case "/api/getall":
Getall.HandleRequest(request, response);
break;
case "/api/gettopten":
Gettopten.HandleRequest(request, response);
break;
case "/api/getuser":
Getuser.HandleRequest(request, response);
break;
case "/api/createp":
CreateProcedure.HandleRequest(response);
break;
default:
HandleMissingPath(response);
break;
}
HandleGet(uri, request, response);
break;
case "POST":
if (request.HasEntityBody)
switch (uri)
{
case "/api/register":
Register.HandleRequest(request, response);
break;
case "/api/login":
Login.HandleRequest(request, response);
break;
case "/api/createlog":
CreateLog.HandleRequest(request, response);
break;
default:
HandleMissingPath(response);
break;
}
else
{
HandleMissingPath(response);
}
HandlePost(uri, request, response);
break;
default:
HandleMissingPath(response);
@@ -101,4 +51,72 @@ class Program
}
}
}
private static void HandlePost(
string uri,
HttpListenerRequest request,
HttpListenerResponse response
)
{
if (request.HasEntityBody)
switch (uri)
{
case "/api/register":
Register.HandleRequest(request, response);
break;
case "/api/login":
Login.HandleRequest(request, response);
break;
case "/api/createlog":
CreateLog.HandleRequest(request, response);
break;
default:
HandleMissingPath(response);
break;
}
else
{
HandleMissingPath(response);
}
}
private static void HandleGet(
string uri,
HttpListenerRequest request,
HttpListenerResponse response
)
{
switch (uri)
{
case "/api/reset":
Reset.HandleRequest(response);
break;
case "/api/getall":
Getall.HandleRequest(request, response);
break;
case "/api/gettopten":
Gettopten.HandleRequest(request, response);
break;
case "/api/getuser":
Getuser.HandleRequest(request, response);
break;
case "/api/createp":
CreateProcedure.HandleRequest(response);
break;
default:
HandleMissingPath(response);
break;
}
}
private static void HandleMissingPath(HttpListenerResponse response)
{
response.StatusCode = 404;
string errorMessage = "Not Found";
byte[] buffer = Encoding.UTF8.GetBytes(errorMessage);
response.ContentType = "text/plain";
response.ContentLength64 = buffer.Length;
response.OutputStream.Write(buffer, 0, buffer.Length);
response.OutputStream.Write(buffer, 0, buffer.Length);
}
}