diff --git a/.github/workflows/build_microservices.yml b/.github/workflows/build_microservices.yml index d53f07a0d..a7339fe11 100644 --- a/.github/workflows/build_microservices.yml +++ b/.github/workflows/build_microservices.yml @@ -24,6 +24,8 @@ jobs: test_dir: 'MiniSpace.Services.Organizations/tests' - project: 'MiniSpace.Services.Posts/src/MiniSpace.Services.Posts.Api' test_dir: 'MiniSpace.Services.Posts/tests' + - project: 'MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Api' + test_dir: 'MiniSpace.Services.Reactions/tests' - project: 'MiniSpace.Web/src/MiniSpace.Web' steps: - uses: actions/checkout@v3 diff --git a/MiniSpace.Services.Reactions/MiniSpace.Services.Reactions.sln b/MiniSpace.Services.Reactions/MiniSpace.Services.Reactions.sln index 5823effcb..d318646df 100644 --- a/MiniSpace.Services.Reactions/MiniSpace.Services.Reactions.sln +++ b/MiniSpace.Services.Reactions/MiniSpace.Services.Reactions.sln @@ -1,17 +1,23 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E78E3850-ECCC-443C-B325-9F13D1639D46}" +Project("{3d037f0c-67cd-45ad-b948-796556725ba1}") = "src", "src", "{e6ad26e8-28d9-4ad5-a725-bc0420c4a11e}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Reactions.Api", "src\MiniSpace.Services.Reactions.Api\MiniSpace.Services.Reactions.Api.csproj", "{05081A01-8BBE-4BB3-931C-4F33F78A7571}" +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Api", "src\MiniSpace.Services.Reactions.Api\MiniSpace.Services.Reactions.Api.csproj", "{18b66777-ecb1-467d-9cc3-8259358cbbba}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Reactions.Application", "src\MiniSpace.Services.Reactions.Application\MiniSpace.Services.Reactions.Application.csproj", "{E122069F-329F-4400-8B3A-057BC704F5FC}" +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Application", "src\MiniSpace.Services.Reactions.Application\MiniSpace.Services.Reactions.Application.csproj", "{d80f3f9e-14fa-49ab-83a9-182583dad2f7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Reactions.Core", "src\MiniSpace.Services.Reactions.Core\MiniSpace.Services.Reactions.Core.csproj", "{6B7F5638-AC31-482B-B806-D7AE537D0A10}" +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Core", "src\MiniSpace.Services.Reactions.Core\MiniSpace.Services.Reactions.Core.csproj", "{a8fc1492-3d9c-4e35-99bf-ffda61450adb}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniSpace.Services.Reactions.Infrastructure", "src\MiniSpace.Services.Reactions.Infrastructure\MiniSpace.Services.Reactions.Infrastructure.csproj", "{DC4D92C4-18F6-463B-BD20-C9BEE5F9267F}" +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Infrastructure", "src\MiniSpace.Services.Reactions.Infrastructure\MiniSpace.Services.Reactions.Infrastructure.csproj", "{222dd1d9-d8bc-41c5-93b8-f8199287ba68}" +EndProject +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Application.UnitTests", "tests\MiniSpace.Services.Reactions.Application.UnitTests\MiniSpace.Services.Reactions.Application.UnitTests.csproj", "{be268176-f843-4500-bcf6-80aea4a6320a}" +EndProject +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Core.UnitTests", "tests\MiniSpace.Services.Reactions.Core.UnitTests\MiniSpace.Services.Reactions.Core.UnitTests.csproj", "{fa017319-e08b-4b07-b275-b0e11a74d975}" +EndProject +Project("{43649d59-f453-441c-8bf8-d49a10ade886}") = "MiniSpace.Services.Reactions.Infrastructure.UnitTests", "tests\MiniSpace.Services.Reactions.Infrastructure.UnitTests\MiniSpace.Services.Reactions.Infrastructure.UnitTests.csproj", "{287b6364-298e-4f8e-8f12-511b5f7daa40}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,27 +28,42 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {05081A01-8BBE-4BB3-931C-4F33F78A7571}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {05081A01-8BBE-4BB3-931C-4F33F78A7571}.Debug|Any CPU.Build.0 = Debug|Any CPU - {05081A01-8BBE-4BB3-931C-4F33F78A7571}.Release|Any CPU.ActiveCfg = Release|Any CPU - {05081A01-8BBE-4BB3-931C-4F33F78A7571}.Release|Any CPU.Build.0 = Release|Any CPU - {E122069F-329F-4400-8B3A-057BC704F5FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E122069F-329F-4400-8B3A-057BC704F5FC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E122069F-329F-4400-8B3A-057BC704F5FC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E122069F-329F-4400-8B3A-057BC704F5FC}.Release|Any CPU.Build.0 = Release|Any CPU - {6B7F5638-AC31-482B-B806-D7AE537D0A10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6B7F5638-AC31-482B-B806-D7AE537D0A10}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6B7F5638-AC31-482B-B806-D7AE537D0A10}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6B7F5638-AC31-482B-B806-D7AE537D0A10}.Release|Any CPU.Build.0 = Release|Any CPU - {DC4D92C4-18F6-463B-BD20-C9BEE5F9267F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DC4D92C4-18F6-463B-BD20-C9BEE5F9267F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DC4D92C4-18F6-463B-BD20-C9BEE5F9267F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DC4D92C4-18F6-463B-BD20-C9BEE5F9267F}.Release|Any CPU.Build.0 = Release|Any CPU + {18b66777-ecb1-467d-9cc3-8259358cbbba}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18b66777-ecb1-467d-9cc3-8259358cbbba}.Debug|Any CPU.Build.0 = Debug|Any CPU + {18b66777-ecb1-467d-9cc3-8259358cbbba}.Release|Any CPU.ActiveCfg = Release|Any CPU + {18b66777-ecb1-467d-9cc3-8259358cbbba}.Release|Any CPU.Build.0 = Release|Any CPU + {d80f3f9e-14fa-49ab-83a9-182583dad2f7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {d80f3f9e-14fa-49ab-83a9-182583dad2f7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {d80f3f9e-14fa-49ab-83a9-182583dad2f7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {d80f3f9e-14fa-49ab-83a9-182583dad2f7}.Release|Any CPU.Build.0 = Release|Any CPU + {a8fc1492-3d9c-4e35-99bf-ffda61450adb}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {a8fc1492-3d9c-4e35-99bf-ffda61450adb}.Debug|Any CPU.Build.0 = Debug|Any CPU + {a8fc1492-3d9c-4e35-99bf-ffda61450adb}.Release|Any CPU.ActiveCfg = Release|Any CPU + {a8fc1492-3d9c-4e35-99bf-ffda61450adb}.Release|Any CPU.Build.0 = Release|Any CPU + {222dd1d9-d8bc-41c5-93b8-f8199287ba68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {222dd1d9-d8bc-41c5-93b8-f8199287ba68}.Debug|Any CPU.Build.0 = Debug|Any CPU + {222dd1d9-d8bc-41c5-93b8-f8199287ba68}.Release|Any CPU.ActiveCfg = Release|Any CPU + {222dd1d9-d8bc-41c5-93b8-f8199287ba68}.Release|Any CPU.Build.0 = Release|Any CPU + {be268176-f843-4500-bcf6-80aea4a6320a}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {be268176-f843-4500-bcf6-80aea4a6320a}.Debug|Any CPU.Build.0 = Debug|Any CPU + {be268176-f843-4500-bcf6-80aea4a6320a}.Release|Any CPU.ActiveCfg = Release|Any CPU + {be268176-f843-4500-bcf6-80aea4a6320a}.Release|Any CPU.Build.0 = Release|Any CPU + {fa017319-e08b-4b07-b275-b0e11a74d975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {fa017319-e08b-4b07-b275-b0e11a74d975}.Debug|Any CPU.Build.0 = Debug|Any CPU + {fa017319-e08b-4b07-b275-b0e11a74d975}.Release|Any CPU.ActiveCfg = Release|Any CPU + {fa017319-e08b-4b07-b275-b0e11a74d975}.Release|Any CPU.Build.0 = Release|Any CPU + {287b6364-298e-4f8e-8f12-511b5f7daa40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {287b6364-298e-4f8e-8f12-511b5f7daa40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {287b6364-298e-4f8e-8f12-511b5f7daa40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {287b6364-298e-4f8e-8f12-511b5f7daa40}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution - {05081A01-8BBE-4BB3-931C-4F33F78A7571} = {E78E3850-ECCC-443C-B325-9F13D1639D46} - {E122069F-329F-4400-8B3A-057BC704F5FC} = {E78E3850-ECCC-443C-B325-9F13D1639D46} - {6B7F5638-AC31-482B-B806-D7AE537D0A10} = {E78E3850-ECCC-443C-B325-9F13D1639D46} - {DC4D92C4-18F6-463B-BD20-C9BEE5F9267F} = {E78E3850-ECCC-443C-B325-9F13D1639D46} + {18b66777-ecb1-467d-9cc3-8259358cbbba} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} + {d80f3f9e-14fa-49ab-83a9-182583dad2f7} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} + {a8fc1492-3d9c-4e35-99bf-ffda61450adb} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} + {222dd1d9-d8bc-41c5-93b8-f8199287ba68} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} + {be268176-f843-4500-bcf6-80aea4a6320a} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} + {fa017319-e08b-4b07-b275-b0e11a74d975} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} + {287b6364-298e-4f8e-8f12-511b5f7daa40} = {e6ad26e8-28d9-4ad5-a725-bc0420c4a11e} EndGlobalSection -EndGlobal +EndGlobal \ No newline at end of file diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionDto.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionDto.cs index 474c1478f..6b50c338e 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionDto.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionDto.cs @@ -1,8 +1,10 @@ +using System.Diagnostics.CodeAnalysis; using MiniSpace.Services.Reactions.Core.Entities; namespace MiniSpace.Services.Reactions.Application.Dto { + [ExcludeFromCodeCoverage] public class ReactionDto { public Guid Id { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionsSummaryDto.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionsSummaryDto.cs index 42adb1df7..f4c7317cd 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionsSummaryDto.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Dto/ReactionsSummaryDto.cs @@ -1,8 +1,10 @@ +using System.Diagnostics.CodeAnalysis; using MiniSpace.Services.Reactions.Core.Entities; namespace MiniSpace.Services.Reactions.Application.Dto { + [ExcludeFromCodeCoverage] public class ReactionsSummaryDto(int nrReactions, ReactionType? dominant, Guid? authUserReactionId, ReactionType? authUserReactionType) { diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Events/External/Handlers/PostCreatedHandler.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Events/External/Handlers/PostCreatedHandler.cs index 9a146fdb5..5933153f4 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Events/External/Handlers/PostCreatedHandler.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Events/External/Handlers/PostCreatedHandler.cs @@ -21,7 +21,7 @@ public async Task HandleAsync(PostCreated @event, CancellationToken cancellation { if (await _postRepository.ExistsAsync(@event.PostId)) { - throw new StudentAlreadyAddedException(@event.PostId); + throw new PostAlreadyAddedException(@event.PostId); } await _postRepository.AddAsync(new Post(@event.PostId)); diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Exceptions/PostAlreadyAddedException.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Exceptions/PostAlreadyAddedException.cs new file mode 100644 index 000000000..404ee8c42 --- /dev/null +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Exceptions/PostAlreadyAddedException.cs @@ -0,0 +1,14 @@ +namespace MiniSpace.Services.Reactions.Application.Exceptions +{ + public class PostAlreadyAddedException : AppException + { + public override string Code { get; } = "post_already_added"; + public Guid PostId { get; } + + public PostAlreadyAddedException(Guid postId) + : base($"Post with id: {postId} was already added.") + { + PostId = postId; + } + } +} diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Extensions.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Extensions.cs index eedc5326f..85882d7b2 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Extensions.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Extensions.cs @@ -1,9 +1,11 @@ +using System.Diagnostics.CodeAnalysis; using Convey; using Convey.CQRS.Commands; using Convey.CQRS.Events; namespace MiniSpace.Services.Reactions.Application { + [ExcludeFromCodeCoverage] public static class Extensions { public static IConveyBuilder AddApplication(this IConveyBuilder builder) diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactions.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactions.cs index 35da121ab..30289cde7 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactions.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactions.cs @@ -1,10 +1,12 @@ +using System.Diagnostics.CodeAnalysis; using Convey.CQRS.Queries; using MiniSpace.Services.Reactions.Application.Dto; using MiniSpace.Services.Reactions.Core.Entities; namespace MiniSpace.Services.Reactions.Application.Queries { + [ExcludeFromCodeCoverage] public class GetReactions : IQuery> { public Guid ContentId { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactionsSummary.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactionsSummary.cs index da876e974..a60d50a42 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactionsSummary.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Application/Queries/GetReactionsSummary.cs @@ -1,4 +1,5 @@ +using System.Diagnostics.CodeAnalysis; using Convey.CQRS.Queries; using MiniSpace.Services.Reactions.Application.Dto; using MiniSpace.Services.Reactions.Core.Entities; @@ -6,6 +7,7 @@ namespace MiniSpace.Services.Reactions.Application.Queries { + [ExcludeFromCodeCoverage] public class GetReactionsSummary : IQuery { public Guid ContentId { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContext.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContext.cs index ce174891c..ebe8fed9d 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContext.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContext.cs @@ -1,7 +1,9 @@ +using System.Diagnostics.CodeAnalysis; using MiniSpace.Services.Reactions.Application; namespace MiniSpace.Services.Reactions.Infrastructure.Contexts { + [ExcludeFromCodeCoverage] internal class AppContext : IAppContext { public string RequestId { get; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContextFactory.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContextFactory.cs index 558fa1860..a743b55df 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContextFactory.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/AppContextFactory.cs @@ -2,9 +2,11 @@ using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using MiniSpace.Services.Reactions.Application; +using System.Diagnostics.CodeAnalysis; namespace MiniSpace.Services.Reactions.Infrastructure.Contexts { + [ExcludeFromCodeCoverage] internal sealed class AppContextFactory : IAppContextFactory { private readonly ICorrelationContextAccessor _contextAccessor; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/CorrelationContext.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/CorrelationContext.cs index 992fd7079..842670842 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/CorrelationContext.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/CorrelationContext.cs @@ -1,5 +1,8 @@ +using System.Diagnostics.CodeAnalysis; + namespace MiniSpace.Services.Reactions.Infrastructure.Contexts { + [ExcludeFromCodeCoverage] internal class CorrelationContext { public string CorrelationId { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/IdentityContext.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/IdentityContext.cs index 073e96468..d305b8e8c 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/IdentityContext.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Contexts/IdentityContext.cs @@ -1,7 +1,9 @@ +using System.Diagnostics.CodeAnalysis; using MiniSpace.Services.Reactions.Application; namespace MiniSpace.Services.Reactions.Infrastructure.Contexts { + [ExcludeFromCodeCoverage] internal class IdentityContext : IIdentityContext { public Guid Id { get; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxCommandHandlerDecorator.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxCommandHandlerDecorator.cs index dd770fd56..6448d1944 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxCommandHandlerDecorator.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxCommandHandlerDecorator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.CQRS.Commands; using Convey.MessageBrokers; using Convey.MessageBrokers.Outbox; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Decorators { + [ExcludeFromCodeCoverage] [Decorator] internal sealed class OutboxCommandHandlerDecorator : ICommandHandler where TCommand : class, ICommand diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxEventHandlerDecorator.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxEventHandlerDecorator.cs index 57bd45159..9c8d7755f 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxEventHandlerDecorator.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Decorators/OutboxEventHandlerDecorator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.CQRS.Events; using Convey.MessageBrokers; using Convey.MessageBrokers.Outbox; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Decorators { + [ExcludeFromCodeCoverage] [Decorator] internal sealed class OutboxEventHandlerDecorator : IEventHandler where TEvent : class, IEvent diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToMessageMapper.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToMessageMapper.cs index 21e9c097c..5df6e2a82 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToMessageMapper.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToMessageMapper.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.MessageBrokers.RabbitMQ; using MiniSpace.Services.Reactions.Application.Commands; using MiniSpace.Services.Reactions.Application.Events.Rejected; @@ -8,6 +9,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Exceptions { + [ExcludeFromCodeCoverage] internal sealed class ExceptionToMessageMapper : IExceptionToMessageMapper { public object Map(Exception exception, object message) diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToResponseMapper.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToResponseMapper.cs index 213b0e342..45c8017b9 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToResponseMapper.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Exceptions/ExceptionToResponseMapper.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using System.Net; using Convey; using Convey.WebApi.Exceptions; @@ -7,6 +8,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Exceptions { + [ExcludeFromCodeCoverage] internal sealed class ExceptionToResponseMapper : IExceptionToResponseMapper { private static readonly ConcurrentDictionary Codes = new ConcurrentDictionary(); diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Extensions.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Extensions.cs index 7de580200..463e41475 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Extensions.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Extensions.cs @@ -41,9 +41,11 @@ using Convey.Logging.CQRS; using MiniSpace.Services.Reactions.Application.Events; using MiniSpace.Services.Reactions.Application.Events.External; +using System.Diagnostics.CodeAnalysis; namespace MiniSpace.Services.Reactions.Infrastructure { + [ExcludeFromCodeCoverage] public static class Extensions { public static IConveyBuilder AddInfrastructure(this IConveyBuilder builder) diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/Extensions.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/Extensions.cs index e642cb90d..64466eb7b 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/Extensions.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/Extensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey; using Convey.Logging.CQRS; using Microsoft.Extensions.DependencyInjection; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Logging { + [ExcludeFromCodeCoverage] internal static class Extensions { public static IConveyBuilder AddHandlersLogging(this IConveyBuilder builder) diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/MessageToLogTemplateMapper.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/MessageToLogTemplateMapper.cs index a2383e89c..9b0803c60 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/MessageToLogTemplateMapper.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Logging/MessageToLogTemplateMapper.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Logging.CQRS; using MiniSpace.Services.Reactions.Application.Commands; using MiniSpace.Services.Reactions.Application.Events; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Logging { + [ExcludeFromCodeCoverage] internal sealed class MessageToLogTemplateMapper : IMessageToLogTemplateMapper { private static IReadOnlyDictionary MessageTemplates diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/EventDocument.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/EventDocument.cs index d17d51cbc..b861ace39 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/EventDocument.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/EventDocument.cs @@ -1,7 +1,9 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Types; namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Documents { + [ExcludeFromCodeCoverage] public class EventDocument : IIdentifiable { public Guid Id { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/Extensions.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/Extensions.cs index df263b75d..3584e73de 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/Extensions.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/Extensions.cs @@ -1,8 +1,10 @@ +using System.Diagnostics.CodeAnalysis; using MiniSpace.Services.Reactions.Application.Dto; using MiniSpace.Services.Reactions.Core.Entities; namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Documents { + [ExcludeFromCodeCoverage] public static class Extensions { public static Reaction AsEntity(this ReactionDocument document) diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/PostDocument.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/PostDocument.cs index 7667f01d5..77aff9dbe 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/PostDocument.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/PostDocument.cs @@ -1,7 +1,9 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Types; namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Documents { + [ExcludeFromCodeCoverage] public class PostDocument : IIdentifiable { public Guid Id { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/ReactionDocument.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/ReactionDocument.cs index 70839cd63..19a0facc9 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/ReactionDocument.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/ReactionDocument.cs @@ -1,9 +1,11 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Types; using Convey.WebApi.CQRS; using MiniSpace.Services.Reactions.Core.Entities; namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Documents { + [ExcludeFromCodeCoverage] public class ReactionDocument : IIdentifiable { public Guid Id {get;set;} diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/StudentDocument.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/StudentDocument.cs index 045f88352..859d49f98 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/StudentDocument.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Documents/StudentDocument.cs @@ -1,7 +1,9 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Types; namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Documents { + [ExcludeFromCodeCoverage] public class StudentDocument : IIdentifiable { public Guid Id { get; set; } diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsHandler.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsHandler.cs index d488e6a81..8463aa226 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsHandler.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsHandler.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.CQRS.Queries; using Convey.Persistence.MongoDB; using DnsClient; @@ -10,6 +11,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Queries.Handlers { + [ExcludeFromCodeCoverage] public class GetReactionsHandler : IQueryHandler> { private readonly IMongoRepository _reactionRepository; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsSummaryHandler.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsSummaryHandler.cs index 62da6a09d..d39a1aa3c 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsSummaryHandler.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Queries/Handlers/GetReactionsSummaryHandler.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.CQRS.Queries; using Convey.Persistence.MongoDB; using MiniSpace.Services.Reactions.Application; @@ -10,6 +11,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Queries.Handlers { + [ExcludeFromCodeCoverage] public class GetReactionsSummaryHandler : IQueryHandler { private readonly IMongoRepository _reactionRepository; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/EventMongoRepository.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/EventMongoRepository.cs index e33b1fce9..1868abe65 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/EventMongoRepository.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/EventMongoRepository.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Persistence.MongoDB; using MiniSpace.Services.Reactions.Core.Entities; using MiniSpace.Services.Reactions.Core.Repositories; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Repositories { + [ExcludeFromCodeCoverage] public class EventMongoRepository : IEventRepository { private readonly IMongoRepository _repository; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/PostMongoRepository.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/PostMongoRepository.cs index 85506560d..8dce852f1 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/PostMongoRepository.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/PostMongoRepository.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Persistence.MongoDB; using MiniSpace.Services.Reactions.Core.Entities; using MiniSpace.Services.Reactions.Core.Repositories; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Repositories { + [ExcludeFromCodeCoverage] public class PostMongoRepository : IPostRepository { private readonly IMongoRepository _repository; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/ReactionMongoRepository.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/ReactionMongoRepository.cs index 8721c6c3d..011e32b07 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/ReactionMongoRepository.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/ReactionMongoRepository.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Persistence.MongoDB; using Jaeger.Propagation; using Microsoft.AspNetCore.Components.Forms; @@ -9,6 +10,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Repositories { + [ExcludeFromCodeCoverage] public class ReactionMongoRepository(IMongoRepository repository) : IReactionRepository { private readonly IMongoRepository _repository = repository; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/StudentMongoRepository.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/StudentMongoRepository.cs index 1b0bfaddd..a86eefccf 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/StudentMongoRepository.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Mongo/Repositories/StudentMongoRepository.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Convey.Persistence.MongoDB; using MiniSpace.Services.Reactions.Core.Entities; using MiniSpace.Services.Reactions.Core.Repositories; @@ -5,6 +6,7 @@ namespace MiniSpace.Services.Reactions.Infrastructure.Mongo.Repositories { + [ExcludeFromCodeCoverage] public class StudentMongoRepository : IStudentRepository { private readonly IMongoRepository _repository; diff --git a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Services/MessageBroker.cs b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Services/MessageBroker.cs index ae7b64798..3c8a76256 100644 --- a/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Services/MessageBroker.cs +++ b/MiniSpace.Services.Reactions/src/MiniSpace.Services.Reactions.Infrastructure/Services/MessageBroker.cs @@ -6,7 +6,9 @@ using Microsoft.Extensions.Logging; using OpenTracing; using MiniSpace.Services.Reactions.Application.Services; +using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("MiniSpace.Services.Reactions.Infrastructure.UnitTests")] namespace MiniSpace.Services.Reactions.Infrastructure.Services { internal sealed class MessageBroker : IMessageBroker diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Commands/Handlers/ChangeReactionHandlerTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Commands/Handlers/ChangeReactionHandlerTest.cs new file mode 100644 index 000000000..e69de29bb diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Commands/Handlers/DeleteReactionHandlerTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Commands/Handlers/DeleteReactionHandlerTest.cs new file mode 100644 index 000000000..e69de29bb diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/EventCreatedHandlerTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/EventCreatedHandlerTest.cs new file mode 100644 index 000000000..de740e93f --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/EventCreatedHandlerTest.cs @@ -0,0 +1,65 @@ +using Xunit; +using Moq; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using MiniSpace.Services.Reactions.Application.Exceptions; +using MiniSpace.Services.Reactions.Application.Services; +using MiniSpace.Services.Reactions.Core.Entities; +using MiniSpace.Services.Reactions.Core.Repositories; +using MiniSpace.Services.Reactions.Application.Commands.Handlers; +using MiniSpace.Services.Reactions.Application.Commands; +using MiniSpace.Services.Reactions.Infrastructure.Contexts; +using System.Threading; +using FluentAssertions; +using MiniSpace.Services.Reactions.Application.Events.External.Handlers; +using MiniSpace.Services.Reactions.Application.Events.External; +using System.ComponentModel.Design; +using Convey.CQRS.Commands; + +namespace MiniSpace.Services.Reactions.Application.UnitTests.Events.External.Handlers +{ + public class EventCreatedHandlerTest + { + private readonly EventCreatedHandler _eventDeletedHandler; + private readonly Mock _eventRepositoryMock; + + public EventCreatedHandlerTest() + { + _eventRepositoryMock = new(); + _eventDeletedHandler = new EventCreatedHandler(_eventRepositoryMock.Object); + } + + [Fact] + public async Task HandleAsync_ValidData_ShouldNotThrowExeption() + { + // Arrange + var eventId = Guid.NewGuid(); + var organizerId = Guid.NewGuid(); + var @event = new EventCreated(eventId, organizerId); + + _eventRepositoryMock.Setup(repo => repo.ExistsAsync(eventId)) + .ReturnsAsync(false); + + // Act & Assert + Func act = async () => await _eventDeletedHandler.HandleAsync(@event); + await act.Should().NotThrowAsync(); + } + + [Fact] + public async Task HandleAsync_EventAlreadyCreated_ShouldThrowEventAlreadyExistsException() + { + // Arrange + var eventId = Guid.NewGuid(); + var organizerId = Guid.NewGuid(); + var @event = new EventCreated(eventId, organizerId); + + _eventRepositoryMock.Setup(repo => repo.ExistsAsync(eventId)) + .ReturnsAsync(true); + + // Act & Assert + Func act = async () => await _eventDeletedHandler.HandleAsync(@event); + await act.Should().ThrowAsync(); + } + } +} \ No newline at end of file diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/PostCreatedHandlerTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/PostCreatedHandlerTest.cs new file mode 100644 index 000000000..e62a753ac --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/PostCreatedHandlerTest.cs @@ -0,0 +1,64 @@ +using Xunit; +using Moq; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using MiniSpace.Services.Reactions.Application.Exceptions; +using MiniSpace.Services.Reactions.Application.Services; +using MiniSpace.Services.Reactions.Core.Entities; +using MiniSpace.Services.Reactions.Core.Repositories; +using MiniSpace.Services.Reactions.Application.Commands.Handlers; +using MiniSpace.Services.Reactions.Application.Commands; +using MiniSpace.Services.Reactions.Infrastructure.Contexts; +using System.Threading; +using FluentAssertions; +using MiniSpace.Services.Reactions.Application.Events.External.Handlers; +using MiniSpace.Services.Reactions.Application.Events.External; +using System.ComponentModel.Design; +using Convey.CQRS.Commands; +using MiniSpace.Services.Reactions.Application.Events; + +namespace MiniSpace.Services.Reactions.Application.UnitTests.Events.External.Handlers +{ + public class PostCreatedHandlerTest + { + private readonly PostCreatedHandler _postDeletedHandler; + private readonly Mock _postRepositoryMock; + + public PostCreatedHandlerTest() + { + _postRepositoryMock = new(); + _postDeletedHandler = new PostCreatedHandler(_postRepositoryMock.Object); + } + + [Fact] + public async Task HandleAsync_ValidData_ShouldNotThrowExeption() + { + // Arrange + var postId = Guid.NewGuid(); + var post = new PostCreated(postId); + + _postRepositoryMock.Setup(repo => repo.ExistsAsync(postId)) + .ReturnsAsync(false); + + // Act & Assert + Func act = async () => await _postDeletedHandler.HandleAsync(post, new CancellationToken()); + await act.Should().NotThrowAsync(); + } + + [Fact] + public async Task HandleAsync_PostAlreadyCreated_ShouldThrowPostAlreadyExistsException() + { + // Arrange + var postId = Guid.NewGuid(); + var post = new PostCreated(postId); + + _postRepositoryMock.Setup(repo => repo.ExistsAsync(postId)) + .ReturnsAsync(true); + + // Act & Assert + Func act = async () => await _postDeletedHandler.HandleAsync(post, new CancellationToken()); + await act.Should().ThrowAsync(); + } + } +} \ No newline at end of file diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/StudentCreatedHandlerTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/StudentCreatedHandlerTest.cs new file mode 100644 index 000000000..43569aa97 --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/Events/External/Handlers/StudentCreatedHandlerTest.cs @@ -0,0 +1,65 @@ +using Xunit; +using Moq; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using MiniSpace.Services.Reactions.Application.Exceptions; +using MiniSpace.Services.Reactions.Application.Services; +using MiniSpace.Services.Reactions.Core.Entities; +using MiniSpace.Services.Reactions.Core.Repositories; +using MiniSpace.Services.Reactions.Application.Commands.Handlers; +using MiniSpace.Services.Reactions.Application.Commands; +using MiniSpace.Services.Reactions.Infrastructure.Contexts; +using System.Threading; +using FluentAssertions; +using MiniSpace.Services.Reactions.Application.Events.External.Handlers; +using MiniSpace.Services.Reactions.Application.Events.External; +using System.ComponentModel.Design; + +namespace MiniSpace.Services.Reactions.Application.UnitTests.Events.External.Handlers +{ + public class StudentCreatedHandlerTest + { + private readonly StudentCreatedHandler _studentCreatedHandler; + private readonly Mock _studentRepositoryMock; + + public StudentCreatedHandlerTest() + { + _studentRepositoryMock = new Mock(); + _studentCreatedHandler = new StudentCreatedHandler(_studentRepositoryMock.Object); + } + + [Fact] + public async Task HandleAsync_ValidData_ShouldNotThrowExeption() + { + // Arrange + var studentId = Guid.NewGuid(); + var @event = new StudentCreated(studentId, "Jan Kowalski"); + var cancellationToken = new CancellationToken(); + + _studentRepositoryMock.Setup(repo => repo.ExistsAsync(studentId)) + .ReturnsAsync(false); + + // Act & Assert + Func act = async () => await _studentCreatedHandler.HandleAsync(@event, cancellationToken); + await act.Should().NotThrowAsync(); + + } + + [Fact] + public async Task HandleAsync_StudentAlreadyCreated_ShuldThrowStudentAlreadyAddedException() + { + // Arrange + var studentId = Guid.NewGuid(); + var @event = new StudentCreated(studentId, "Jan Kowalski"); + var cancellationToken = new CancellationToken(); + + _studentRepositoryMock.Setup(repo => repo.ExistsAsync(studentId)) + .ReturnsAsync(true); + + // Act & Assert + Func act = async () => await _studentCreatedHandler.HandleAsync(@event, cancellationToken); + await act.Should().ThrowAsync(); + } + } +} \ No newline at end of file diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/MiniSpace.Services.Reactions.Application.UnitTests.csproj b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/MiniSpace.Services.Reactions.Application.UnitTests.csproj new file mode 100644 index 000000000..bd23aff30 --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Application.UnitTests/MiniSpace.Services.Reactions.Application.UnitTests.csproj @@ -0,0 +1,33 @@ + + + + net8.0 + enable + disable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Core.UnitTests/Entities/AggregatedIdTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Core.UnitTests/Entities/AggregatedIdTest.cs new file mode 100644 index 000000000..623ceff84 --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Core.UnitTests/Entities/AggregatedIdTest.cs @@ -0,0 +1,52 @@ +using Xunit; +using Moq; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Linq; +using System.Text; +using MiniSpace.Services.Reactions.Application.Events; +using MiniSpace.Services.Reactions.Application.Exceptions; +using MiniSpace.Services.Reactions.Application.Services; +using MiniSpace.Services.Reactions.Core.Entities; +using MiniSpace.Services.Reactions.Core.Repositories; +using MiniSpace.Services.Reactions.Application.Commands.Handlers; +using MiniSpace.Services.Reactions.Application.Commands; +using MiniSpace.Services.Reactions.Infrastructure.Contexts; +using Convey.CQRS.Commands; +using System.Threading; +using System.Security.Claims; +using FluentAssertions; +using MiniSpace.Services.Reactions.Core.Exceptions; +using Microsoft.AspNetCore.DataProtection.KeyManagement; + +namespace MiniSpace.Services.Reactions.Core.UnitTests.Entities +{ + public class AggregatedIdTest + { + [Fact] + public void AggregateId_CreatedTwice_ShouldBeDifferent() + { + // Arrange & Act + var id1 = new AggregateId(); + var id2 = new AggregateId(); + + // Assert + Assert.NotEqual(id1.Value, id2.Value); + } + + [Fact] + public void AggregateId_CreatedTwiceSameGuid_ShouldBeSame() + { + // Arrange + var id = Guid.NewGuid(); + + // Act + var id1 = new AggregateId(id); + var id2 = new AggregateId(id); + + // Assert + Assert.Equal(id1.Value, id2.Value); + } + } +} \ No newline at end of file diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Core.UnitTests/MiniSpace.Services.Reactions.Core.UnitTests.csproj b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Core.UnitTests/MiniSpace.Services.Reactions.Core.UnitTests.csproj new file mode 100644 index 000000000..bd23aff30 --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Core.UnitTests/MiniSpace.Services.Reactions.Core.UnitTests.csproj @@ -0,0 +1,33 @@ + + + + net8.0 + enable + disable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Infrastructure.UnitTests/MiniSpace.Services.Reactions.Infrastructure.UnitTests.csproj b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Infrastructure.UnitTests/MiniSpace.Services.Reactions.Infrastructure.UnitTests.csproj new file mode 100644 index 000000000..bd23aff30 --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Infrastructure.UnitTests/MiniSpace.Services.Reactions.Infrastructure.UnitTests.csproj @@ -0,0 +1,33 @@ + + + + net8.0 + enable + disable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Infrastructure.UnitTests/Services/MessageBrokerTest.cs b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Infrastructure.UnitTests/Services/MessageBrokerTest.cs new file mode 100644 index 000000000..dcd755ff6 --- /dev/null +++ b/MiniSpace.Services.Reactions/tests/MiniSpace.Services.Reactions.Infrastructure.UnitTests/Services/MessageBrokerTest.cs @@ -0,0 +1,142 @@ +using Xunit; +using Moq; +using Convey.CQRS.Events; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Convey.MessageBrokers; +using Convey.MessageBrokers.Outbox; +using Convey.MessageBrokers.RabbitMQ; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using OpenTracing; +using MiniSpace.Services.Reactions.Infrastructure.Services; +using MiniSpace.Services.Reactions.Application.Services; +using MiniSpace.Services.Reactions.Application.Events; + +namespace MiniSpace.Services.Reactions.Infrastructure.UnitTests.Services +{ + public class MessageBrokerTest + { + private readonly MessageBroker _messageBroker; + private readonly Mock _mockBusPublisher; + private readonly Mock _mockMessageOutbox; + private readonly Mock _mockContextAccessor; + private readonly Mock _mockHttpContextAccessor; + private readonly Mock _mockMessagePropertiesAccessor; + private readonly Mock _mockTracer; + private readonly Mock> _mockLogger; + + public MessageBrokerTest() + { + _mockBusPublisher = new Mock(); + _mockMessageOutbox = new Mock(); + _mockContextAccessor = new Mock(); + _mockHttpContextAccessor = new Mock(); + _mockMessagePropertiesAccessor = new Mock(); + _mockTracer = new Mock(); + _mockLogger = new Mock>(); + + _messageBroker = new MessageBroker(_mockBusPublisher.Object, _mockMessageOutbox.Object, _mockContextAccessor.Object, + _mockHttpContextAccessor.Object, _mockMessagePropertiesAccessor.Object, new RabbitMqOptions(), + _mockTracer.Object, _mockLogger.Object); + } + + [Fact] + public async Task PublishAsync_WithEventsAndOutboxDisabled_PublishesEvents() + { + //Arrange + var events = new List + { + new PostCreated(Guid.NewGuid()) + }; + _mockMessageOutbox.Setup(x => x.Enabled).Returns(false); + + //Act + await _messageBroker.PublishAsync(events); + + //Assert + _mockMessageOutbox.Verify( + x => x.SendAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny>()), + Times.Never + ); + _mockBusPublisher.Verify( + x => x.PublishAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny>()), Times.Exactly(events.Count) + ); + } + + [Fact] + public async Task PublishAsync_WithEventsAndOutboxEnabled_SendsMessagesToOutbox() + { + //Arrange + var events = new List + { + new PostCreated(Guid.NewGuid()) + }; + _mockMessageOutbox.Setup(x => x.Enabled).Returns(true); + + //Act + await _messageBroker.PublishAsync(events); + + //Assert + _mockMessageOutbox.Verify( + x => x.SendAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny>()), + Times.Exactly(events.Count) + ); + _mockBusPublisher.Verify( + x => x.PublishAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny>()), Times.Never + ); + } + + [Fact] + public async Task PublishAsync_WithoutEvents_Returns() + { + //Arrange + List events = null; + + //Act + await _messageBroker.PublishAsync(events); + + //Assert + _mockMessageOutbox.Verify( + x => x.SendAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny>()), + Times.Never + ); + _mockBusPublisher.Verify( + x => x.PublishAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny>()), Times.Never + ); + } + + [Fact] + public async Task PublishAsync_WithNullEventAndOutboxDisabled_PublishesOneLessEvent() + { + //Arrange + var events = new List + { + new PostCreated(Guid.NewGuid()), + null + }; + _mockMessageOutbox.Setup(x => x.Enabled).Returns(false); + + //Act + await _messageBroker.PublishAsync(events); + + //Assert + _mockMessageOutbox.Verify( + x => x.SendAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny>()), + Times.Never + ); + _mockBusPublisher.Verify( + x => x.PublishAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny>()), Times.Exactly(events.Count - 1) + ); + } + } +} \ No newline at end of file