Skip to content
Snippets Groups Projects
Commit 462dc51e authored by Jakub Konvička's avatar Jakub Konvička
Browse files

feat: Add diagram tests

parent 2a6f1cd0
1 merge request!15merge: develop into main
Pipeline #910 passed with stages
in 6 minutes and 15 seconds
#include <iostream>
#include <string>
namespace MyNamespace {
class Person {
public:
std::string name;
int age;
void displayInfo() {
std::cout << "Name: " << name << ", Age: " << age << std::endl;
}
};
}
int main() {
MyNamespace::Person person1;
person1.name = "John";
person1.age = 25;
person1.displayInfo();
return 0;
}
\ No newline at end of file
......@@ -23,4 +23,10 @@
<ProjectReference Include="..\WebAPI\WebAPI.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="Input\main.cpp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
using System.Text;
using Database;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
......@@ -256,7 +257,7 @@ public class WebApiTests
[TestCase(true)]
[TestCase(false)]
public void UploadCode(bool getValidToken)
public void UploadCodeAndTransform(bool getValidToken)
{
string token = string.Empty;
if (getValidToken)
......@@ -269,10 +270,12 @@ public class WebApiTests
}
var path = Path.Join(Directory.GetCurrentDirectory(), "users.json");
ApiController apiController = new ApiController(null, null, path);
var code = File.ReadAllText("Input/main.cpp");
var codeBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(code));
var model = new UploadCodeModel()
{
Token = token,
Code = "TestCode",
Code = codeBase64
};
var result = apiController.UploadCode(model);
if (getValidToken)
......@@ -288,6 +291,8 @@ public class WebApiTests
Assert.IsTrue(idInt == 1);
ListAll(true, 1);
ListOne(true, 1, true);
ConvertToActivityDiagram(true, 1, true);
ConvertToClassDiagram(true, 1, true);
}
else
{
......@@ -341,7 +346,103 @@ public class WebApiTests
Assert.IsTrue(okResult.Value as string == "Invalid token");
}
}
#endregion
#region Code Transformation Tests
[TestCase(true, -1, false)]
[TestCase(false, -1, false)]
public void ConvertToActivityDiagram(bool getValidToken, int id, bool codeExists)
{
string token = string.Empty;
if (getValidToken)
{
token = GetToken(TestUserAuthenticationProcedure());
}
else
{
token = "WrongToken";
}
var path = Path.Join(Directory.GetCurrentDirectory(), "users.json");
ApiController apiController = new ApiController(null, null, path);
var result = apiController.ConvertToActivityDiagram(token, id, string.Empty,"main");
if (getValidToken)
{
if (codeExists)
{
Assert.IsTrue(result is FileStreamResult);
var fileStreamResult = result as FileStreamResult;
Assert.IsTrue(fileStreamResult.ContentType == "application/xml");
Assert.IsTrue(!string.IsNullOrEmpty(fileStreamResult.FileDownloadName));
//check if filestream is not empty
var stream = fileStreamResult.FileStream;
Assert.IsTrue(stream.Length > 0);
}
else
{
Assert.IsTrue(result is NotFoundObjectResult);
var okResult = result as NotFoundObjectResult;
Assert.IsTrue(okResult.Value is string);
Assert.IsTrue(okResult.Value as string == "Code does not exist");
}
}
else
{
Assert.IsTrue(result is BadRequestObjectResult);
var okResult = result as BadRequestObjectResult;
Assert.IsTrue(okResult.Value is string);
Assert.IsTrue(okResult.Value as string == "Invalid token");
}
}
//ConvertToClassDiagram
[TestCase(true, -1, false)]
[TestCase(false, -1, false)]
public void ConvertToClassDiagram(bool getValidToken, int id, bool codeExists)
{
string token = string.Empty;
if (getValidToken)
{
token = GetToken(TestUserAuthenticationProcedure());
}
else
{
token = "WrongToken";
}
var path = Path.Join(Directory.GetCurrentDirectory(), "users.json");
ApiController apiController = new ApiController(null, null, path);
var result = apiController.ConvertToClassDiagram(token, id);
if (getValidToken)
{
if (codeExists)
{
Assert.IsTrue(result is FileStreamResult);
var fileStreamResult = result as FileStreamResult;
Assert.IsTrue(fileStreamResult.ContentType == "application/xml");
Assert.IsTrue(!string.IsNullOrEmpty(fileStreamResult.FileDownloadName));
//check if filestream is not empty
var stream = fileStreamResult.FileStream;
Assert.IsTrue(stream.Length > 0);
}
else
{
Assert.IsTrue(result is NotFoundObjectResult);
var okResult = result as NotFoundObjectResult;
Assert.IsTrue(okResult.Value is string);
Assert.IsTrue(okResult.Value as string == "Code does not exist");
}
}
else
{
Assert.IsTrue(result is BadRequestObjectResult);
var okResult = result as BadRequestObjectResult;
Assert.IsTrue(okResult.Value is string);
Assert.IsTrue(okResult.Value as string == "Invalid token");
}
}
#endregion
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment