From bf0ac46211a650f95bf8cd08274ab740d111e05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Konvi=C4=8Dka?= <konvicka.g630@gmail.com> Date: Tue, 23 Jan 2024 19:16:31 +0100 Subject: [PATCH] feat: Add test cases --- .../Cpp/CppClassDiagramVisitor.cs | 4 +- UnitTest/Input/main.cpp | 37 +++++++++++- UnitTest/WebApiTests.cs | 59 +++++++++++++++++-- 3 files changed, 93 insertions(+), 7 deletions(-) diff --git a/LanguageRecogniser/Cpp/CppClassDiagramVisitor.cs b/LanguageRecogniser/Cpp/CppClassDiagramVisitor.cs index ba6ae40..4142461 100644 --- a/LanguageRecogniser/Cpp/CppClassDiagramVisitor.cs +++ b/LanguageRecogniser/Cpp/CppClassDiagramVisitor.cs @@ -144,8 +144,8 @@ public class CppClassDiagramVisitor : CPP14ParserBaseVisitor<object> string compositionPattern = @"^(?:std::)?(?:vector<)?(\w+)>?$"; // Check if the property type matches aggregation or composition - Match aggregationMatch = Regex.Match(atribute.Type, aggregationPattern, RegexOptions.NonBacktracking); - Match compositionMatch = Regex.Match(atribute.Type, compositionPattern, RegexOptions.NonBacktracking); + Match aggregationMatch = Regex.Match(atribute.Type, aggregationPattern, RegexOptions.Compiled); + Match compositionMatch = Regex.Match(atribute.Type, compositionPattern, RegexOptions.Compiled); int groupMatch = 1; if (aggregationMatch.Success && !string.IsNullOrEmpty(aggregationMatch.Groups[groupMatch].Value)) { diff --git a/UnitTest/Input/main.cpp b/UnitTest/Input/main.cpp index 0bbf990..c85c1ad 100644 --- a/UnitTest/Input/main.cpp +++ b/UnitTest/Input/main.cpp @@ -11,13 +11,48 @@ namespace MyNamespace { std::cout << "Name: " << name << ", Age: " << age << std::endl; } }; + + class Student : public Person + { + private: + std::string login; + + void changeLogin(std::string newLogin) { + login = newLogin; + return; + } + }; + + class Teacher : public Person + { + public: + //vector of students + std::vector<Student> students; + + }; } int main() { - MyNamespace::Person person1; + MyNamespace::Student person1; person1.name = "John"; person1.age = 25; person1.displayInfo(); + if(person1.age > 18) { + std::cout << "Student is an adult" << std::endl; + int i = 0; + while(i < 10) { + std::cout << "i = " << i << std::endl; + i++; + } + } else { + std::cout << "Student is not an adult" << std::endl; + if(person1.age < 10) { + std::cout << "Student is a child" << std::endl; + } else { + std::cout << "Student is not a child" << std::endl; + } + } + return 0; } \ No newline at end of file diff --git a/UnitTest/WebApiTests.cs b/UnitTest/WebApiTests.cs index 2ec6ad8..8394d02 100644 --- a/UnitTest/WebApiTests.cs +++ b/UnitTest/WebApiTests.cs @@ -1,9 +1,7 @@ using System.Text; using Database; -using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; -using NUnit.Framework.Constraints; using WebAPI.Controllers; using WebAPI.DTO; using WebAPI.DTO.External; @@ -257,7 +255,7 @@ public class WebApiTests [TestCase(true)] [TestCase(false)] - public void UploadCodeAndTransform(bool getValidToken) + public void UploadCodeListTransformRemoveList(bool getValidToken) { string token = string.Empty; if (getValidToken) @@ -293,6 +291,9 @@ public class WebApiTests ListOne(true, 1, true); ConvertToActivityDiagram(true, 1, true); ConvertToClassDiagram(true, 1, true); + RemoveCode(true, 1, true); + ListAll(true, 0); + ListOne(true, 1, false); } else { @@ -445,7 +446,57 @@ public class WebApiTests } #endregion - + + #region Remove Code Tests + + [TestCase(true, -1, false)] + [TestCase(false, -1, false)] + public void RemoveCode(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 model = new RemoveCodeModel() + { + Id = id, + Token = token + }; + var result = apiController.RemoveCode(model); + if (getValidToken) + { + if (codeExists) + { + Assert.IsTrue(result is OkObjectResult); + var okResult = result as OkObjectResult; + Assert.IsTrue(okResult.Value is string); + Assert.IsTrue(okResult.Value as string == "Code removed"); + } + 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 private string GetToken(string authResult) { //parse guid from authResult -- GitLab