From 6786e56df01c9f4c9f87f61b7abca8d083d9f7a1 Mon Sep 17 00:00:00 2001 From: Emilia Date: Wed, 29 May 2024 09:17:03 +0300 Subject: [PATCH 01/14] Adding Taskman.Tests --- .../.idea.TaskmanAPI/.idea/dataSources.xml | 12 + .../.idea/jsLibraryMappings.xml | 6 + .../.idea/config/applicationhost.config | 983 ++++++++++++++++++ TaskmanAPI/Properties/launchSettings.json | 1 + TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj | 23 + TaskmanAPI/Taskman.Tests/UnitTest1.cs | 10 + TaskmanAPI/TaskmanAPI.csproj | 48 +- TaskmanAPI/TaskmanAPI.sln | 6 + 8 files changed, 1068 insertions(+), 21 deletions(-) create mode 100644 TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/dataSources.xml create mode 100644 TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/jsLibraryMappings.xml create mode 100644 TaskmanAPI/.idea/config/applicationhost.config create mode 100644 TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj create mode 100644 TaskmanAPI/Taskman.Tests/UnitTest1.cs diff --git a/TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/dataSources.xml b/TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/dataSources.xml new file mode 100644 index 0000000..feb71e3 --- /dev/null +++ b/TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost:5432/taskman + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/jsLibraryMappings.xml b/TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/TaskmanAPI/.idea/.idea.TaskmanAPI/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TaskmanAPI/.idea/config/applicationhost.config b/TaskmanAPI/.idea/config/applicationhost.config new file mode 100644 index 0000000..d0cc40e --- /dev/null +++ b/TaskmanAPI/.idea/config/applicationhost.config @@ -0,0 +1,983 @@ + + + + + + +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TaskmanAPI/Properties/launchSettings.json b/TaskmanAPI/Properties/launchSettings.json index 9a43f6b..922fc76 100644 --- a/TaskmanAPI/Properties/launchSettings.json +++ b/TaskmanAPI/Properties/launchSettings.json @@ -33,6 +33,7 @@ "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", + "applicationUrl": "http://localhost:15915", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj b/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj new file mode 100644 index 0000000..085bddd --- /dev/null +++ b/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/TaskmanAPI/Taskman.Tests/UnitTest1.cs b/TaskmanAPI/Taskman.Tests/UnitTest1.cs new file mode 100644 index 0000000..f009937 --- /dev/null +++ b/TaskmanAPI/Taskman.Tests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace Taskman.Tests; +using Xunit; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + } +} \ No newline at end of file diff --git a/TaskmanAPI/TaskmanAPI.csproj b/TaskmanAPI/TaskmanAPI.csproj index f6b5bd2..48a5f37 100644 --- a/TaskmanAPI/TaskmanAPI.csproj +++ b/TaskmanAPI/TaskmanAPI.csproj @@ -9,37 +9,43 @@ - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Create.cshtml"/> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Delete.cshtml"/> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Details.cshtml"/> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Edit.cshtml"/> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Index.cshtml"/> - <_ContentIncludedByDefault Remove="Views\Shared\_ValidationScriptsPartial.cshtml"/> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Create.cshtml" /> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Delete.cshtml" /> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Details.cshtml" /> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Edit.cshtml" /> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Views\Shared\_ValidationScriptsPartial.cshtml" /> - - - - - - + + + + + + diff --git a/TaskmanAPI/TaskmanAPI.sln b/TaskmanAPI/TaskmanAPI.sln index bcd5441..101b8f9 100644 --- a/TaskmanAPI/TaskmanAPI.sln +++ b/TaskmanAPI/TaskmanAPI.sln @@ -7,6 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution docker-compose.yml = docker-compose.yml EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Taskman.Tests", "Taskman.Tests\Taskman.Tests.csproj", "{0BD927F0-678E-4F7A-9500-BD5A44779200}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,5 +19,9 @@ Global {8A5367CC-EE14-4B61-9660-5329C67B8DB1}.Debug|Any CPU.Build.0 = Debug|Any CPU {8A5367CC-EE14-4B61-9660-5329C67B8DB1}.Release|Any CPU.ActiveCfg = Release|Any CPU {8A5367CC-EE14-4B61-9660-5329C67B8DB1}.Release|Any CPU.Build.0 = Release|Any CPU + {0BD927F0-678E-4F7A-9500-BD5A44779200}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0BD927F0-678E-4F7A-9500-BD5A44779200}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0BD927F0-678E-4F7A-9500-BD5A44779200}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0BD927F0-678E-4F7A-9500-BD5A44779200}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal From b5fdc4c7ce33b6a3825540d256599061c6daecd0 Mon Sep 17 00:00:00 2001 From: Emilia Date: Sun, 16 Jun 2024 12:24:37 +0300 Subject: [PATCH 02/14] Automatic test for NotificationController --- TaskmanAPI/Contexts/DefaultContext.cs | 6 +- .../NotificationsControllerTests.cs | 163 ++++++++++++++++++ TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj | 11 +- TaskmanAPI/Taskman.Tests/UnitTest1.cs | 10 -- TaskmanAPI/TaskmanAPI.csproj | 4 +- 5 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs delete mode 100644 TaskmanAPI/Taskman.Tests/UnitTest1.cs diff --git a/TaskmanAPI/Contexts/DefaultContext.cs b/TaskmanAPI/Contexts/DefaultContext.cs index 2def835..44be02a 100644 --- a/TaskmanAPI/Contexts/DefaultContext.cs +++ b/TaskmanAPI/Contexts/DefaultContext.cs @@ -8,16 +8,14 @@ namespace TaskmanAPI.Contexts; // RENAME THIS IF USING MORE CONTEXTS public class DefaultContext : IdentityDbContext { - public DefaultContext(DbContextOptions options) : base(options) - { - } + public DefaultContext(DbContextOptions options) : base(options){} public DbSet Users { get; set; } public DbSet Projects { get; set; } public DbSet ProjTasks { get; set; } public DbSet RolePerProjects { get; set; } public DbSet UserTasks { get; set; } - public DbSet Notifications { get; set; } + public virtual DbSet Notifications { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs b/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs new file mode 100644 index 0000000..f9c1e0f --- /dev/null +++ b/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs @@ -0,0 +1,163 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using TaskmanAPI.Contexts; +using TaskmanAPI.Controllers; +using TaskmanAPI.Model; + + +public class NotificationsControllerTests +{ + private DefaultContext _context; + private NotificationsController _controller; + + public NotificationsControllerTests() + { + Setup(); + } + + private void Setup() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: $"TestDatabase_{Guid.NewGuid()}") + .Options; + _context = new DefaultContext(options); + + // Seed the in-memory database + SeedDatabase(); + + // Create controller + _controller = new NotificationsController(_context); + } + + private void SeedDatabase() + { + var notifications = new List + { + new Notification { Id = 1,UserId = "1",Title = "Titlu1", Content = "Test1" }, + new Notification { Id = 2, UserId = "2", Title = "Titlu2", Content = "Test2" } + }; + + _context.Notifications.AddRange(notifications); + _context.SaveChanges(); + } + + //Test for GetNotifications method + [Fact] + public async Task GetNotifications_ReturnsAllNotifications() + { + // Act + var result = await _controller.GetNotifications(); + + // Assert + var okResult = Assert.IsType>>(result); + var returnValue = Assert.IsType>(okResult.Value); + Assert.Equal(2, returnValue.Count); + } + + //Tests for GetNotification method + [Fact] + public async Task GetNotification_ReturnsNotification_WhenNotificationExists() + { + // Act + var result = await _controller.GetNotification(1); + + // Assert + var okResult = Assert.IsType>(result); + Assert.Equal(1, okResult.Value.Id); + } + + [Fact] + public async Task GetNotification_ReturnsNotFound_WhenNotificationDoesNotExist() + { + // Act + var result = await _controller.GetNotification(99); + + // Assert + Assert.IsType(result.Result); + } + + //Tester for PutNotification method + [Fact] + public async Task PutNotification_ReturnsNoContent_WhenUpdateIsSuccessful() + { + // Arrange + var existingNotification = await _context.Notifications.FindAsync(1); + existingNotification.Content = "Updated"; + + // Act + var result = await _controller.PutNotification(1, existingNotification); + + // Assert + Assert.IsType(result); + + // Verify the update + var updatedNotification = await _context.Notifications.FindAsync(1); + Assert.Equal("Updated", updatedNotification.Content); + } + + [Fact] + public async Task PutNotification_ReturnsBadRequest_WhenIdMismatch() + { + // Arrange + var notification = new Notification { Id = 1, Content = "Updated" }; + + // Act + var result = await _controller.PutNotification(2, notification); + + // Assert + Assert.IsType(result); + } + + [Fact] + public async Task PutNotification_ReturnsNotFound_WhenNotificationDoesNotExist() + { + // Arrange + var notification = new Notification { Id = 10,UserId = "99",Title = "Titlu99", Content = "Updated" }; + + // Act + var result = await _controller.PutNotification(10, notification); + + // Assert + Assert.IsType(result); + } + + + //Test for PostNotification method + [Fact] + public async Task PostNotification_ReturnsCreatedAtAction_WhenPostIsSuccessful() + { + // Arrange + var notification = new Notification { Id = 3,UserId = "3",Title = "Title3", Content = "New" }; + + // Act + var result = await _controller.PostNotification(notification); + + // Assert + var actionResult = Assert.IsType>(result); + var createdAtActionResult = Assert.IsType(actionResult.Result); + Assert.Equal("GetNotification", createdAtActionResult.ActionName); + Assert.Equal(notification.Id, ((Notification)createdAtActionResult.Value).Id); + } + + //Test for DeleteNotification + [Fact] + public async Task DeleteNotification_ReturnsNoContent_WhenDeleteIsSuccessful() + { + // Act + var result = await _controller.DeleteNotification(1); + + // Assert + Assert.IsType(result); + } + + [Fact] + public async Task DeleteNotification_ReturnsNotFound_WhenNotificationDoesNotExist() + { + // Act + var result = await _controller.DeleteNotification(99); + + // Assert + Assert.IsType(result); + } + +} diff --git a/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj b/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj index 085bddd..f86a911 100644 --- a/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj +++ b/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj @@ -11,13 +11,18 @@ - - - + + + + + + + + diff --git a/TaskmanAPI/Taskman.Tests/UnitTest1.cs b/TaskmanAPI/Taskman.Tests/UnitTest1.cs deleted file mode 100644 index f009937..0000000 --- a/TaskmanAPI/Taskman.Tests/UnitTest1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Taskman.Tests; -using Xunit; - -public class UnitTest1 -{ - [Fact] - public void Test1() - { - } -} \ No newline at end of file diff --git a/TaskmanAPI/TaskmanAPI.csproj b/TaskmanAPI/TaskmanAPI.csproj index 48a5f37..58c5816 100644 --- a/TaskmanAPI/TaskmanAPI.csproj +++ b/TaskmanAPI/TaskmanAPI.csproj @@ -12,7 +12,8 @@ - + + @@ -21,6 +22,7 @@ + From c8743edf03c5b311d7dc3f915400118f02ebe2cc Mon Sep 17 00:00:00 2001 From: Emilia Date: Sun, 16 Jun 2024 13:22:24 +0300 Subject: [PATCH 03/14] Adding tester for PrivilegeChecker (maybe temporaly) --- TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs | 18 +++ .../Taskman.Tests/PrivilegeCheckerTest.cs | 137 ++++++++++++++++++ TaskmanAPI/TaskmanAPI.sln.DotSettings.user | 13 ++ 3 files changed, 168 insertions(+) create mode 100644 TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs create mode 100644 TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs create mode 100644 TaskmanAPI/TaskmanAPI.sln.DotSettings.user diff --git a/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs b/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs new file mode 100644 index 0000000..0d14825 --- /dev/null +++ b/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using Moq; +using System.Collections.Generic; +using System.Linq; + +public static class DbSetMockHelper +{ + public static DbSet CreateMockDbSet(List elements) where T : class + { + var queryable = elements.AsQueryable(); + var mockSet = new Mock>(); + mockSet.As>().Setup(m => m.Provider).Returns(queryable.Provider); + mockSet.As>().Setup(m => m.Expression).Returns(queryable.Expression); + mockSet.As>().Setup(m => m.ElementType).Returns(queryable.ElementType); + mockSet.As>().Setup(m => m.GetEnumerator()).Returns(queryable.GetEnumerator()); + return mockSet.Object; + } +} \ No newline at end of file diff --git a/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs b/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs new file mode 100644 index 0000000..5efcd83 --- /dev/null +++ b/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs @@ -0,0 +1,137 @@ +// MyProject.Tests/PrivilegeCheckerTests.cs +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using Microsoft.EntityFrameworkCore; +using Moq; +using TaskmanAPI.Contexts; +using TaskmanAPI.Enums; +using TaskmanAPI.Models; +using TaskmanAPI.Services; +using Xunit; + +namespace MyProject.Tests +{ + public class PrivilegeCheckerTests : IDisposable + { + private readonly DefaultContext _context; + private readonly ClaimsPrincipal _mockUser; + private readonly PrivilegeChecker _privilegeChecker; + + public PrivilegeCheckerTests() + { + // Configurăm opțiunile pentru DbContextOptions + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) + .Options; + + // Inițializăm contextul cu opțiunile definite + _context = new DefaultContext(options); + + // Populăm contextul cu datele de test + SeedDatabase(); + + // Configurăm un mock pentru utilizator + var claims = new List + { + new Claim(ClaimTypes.NameIdentifier, "user1") + }; + var identity = new ClaimsIdentity(claims, "TestAuthType"); + _mockUser = new ClaimsPrincipal(identity); + + // Inițializăm PrivilegeChecker cu contextul și utilizatorul simulat + _privilegeChecker = new PrivilegeChecker(_context, _mockUser); + } + + // Metodă pentru popularea bazei de date cu date de test + private void SeedDatabase() + { + var rolePerProjects = new List + { + new RolePerProject { ProjectId = 1, UserId = "user1", RoleName = "User" } + }; + _context.RolePerProjects.AddRange(rolePerProjects); + _context.SaveChanges(); + } + + [Fact] + public void HasAccessToProject_ReturnsTrue_WhenUserHasAccess() + { + // Act + var result = _privilegeChecker.HasAccessToProject(1); + + // Assert + Assert.True(result); + } + + [Fact] + public void HasAccessToProject_ReturnsFalse_WhenUserDoesNotHaveAccess() + { + // Arrange + var rolePerProjects = new List(); + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasAccessToProject(1); + + // Assert + Assert.False(result); + } + + [Fact] + public void HasPrivilege_ReturnsTrue_WhenUserHasSufficientRole() + { + // Arrange + var rolePerProjects = new List + { + new RolePerProject { ProjectId = 1, UserId = "user1", RoleName = "Admin" } + }; + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasPrivilege(1, Role.Admin); + + // Assert + Assert.True(result); + } + + [Fact] + public void HasPrivilege_ReturnsFalse_WhenUserHasInsufficientRole() + { + // Arrange + var rolePerProjects = new List + { + new RolePerProject { ProjectId = 1, UserId = "user1", RoleName = "User" } + }; + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasPrivilege(1, Role.Admin); + + // Assert + Assert.False(result); + } + + [Fact] + public void HasPrivilege_ReturnsFalse_WhenUserHasNoRole() + { + // Arrange + var rolePerProjects = new List(); + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasPrivilege(1, Role.User); + + // Assert + Assert.False(result); + } + public void Dispose() + { + _context.Dispose(); + } + } +} diff --git a/TaskmanAPI/TaskmanAPI.sln.DotSettings.user b/TaskmanAPI/TaskmanAPI.sln.DotSettings.user new file mode 100644 index 0000000..11f74c5 --- /dev/null +++ b/TaskmanAPI/TaskmanAPI.sln.DotSettings.user @@ -0,0 +1,13 @@ + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> + <SessionState ContinuousTestingMode="0" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> + <SessionState ContinuousTestingMode="0" Name="All tests from Solution #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> + <SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Solution /> +</SessionState> \ No newline at end of file From e367656dad538e31724697e8fa049d14246d898b Mon Sep 17 00:00:00 2001 From: Emilia Date: Sun, 16 Jun 2024 19:05:29 +0300 Subject: [PATCH 04/14] repair errors --- .github/workflows/angular.yml | 18 +- .github/workflows/dotnet.yml | 22 +- TaskmanAPI/Contexts/DefaultContext.cs | 4 +- TaskmanAPI/Controllers/ProjTasksController.cs | 1 + TaskmanAPI/Controllers/ProjectsController.cs | 3 +- TaskmanAPI/Services/ProjTasksService.cs | 4 +- TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs | 2 - .../NotificationsControllerTests.cs | 20 +- .../Taskman.Tests/PrivilegeCheckerTest.cs | 235 +++++++++--------- TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj | 7 +- TaskmanAPI/TaskmanAPI.csproj | 57 +++-- TaskmanAPI/TaskmanAPI.csproj.user | 32 +-- TaskmanAPI/TaskmanAPI.sln.DotSettings.user | 20 +- TaskmanClient/.vscode/extensions.json | 4 +- TaskmanClient/src/app/app.component.spec.ts | 4 +- TaskmanClient/src/app/app.component.ts | 4 +- TaskmanClient/src/app/app.config.ts | 8 +- TaskmanClient/src/app/app.module.ts | 15 +- TaskmanClient/src/app/app.routes.ts | 12 +- .../src/app/footer/footer.component.html | 27 +- .../src/app/footer/footer.component.spec.ts | 4 +- .../src/app/footer/footer.component.ts | 5 +- .../src/app/header/header.component.html | 96 ++++--- .../src/app/header/header.component.spec.ts | 4 +- .../src/app/header/header.component.ts | 5 +- .../src/app/login/login.component.html | 34 ++- .../src/app/login/login.component.spec.ts | 4 +- .../src/app/login/login.component.ts | 12 +- .../app/navigation/navigation.component.html | 37 +-- .../navigation/navigation.component.spec.ts | 4 +- .../app/navigation/navigation.component.ts | 5 +- .../src/app/projects/projects.component.html | 84 ++++--- .../app/projects/projects.component.spec.ts | 4 +- .../src/app/projects/projects.component.ts | 77 +++--- .../src/app/register/register.component.html | 39 ++- .../app/register/register.component.spec.ts | 4 +- .../src/app/register/register.component.ts | 10 +- TaskmanClient/src/app/service/auth-service.ts | 7 +- .../app/service/login-service.service.spec.ts | 4 +- .../src/app/service/login-service.service.ts | 8 +- .../app/service/project-service.service.ts | 22 +- .../app/start/start-page.component.spec.ts | 4 +- .../src/app/start/start-page.component.ts | 8 +- TaskmanClient/src/index.html | 6 +- TaskmanClient/src/main.ts | 6 +- 45 files changed, 544 insertions(+), 448 deletions(-) diff --git a/.github/workflows/angular.yml b/.github/workflows/angular.yml index 0422287..b619f56 100644 --- a/.github/workflows/angular.yml +++ b/.github/workflows/angular.yml @@ -14,13 +14,13 @@ jobs: working-directory: TaskmanClient steps: - - uses: actions/checkout@v4 - - name: Setup - uses: actions/setup-node@v4 - with: - node-version: 20.12.2 - - name: Restore dependencies - run: npm install - - name: Build - run: npm run build --prod + - uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-node@v4 + with: + node-version: 20.12.2 + - name: Restore dependencies + run: npm install + - name: Build + run: npm run build --prod # TODO: tests? diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 817d416..1f725ef 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -17,14 +17,14 @@ jobs: working-directory: TaskmanAPI steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal diff --git a/TaskmanAPI/Contexts/DefaultContext.cs b/TaskmanAPI/Contexts/DefaultContext.cs index 44be02a..7b4962d 100644 --- a/TaskmanAPI/Contexts/DefaultContext.cs +++ b/TaskmanAPI/Contexts/DefaultContext.cs @@ -8,7 +8,9 @@ namespace TaskmanAPI.Contexts; // RENAME THIS IF USING MORE CONTEXTS public class DefaultContext : IdentityDbContext { - public DefaultContext(DbContextOptions options) : base(options){} + public DefaultContext(DbContextOptions options) : base(options) + { + } public DbSet Users { get; set; } public DbSet Projects { get; set; } diff --git a/TaskmanAPI/Controllers/ProjTasksController.cs b/TaskmanAPI/Controllers/ProjTasksController.cs index 47e85ef..1dadedc 100644 --- a/TaskmanAPI/Controllers/ProjTasksController.cs +++ b/TaskmanAPI/Controllers/ProjTasksController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using TaskmanAPI.Contexts; using TaskmanAPI.Model; diff --git a/TaskmanAPI/Controllers/ProjectsController.cs b/TaskmanAPI/Controllers/ProjectsController.cs index c829b11..d055b2a 100644 --- a/TaskmanAPI/Controllers/ProjectsController.cs +++ b/TaskmanAPI/Controllers/ProjectsController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using TaskmanAPI.Contexts; using TaskmanAPI.Models; @@ -106,7 +107,7 @@ public async Task>> GetProjectUsers(int id) { return Ok(await _projectsService.GetProjectUsers(id)); } - + // get current user's role in project: api/projects/{id}/my_role [HttpGet("{id}/my_role")] public async Task> GetMyRole(int id) diff --git a/TaskmanAPI/Services/ProjTasksService.cs b/TaskmanAPI/Services/ProjTasksService.cs index 1260753..aab71f6 100644 --- a/TaskmanAPI/Services/ProjTasksService.cs +++ b/TaskmanAPI/Services/ProjTasksService.cs @@ -46,7 +46,7 @@ public async Task> GetAllTasks(int projectId) // return only tasks where parent id is null to avoid returning subtasks return await _context.ProjTasks.Where(t => t.ProjectId == projectId && t.ParentId == default).ToListAsync(); } - + public async Task GetTask(int id) { var task = await _context.ProjTasks.FindAsync(id); @@ -127,7 +127,7 @@ public async Task AddUser(int id, string userId) var user = await _context.Users.FindAsync(userId); if (user == null) throw new EntityNotFoundException("User does not exist"); - + // check if user is part of the project if (!_context.RolePerProjects.Any(rp => rp.ProjectId == task.ProjectId && rp.UserId == userId)) throw new EntityNotFoundException("User does not have access to project"); diff --git a/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs b/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs index 0d14825..8d8f40d 100644 --- a/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs +++ b/TaskmanAPI/Taskman.Tests/DbSetMockHelper.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; using Moq; -using System.Collections.Generic; -using System.Linq; public static class DbSetMockHelper { diff --git a/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs b/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs index f9c1e0f..6cb32d1 100644 --- a/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs +++ b/TaskmanAPI/Taskman.Tests/NotificationsControllerTests.cs @@ -4,8 +4,7 @@ using TaskmanAPI.Controllers; using TaskmanAPI.Model; - -public class NotificationsControllerTests +public class NotificationsControllerTests { private DefaultContext _context; private NotificationsController _controller; @@ -18,7 +17,7 @@ public NotificationsControllerTests() private void Setup() { var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName: $"TestDatabase_{Guid.NewGuid()}") + .UseInMemoryDatabase($"TestDatabase_{Guid.NewGuid()}") .Options; _context = new DefaultContext(options); @@ -33,8 +32,8 @@ private void SeedDatabase() { var notifications = new List { - new Notification { Id = 1,UserId = "1",Title = "Titlu1", Content = "Test1" }, - new Notification { Id = 2, UserId = "2", Title = "Titlu2", Content = "Test2" } + new() { Id = 1, UserId = "1", Title = "Titlu1", Content = "Test1" }, + new() { Id = 2, UserId = "2", Title = "Titlu2", Content = "Test2" } }; _context.Notifications.AddRange(notifications); @@ -112,7 +111,7 @@ public async Task PutNotification_ReturnsBadRequest_WhenIdMismatch() public async Task PutNotification_ReturnsNotFound_WhenNotificationDoesNotExist() { // Arrange - var notification = new Notification { Id = 10,UserId = "99",Title = "Titlu99", Content = "Updated" }; + var notification = new Notification { Id = 10, UserId = "99", Title = "Titlu99", Content = "Updated" }; // Act var result = await _controller.PutNotification(10, notification); @@ -121,13 +120,13 @@ public async Task PutNotification_ReturnsNotFound_WhenNotificationDoesNotExist() Assert.IsType(result); } - + //Test for PostNotification method [Fact] public async Task PostNotification_ReturnsCreatedAtAction_WhenPostIsSuccessful() { // Arrange - var notification = new Notification { Id = 3,UserId = "3",Title = "Title3", Content = "New" }; + var notification = new Notification { Id = 3, UserId = "3", Title = "Title3", Content = "New" }; // Act var result = await _controller.PostNotification(notification); @@ -147,7 +146,7 @@ public async Task DeleteNotification_ReturnsNoContent_WhenDeleteIsSuccessful() var result = await _controller.DeleteNotification(1); // Assert - Assert.IsType(result); + Assert.IsType(result); } [Fact] @@ -159,5 +158,4 @@ public async Task DeleteNotification_ReturnsNotFound_WhenNotificationDoesNotExis // Assert Assert.IsType(result); } - -} +} \ No newline at end of file diff --git a/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs b/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs index 5efcd83..5082222 100644 --- a/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs +++ b/TaskmanAPI/Taskman.Tests/PrivilegeCheckerTest.cs @@ -1,137 +1,134 @@ // MyProject.Tests/PrivilegeCheckerTests.cs -using System.Collections.Generic; -using System.Linq; + using System.Security.Claims; using Microsoft.EntityFrameworkCore; -using Moq; using TaskmanAPI.Contexts; using TaskmanAPI.Enums; -using TaskmanAPI.Models; +using TaskmanAPI.Models; using TaskmanAPI.Services; -using Xunit; -namespace MyProject.Tests +namespace MyProject.Tests; + +public class PrivilegeCheckerTests : IDisposable { - public class PrivilegeCheckerTests : IDisposable + private readonly DefaultContext _context; + private readonly ClaimsPrincipal _mockUser; + private readonly PrivilegeChecker _privilegeChecker; + + public PrivilegeCheckerTests() { - private readonly DefaultContext _context; - private readonly ClaimsPrincipal _mockUser; - private readonly PrivilegeChecker _privilegeChecker; + // Configurăm opțiunile pentru DbContextOptions + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; - public PrivilegeCheckerTests() - { - // Configurăm opțiunile pentru DbContextOptions - var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) - .Options; - - // Inițializăm contextul cu opțiunile definite - _context = new DefaultContext(options); - - // Populăm contextul cu datele de test - SeedDatabase(); - - // Configurăm un mock pentru utilizator - var claims = new List - { - new Claim(ClaimTypes.NameIdentifier, "user1") - }; - var identity = new ClaimsIdentity(claims, "TestAuthType"); - _mockUser = new ClaimsPrincipal(identity); - - // Inițializăm PrivilegeChecker cu contextul și utilizatorul simulat - _privilegeChecker = new PrivilegeChecker(_context, _mockUser); - } - - // Metodă pentru popularea bazei de date cu date de test - private void SeedDatabase() - { - var rolePerProjects = new List - { - new RolePerProject { ProjectId = 1, UserId = "user1", RoleName = "User" } - }; - _context.RolePerProjects.AddRange(rolePerProjects); - _context.SaveChanges(); - } - - [Fact] - public void HasAccessToProject_ReturnsTrue_WhenUserHasAccess() - { - // Act - var result = _privilegeChecker.HasAccessToProject(1); - - // Assert - Assert.True(result); - } - - [Fact] - public void HasAccessToProject_ReturnsFalse_WhenUserDoesNotHaveAccess() + // Inițializăm contextul cu opțiunile definite + _context = new DefaultContext(options); + + // Populăm contextul cu datele de test + SeedDatabase(); + + // Configurăm un mock pentru utilizator + var claims = new List { - // Arrange - var rolePerProjects = new List(); - var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); - _context.RolePerProjects = mockDbSet; + new(ClaimTypes.NameIdentifier, "user1") + }; + var identity = new ClaimsIdentity(claims, "TestAuthType"); + _mockUser = new ClaimsPrincipal(identity); - // Act - var result = _privilegeChecker.HasAccessToProject(1); + // Inițializăm PrivilegeChecker cu contextul și utilizatorul simulat + _privilegeChecker = new PrivilegeChecker(_context, _mockUser); + } - // Assert - Assert.False(result); - } + public void Dispose() + { + _context.Dispose(); + } - [Fact] - public void HasPrivilege_ReturnsTrue_WhenUserHasSufficientRole() - { - // Arrange - var rolePerProjects = new List - { - new RolePerProject { ProjectId = 1, UserId = "user1", RoleName = "Admin" } - }; - var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); - _context.RolePerProjects = mockDbSet; - - // Act - var result = _privilegeChecker.HasPrivilege(1, Role.Admin); - - // Assert - Assert.True(result); - } - - [Fact] - public void HasPrivilege_ReturnsFalse_WhenUserHasInsufficientRole() + // Metodă pentru popularea bazei de date cu date de test + private void SeedDatabase() + { + var rolePerProjects = new List { - // Arrange - var rolePerProjects = new List - { - new RolePerProject { ProjectId = 1, UserId = "user1", RoleName = "User" } - }; - var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); - _context.RolePerProjects = mockDbSet; - - // Act - var result = _privilegeChecker.HasPrivilege(1, Role.Admin); - - // Assert - Assert.False(result); - } - - [Fact] - public void HasPrivilege_ReturnsFalse_WhenUserHasNoRole() + new() { ProjectId = 1, UserId = "user1", RoleName = "User" } + }; + _context.RolePerProjects.AddRange(rolePerProjects); + _context.SaveChanges(); + } + + [Fact] + public void HasAccessToProject_ReturnsTrue_WhenUserHasAccess() + { + // Act + var result = _privilegeChecker.HasAccessToProject(1); + + // Assert + Assert.True(result); + } + + [Fact] + public void HasAccessToProject_ReturnsFalse_WhenUserDoesNotHaveAccess() + { + // Arrange + var rolePerProjects = new List(); + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasAccessToProject(1); + + // Assert + Assert.False(result); + } + + [Fact] + public void HasPrivilege_ReturnsTrue_WhenUserHasSufficientRole() + { + // Arrange + var rolePerProjects = new List { - // Arrange - var rolePerProjects = new List(); - var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); - _context.RolePerProjects = mockDbSet; - - // Act - var result = _privilegeChecker.HasPrivilege(1, Role.User); - - // Assert - Assert.False(result); - } - public void Dispose() + new() { ProjectId = 1, UserId = "user1", RoleName = "Admin" } + }; + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasPrivilege(1, Role.Admin); + + // Assert + Assert.True(result); + } + + [Fact] + public void HasPrivilege_ReturnsFalse_WhenUserHasInsufficientRole() + { + // Arrange + var rolePerProjects = new List { - _context.Dispose(); - } + new() { ProjectId = 1, UserId = "user1", RoleName = "User" } + }; + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasPrivilege(1, Role.Admin); + + // Assert + Assert.False(result); + } + + [Fact] + public void HasPrivilege_ReturnsFalse_WhenUserHasNoRole() + { + // Arrange + var rolePerProjects = new List(); + var mockDbSet = DbSetMockHelper.CreateMockDbSet(rolePerProjects); + _context.RolePerProjects = mockDbSet; + + // Act + var result = _privilegeChecker.HasPrivilege(1, Role.User); + + // Assert + Assert.False(result); } -} +} \ No newline at end of file diff --git a/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj b/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj index f86a911..5aaa724 100644 --- a/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj +++ b/TaskmanAPI/Taskman.Tests/Taskman.Tests.csproj @@ -1,6 +1,9 @@ + $(SolutionDir)\bin\$(MSBuildProjectName)\ + $(SolutionDir)\obj\$(MSBuildProjectName)\ + net8.0 enable enable @@ -12,7 +15,7 @@ - + @@ -22,7 +25,7 @@ - + diff --git a/TaskmanAPI/TaskmanAPI.csproj b/TaskmanAPI/TaskmanAPI.csproj index 58c5816..74888a9 100644 --- a/TaskmanAPI/TaskmanAPI.csproj +++ b/TaskmanAPI/TaskmanAPI.csproj @@ -1,6 +1,9 @@  + $(SolutionDir)\bin\$(MSBuildProjectName)\ + $(SolutionDir)\obj\$(MSBuildProjectName)\ + net8.0 enable enable @@ -9,45 +12,45 @@ - - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + + + - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Create.cshtml" /> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Delete.cshtml" /> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Details.cshtml" /> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Edit.cshtml" /> - <_ContentIncludedByDefault Remove="Views\ProjTasks1\Index.cshtml" /> - <_ContentIncludedByDefault Remove="Views\Shared\_ValidationScriptsPartial.cshtml" /> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Create.cshtml"/> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Delete.cshtml"/> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Details.cshtml"/> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Edit.cshtml"/> + <_ContentIncludedByDefault Remove="Views\ProjTasks1\Index.cshtml"/> + <_ContentIncludedByDefault Remove="Views\Shared\_ValidationScriptsPartial.cshtml"/> - - - - - - + + + + + + diff --git a/TaskmanAPI/TaskmanAPI.csproj.user b/TaskmanAPI/TaskmanAPI.csproj.user index b58d16b..adbb311 100644 --- a/TaskmanAPI/TaskmanAPI.csproj.user +++ b/TaskmanAPI/TaskmanAPI.csproj.user @@ -1,19 +1,19 @@  - - <_SelectedScaffolderID>MvcControllerWithContextScaffolder - <_SelectedScaffolderCategoryPath>root/Common - 650 - True - False - True - - TaskmanAPI.Contexts.DefaultContext - False - True - http - - - ProjectDebugger - + + <_SelectedScaffolderID>MvcControllerWithContextScaffolder + <_SelectedScaffolderCategoryPath>root/Common + 650 + True + False + True + + TaskmanAPI.Contexts.DefaultContext + False + True + http + + + ProjectDebugger + \ No newline at end of file diff --git a/TaskmanAPI/TaskmanAPI.sln.DotSettings.user b/TaskmanAPI/TaskmanAPI.sln.DotSettings.user index 11f74c5..6f5fb4e 100644 --- a/TaskmanAPI/TaskmanAPI.sln.DotSettings.user +++ b/TaskmanAPI/TaskmanAPI.sln.DotSettings.user @@ -1,13 +1,11 @@ - - <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution #4" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Solution /> -</SessionState> - <SessionState ContinuousTestingMode="0" Name="All tests from Solution #2" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Solution /> -</SessionState> - <SessionState ContinuousTestingMode="0" Name="All tests from Solution #3" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <Solution /> -</SessionState> - <SessionState ContinuousTestingMode="0" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + + + + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> <Solution /> </SessionState> \ No newline at end of file diff --git a/TaskmanClient/.vscode/extensions.json b/TaskmanClient/.vscode/extensions.json index 77b3745..0409dbe 100644 --- a/TaskmanClient/.vscode/extensions.json +++ b/TaskmanClient/.vscode/extensions.json @@ -1,4 +1,6 @@ { // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 - "recommendations": ["angular.ng-template"] + "recommendations": [ + "angular.ng-template" + ] } diff --git a/TaskmanClient/src/app/app.component.spec.ts b/TaskmanClient/src/app/app.component.spec.ts index a59bb8b..b5c94d5 100644 --- a/TaskmanClient/src/app/app.component.spec.ts +++ b/TaskmanClient/src/app/app.component.spec.ts @@ -1,5 +1,5 @@ -import { TestBed } from '@angular/core/testing'; -import { AppComponent } from './app.component'; +import {TestBed} from '@angular/core/testing'; +import {AppComponent} from './app.component'; describe('AppComponent', () => { beforeEach(async () => { diff --git a/TaskmanClient/src/app/app.component.ts b/TaskmanClient/src/app/app.component.ts index d63430d..2c35083 100644 --- a/TaskmanClient/src/app/app.component.ts +++ b/TaskmanClient/src/app/app.component.ts @@ -1,5 +1,5 @@ -import { Component } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; +import {Component} from '@angular/core'; +import {RouterOutlet} from '@angular/router'; import {LoginComponent} from "./login/login.component"; import {HeaderComponent} from "./header/header.component"; diff --git a/TaskmanClient/src/app/app.config.ts b/TaskmanClient/src/app/app.config.ts index 41c01f7..98bc8e8 100644 --- a/TaskmanClient/src/app/app.config.ts +++ b/TaskmanClient/src/app/app.config.ts @@ -1,9 +1,9 @@ -import { ApplicationConfig } from '@angular/core'; -import { provideRouter } from '@angular/router'; +import {ApplicationConfig} from '@angular/core'; +import {provideRouter} from '@angular/router'; -import { routes } from './app.routes'; +import {routes} from './app.routes'; import {provideHttpClient} from "@angular/common/http"; export const appConfig: ApplicationConfig = { - providers: [provideRouter(routes),provideHttpClient()] + providers: [provideRouter(routes), provideHttpClient()] }; diff --git a/TaskmanClient/src/app/app.module.ts b/TaskmanClient/src/app/app.module.ts index 8cd03c3..d5a5091 100644 --- a/TaskmanClient/src/app/app.module.ts +++ b/TaskmanClient/src/app/app.module.ts @@ -1,21 +1,17 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; import {AppComponent} from "./app.component"; import {BrowserModule} from "@angular/platform-browser"; -import {Router, RouterModule} from "@angular/router"; +import {RouterModule} from "@angular/router"; import {FormsModule} from "@angular/forms"; import {LoginComponent} from "./login/login.component"; import {HeaderComponent} from "./header/header.component"; import {HttpClientModule} from "@angular/common/http"; -import {LoginServiceService} from "./service/login-service.service"; import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; - @NgModule({ - declarations: [ - - ], + declarations: [], exports: [ HeaderComponent, @@ -34,4 +30,5 @@ import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; ] }) -export class AppModule { } +export class AppModule { +} diff --git a/TaskmanClient/src/app/app.routes.ts b/TaskmanClient/src/app/app.routes.ts index 1a4e3e6..fdcb859 100644 --- a/TaskmanClient/src/app/app.routes.ts +++ b/TaskmanClient/src/app/app.routes.ts @@ -1,4 +1,4 @@ -import { Routes } from '@angular/router'; +import {Routes} from '@angular/router'; import {LoginComponent} from "./login/login.component"; import {RegisterComponent} from "./register/register.component"; import {StartPageComponent} from "./start/start-page.component"; @@ -6,9 +6,9 @@ import {ProjectsComponent} from "./projects/projects.component"; import {AuthGuard} from "./service/auth-service"; export const routes: Routes = [ - { path: 'login', component: LoginComponent }, - { path: 'register', component: RegisterComponent }, - { path: 'start', component: StartPageComponent }, - {path:'dashboard',component:ProjectsComponent ,canActivate: [AuthGuard]}, - { path: '**', redirectTo: '/start', pathMatch: 'full' } + {path: 'login', component: LoginComponent}, + {path: 'register', component: RegisterComponent}, + {path: 'start', component: StartPageComponent}, + {path: 'dashboard', component: ProjectsComponent, canActivate: [AuthGuard]}, + {path: '**', redirectTo: '/start', pathMatch: 'full'} ]; diff --git a/TaskmanClient/src/app/footer/footer.component.html b/TaskmanClient/src/app/footer/footer.component.html index 51c45d7..8652745 100644 --- a/TaskmanClient/src/app/footer/footer.component.html +++ b/TaskmanClient/src/app/footer/footer.component.html @@ -1,32 +1,35 @@ diff --git a/TaskmanClient/src/app/footer/footer.component.spec.ts b/TaskmanClient/src/app/footer/footer.component.spec.ts index afd0ee6..f67329d 100644 --- a/TaskmanClient/src/app/footer/footer.component.spec.ts +++ b/TaskmanClient/src/app/footer/footer.component.spec.ts @@ -1,5 +1,5 @@ -import { TestBed } from '@angular/core/testing'; -import { AppComponent } from '../app.component'; +import {TestBed} from '@angular/core/testing'; +import {AppComponent} from '../app.component'; describe('AppComponent', () => { beforeEach(async () => { diff --git a/TaskmanClient/src/app/footer/footer.component.ts b/TaskmanClient/src/app/footer/footer.component.ts index e8e16e4..1a76afc 100644 --- a/TaskmanClient/src/app/footer/footer.component.ts +++ b/TaskmanClient/src/app/footer/footer.component.ts @@ -1,16 +1,17 @@ -import { Component } from '@angular/core'; +import {Component} from '@angular/core'; import {Router, RouterOutlet} from '@angular/router'; import {NgOptimizedImage} from "@angular/common"; @Component({ selector: 'app-footer', - standalone: true, + standalone: true, imports: [RouterOutlet, NgOptimizedImage], templateUrl: './footer.component.html', styleUrl: './footer.component.scss' }) export class FooterComponent { title = 'TaskmanClient'; + constructor(private router: Router) { } diff --git a/TaskmanClient/src/app/header/header.component.html b/TaskmanClient/src/app/header/header.component.html index b708afb..180fe28 100644 --- a/TaskmanClient/src/app/header/header.component.html +++ b/TaskmanClient/src/app/header/header.component.html @@ -1,35 +1,57 @@
-