Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<Result<IEnumerable<TransactLinkDTO>>> Handle(GetAllTransactLin
{
var transactLinks = await _repositoryWrapper.TransactLinksRepository.GetAllAsync();

if (transactLinks.Any())
if (transactLinks?.Any() ?? false)
{
return Result.Ok(_mapper.Map<IEnumerable<TransactLinkDTO>>(transactLinks));
}
Expand All @@ -35,4 +35,4 @@ public async Task<Result<IEnumerable<TransactLinkDTO>>> Handle(GetAllTransactLin
_logger.LogError(request, errorMsg);
return Result.Fail(new Error(errorMsg));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System.Linq.Expressions;

Check warning on line 1 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76Xp&open=AZyu4d7nTsceoUoQ76Xp&pullRequest=116
using AutoMapper;
using FluentAssertions;
using Microsoft.EntityFrameworkCore.Query;
using Moq;

Check warning on line 5 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76Xt&open=AZyu4d7nTsceoUoQ76Xt&pullRequest=116
using Streetcode.BLL.DTO.Transactions;
using Streetcode.BLL.Interfaces.Logging;

Check warning on line 7 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76Xv&open=AZyu4d7nTsceoUoQ76Xv&pullRequest=116
using Streetcode.BLL.Mapping.Transactions;

Check warning on line 8 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76Xw&open=AZyu4d7nTsceoUoQ76Xw&pullRequest=116
using Streetcode.BLL.MediatR.Transactions.TransactionLink.GetAll;

Check warning on line 9 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76Xx&open=AZyu4d7nTsceoUoQ76Xx&pullRequest=116
using Streetcode.DAL.Entities.Transactions;

Check warning on line 10 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76Xy&open=AZyu4d7nTsceoUoQ76Xy&pullRequest=116
using Streetcode.DAL.Repositories.Interfaces.Base;
using Streetcode.Resources;

Check warning on line 12 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76X0&open=AZyu4d7nTsceoUoQ76X0&pullRequest=116
using Streetcode.Shared.Extensions;

Check warning on line 13 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76X1&open=AZyu4d7nTsceoUoQ76X1&pullRequest=116
using Xunit;

namespace Streetcode.XUnitTest.MediatR.Transactions.TransactionLink;

public class GetAllTransactLinksHandlerTests
{
private readonly Mock<IRepositoryWrapper> _mockRepo;

Check warning on line 20 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Field '_mockRepo' should not begin with an underscore

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76X3&open=AZyu4d7nTsceoUoQ76X3&pullRequest=116
private readonly Mock<ILoggerService> _mockLogger;
private readonly IMapper _mapper;

public GetAllTransactLinksHandlerTests()
{
_mockRepo = new Mock<IRepositoryWrapper>();
_mockLogger = new Mock<ILoggerService>();

Check warning on line 27 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76X-&open=AZyu4d7nTsceoUoQ76X-&pullRequest=116

var config = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new TransactionLinkProfile());
});
_mapper = new Mapper(config);

Check warning on line 33 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76X_&open=AZyu4d7nTsceoUoQ76X_&pullRequest=116
}

[Fact]
public async Task Handle_LinksExist_ReturnsSuccessWithMappedDTOs()
{
// Arrange
var links = new List<Streetcode.DAL.Entities.Transactions.TransactionLink>
{
new() { Id = 1, Url = "https://streetcode.com/1", StreetcodeId = 1 },
new() { Id = 2, Url = "https://streetcode.com/2", StreetcodeId = 2 }

Check warning on line 43 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

The keyword 'new' should be followed by a space.

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76X8&open=AZyu4d7nTsceoUoQ76X8&pullRequest=116

Check warning on line 43 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use trailing comma in multi-line initializers

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76YA&open=AZyu4d7nTsceoUoQ76YA&pullRequest=116
};

_mockRepo.Setup(r => r.TransactLinksRepository.GetAllAsync(
It.IsAny<Expression<Func<Streetcode.DAL.Entities.Transactions.TransactionLink, bool>>>(),
It.IsAny<Func<IQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink>, IIncludableQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink, object>>>(),
It.IsAny<bool>()))
.ReturnsAsync(links);

var handler = new GetAllTransactLinksHandler(
_mockRepo.Object,

Check warning on line 53 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76YC&open=AZyu4d7nTsceoUoQ76YC&pullRequest=116
_mapper,
_mockLogger.Object);

Check warning on line 55 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76YE&open=AZyu4d7nTsceoUoQ76YE&pullRequest=116

// Act
var result = await handler.Handle(
new GetAllTransactLinksQuery(),
CancellationToken.None);

// Assert
result.IsSuccess.Should().BeTrue();
result.Value.Should().HaveCount(2);
result.Value.First().Url.Should().Be("https://streetcode.com/1");
}

[Fact]
public async Task Handle_NoLinksFound_ReturnsFailureAndLogsError()
{
// Arrange
var query = new GetAllTransactLinksQuery();

_mockRepo.Setup(r => r.TransactLinksRepository.GetAllAsync(
(Expression<Func<Streetcode.DAL.Entities.Transactions.TransactionLink, bool>>)null!,
(Func<IQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink>, IIncludableQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink, object>>)null!,
false))
.ReturnsAsync(new List<Streetcode.DAL.Entities.Transactions.TransactionLink>());

var handler = new GetAllTransactLinksHandler(
_mockRepo.Object,
_mapper,
_mockLogger.Object);

Check warning on line 83 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76YI&open=AZyu4d7nTsceoUoQ76YI&pullRequest=116

var expectedError = Messages.Error_EntitiesNotFound.Format(
nameof(Streetcode.DAL.Entities.Transactions.TransactionLink));

// Act
var result = await handler.Handle(
query,
CancellationToken.None);

// Assert
result.IsFailed.Should().BeTrue();
result.Errors.Should().ContainSingle()
.Which.Message.Should().Be(expectedError);

_mockLogger.Verify(x => x.LogError(
query,
expectedError), Times.Once);
}

[Fact]
public async Task Handle_RepositoryReturnsNull_ReturnsFailure()
{
// Arrange
_mockRepo.Setup(r => r.TransactLinksRepository.GetAllAsync(

Check warning on line 107 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetAll/GetAllTransactLinksHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4d7nTsceoUoQ76YL&open=AZyu4d7nTsceoUoQ76YL&pullRequest=116
null,
null,
false))
.ReturnsAsync((IEnumerable<Streetcode.DAL.Entities.Transactions.TransactionLink>?)null);

var handler = new GetAllTransactLinksHandler(
_mockRepo.Object,
_mapper,
_mockLogger.Object);

var query = new GetAllTransactLinksQuery();

string expectedError = Messages.Error_EntitiesNotFound.Format(
nameof(Streetcode.DAL.Entities.Transactions.TransactionLink));

// Act
var result = await handler.Handle(
query,
CancellationToken.None);

// Assert
result.IsFailed.Should().BeTrue();
result.Errors.Should().ContainSingle()
.Which.Message.Should().Be(expectedError);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Linq.Expressions;
using AutoMapper;

Check warning on line 2 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YQ&open=AZyu4eC1TsceoUoQ76YQ&pullRequest=116
using FluentAssertions;

Check warning on line 3 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YR&open=AZyu4eC1TsceoUoQ76YR&pullRequest=116
using Microsoft.EntityFrameworkCore.Query;
using Moq;

Check warning on line 5 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YT&open=AZyu4eC1TsceoUoQ76YT&pullRequest=116
using Streetcode.BLL.DTO.Transactions;
using Streetcode.BLL.Interfaces.Logging;

Check warning on line 7 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YV&open=AZyu4eC1TsceoUoQ76YV&pullRequest=116
using Streetcode.BLL.Mapping.Transactions;

Check warning on line 8 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YW&open=AZyu4eC1TsceoUoQ76YW&pullRequest=116
using Streetcode.BLL.MediatR.Transactions.TransactionLink.GetById;

Check warning on line 9 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YX&open=AZyu4eC1TsceoUoQ76YX&pullRequest=116
using Streetcode.DAL.Entities.Transactions;
using Streetcode.DAL.Repositories.Interfaces.Base;

Check warning on line 11 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76YZ&open=AZyu4eC1TsceoUoQ76YZ&pullRequest=116
using Streetcode.Resources;

Check warning on line 12 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Ya&open=AZyu4eC1TsceoUoQ76Ya&pullRequest=116
using Streetcode.Shared.Extensions;

Check warning on line 13 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Yb&open=AZyu4eC1TsceoUoQ76Yb&pullRequest=116
using Xunit;

namespace Streetcode.XUnitTest.MediatR.Transactions.TransactionLink;

public class GetTransactLinkByIdHandlerTests
{
private readonly Mock<IRepositoryWrapper> _mockRepo;
private readonly Mock<ILoggerService> _mockLogger;

Check warning on line 21 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Field '_mockLogger' should not begin with an underscore

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Yd&open=AZyu4eC1TsceoUoQ76Yd&pullRequest=116
private readonly IMapper _mapper;

Check warning on line 22 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Field '_mapper' should not begin with an underscore

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Ye&open=AZyu4eC1TsceoUoQ76Ye&pullRequest=116

public GetTransactLinkByIdHandlerTests()
{
_mockRepo = new Mock<IRepositoryWrapper>();
_mockLogger = new Mock<ILoggerService>();

Check warning on line 27 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Yh&open=AZyu4eC1TsceoUoQ76Yh&pullRequest=116

var config = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new TransactionLinkProfile());
});
_mapper = new Mapper(config);

Check warning on line 33 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Yi&open=AZyu4eC1TsceoUoQ76Yi&pullRequest=116
}

[Fact]
public async Task Handle_LinkExists_ReturnsSuccessWithMappedDTO()
{
// Arrange
int testId = 1;
var link = new Streetcode.DAL.Entities.Transactions.TransactionLink
{
Id = testId,
Url = "https://streetcode.com/donate",
StreetcodeId = 10
};
var query = new GetTransactLinkByIdQuery(
testId);

_mockRepo.Setup(r => r.TransactLinksRepository.GetFirstOrDefaultAsync(
It.IsAny<Expression<Func<Streetcode.DAL.Entities.Transactions.TransactionLink, bool>>>(),
It.IsAny<Func<IQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink>, IIncludableQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink, object>>>(),
It.IsAny<bool>()))
.ReturnsAsync(link);

var handler = new GetTransactLinkByIdHandler(
_mockRepo.Object,
_mapper,
_mockLogger.Object);

// Act
var result = await handler.Handle(
query,
CancellationToken.None);

// Assert
result.IsSuccess.Should().BeTrue();
result.Value.Should().BeOfType<TransactLinkDTO>();
result.Value.Id.Should().Be(testId);
result.Value.Url.Should().Be("https://streetcode.com/donate");
}

[Fact]
public async Task Handle_LinkDoesNotExist_ReturnsFailureAndLogsError()
{
// Arrange
int testId = 99;
var query = new GetTransactLinkByIdQuery(
testId);

_mockRepo.Setup(r => r.TransactLinksRepository.GetFirstOrDefaultAsync(
It.IsAny<Expression<Func<Streetcode.DAL.Entities.Transactions.TransactionLink, bool>>>(),
null,
false))
.ReturnsAsync((Streetcode.DAL.Entities.Transactions.TransactionLink?)null);

var handler = new GetTransactLinkByIdHandler(
_mockRepo.Object,
_mapper,

Check warning on line 89 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Yr&open=AZyu4eC1TsceoUoQ76Yr&pullRequest=116
_mockLogger.Object);

Check warning on line 90 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetById/GetTransactLinkByIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC1TsceoUoQ76Ys&open=AZyu4eC1TsceoUoQ76Ys&pullRequest=116

var expectedError = Messages.Error_EntityWithIdNotFound.Format(
nameof(Streetcode.DAL.Entities.Transactions.TransactionLink),
testId);

// Act
var result = await handler.Handle(
query,
CancellationToken.None);

// Assert
result.IsFailed.Should().BeTrue();
result.Errors.Should().ContainSingle()
.Which.Message.Should().Be(expectedError);

_mockLogger.Verify(x => x.LogError(
query,
expectedError), Times.Once);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.Linq.Expressions;

Check warning on line 1 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Yv&open=AZyu4eC_TsceoUoQ76Yv&pullRequest=116
using AutoMapper;
using FluentAssertions;
using Microsoft.EntityFrameworkCore.Query;

Check warning on line 4 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Yy&open=AZyu4eC_TsceoUoQ76Yy&pullRequest=116
using Moq;

Check warning on line 5 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Yz&open=AZyu4eC_TsceoUoQ76Yz&pullRequest=116
using Streetcode.BLL.DTO.Transactions;
using Streetcode.BLL.Interfaces.Logging;

Check warning on line 7 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y1&open=AZyu4eC_TsceoUoQ76Y1&pullRequest=116
using Streetcode.BLL.Mapping.Transactions;

Check warning on line 8 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y2&open=AZyu4eC_TsceoUoQ76Y2&pullRequest=116
using Streetcode.BLL.MediatR.Transactions.TransactionLink.GetByStreetcodeId;

Check warning on line 9 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y3&open=AZyu4eC_TsceoUoQ76Y3&pullRequest=116
using Streetcode.DAL.Entities.Transactions;

Check warning on line 10 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y4&open=AZyu4eC_TsceoUoQ76Y4&pullRequest=116
using Streetcode.DAL.Repositories.Interfaces.Base;

Check warning on line 11 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y5&open=AZyu4eC_TsceoUoQ76Y5&pullRequest=116
using Streetcode.Resources;

Check warning on line 12 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y6&open=AZyu4eC_TsceoUoQ76Y6&pullRequest=116
using Streetcode.Shared.Extensions;

Check warning on line 13 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y7&open=AZyu4eC_TsceoUoQ76Y7&pullRequest=116
using Xunit;

Check warning on line 14 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Using directive should appear within a namespace declaration

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76Y8&open=AZyu4eC_TsceoUoQ76Y8&pullRequest=116

namespace Streetcode.XUnitTest.MediatR.Transactions.TransactionLink;

public class GetTransactLinkByStreetcodeIdHandlerTests
{
private readonly Mock<IRepositoryWrapper> _mockRepo;
private readonly Mock<ILoggerService> _mockLogger;
private readonly IMapper _mapper;

public GetTransactLinkByStreetcodeIdHandlerTests()
{
_mockRepo = new Mock<IRepositoryWrapper>();
_mockLogger = new Mock<ILoggerService>();

Check warning on line 27 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76ZB&open=AZyu4eC_TsceoUoQ76ZB&pullRequest=116

var config = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new TransactionLinkProfile());
});
_mapper = new Mapper(config);
}

[Fact]
public async Task Handle_LinkExists_ReturnsSuccessWithMappedDTO()
{
// Arrange
int streetcodeId = 5;
var link = new Streetcode.DAL.Entities.Transactions.TransactionLink
{
Id = 1,
StreetcodeId = streetcodeId,
Url = "https://streetcode.com/donate"
};
var query = new GetTransactLinkByStreetcodeIdQuery(
streetcodeId);

_mockRepo.Setup(r => r.TransactLinksRepository.GetFirstOrDefaultAsync(

Check warning on line 50 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76ZE&open=AZyu4eC_TsceoUoQ76ZE&pullRequest=116
It.IsAny<Expression<Func<Streetcode.DAL.Entities.Transactions.TransactionLink, bool>>>(),
It.IsAny<Func<IQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink>, IIncludableQueryable<Streetcode.DAL.Entities.Transactions.TransactionLink, object>>>(),
It.IsAny<bool>()))
.ReturnsAsync(link);

var handler = new GetTransactLinkByStreetcodeIdHandler(
_mockRepo.Object,
_mapper,

Check warning on line 58 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76ZG&open=AZyu4eC_TsceoUoQ76ZG&pullRequest=116
_mockLogger.Object);

Check warning on line 59 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76ZH&open=AZyu4eC_TsceoUoQ76ZH&pullRequest=116

// Act
var result = await handler.Handle(
query,
CancellationToken.None);

// Assert
result.IsSuccess.Should().BeTrue();
result.Value.Should().NotBeNull();
result.Value!.StreetcodeId.Should().Be(streetcodeId);
}

[Fact]
public async Task Handle_LinkDoesNotExist_ReturnsFailureAndLogsError()
{
// Arrange
int streetcodeId = 10;
var query = new GetTransactLinkByStreetcodeIdQuery(
streetcodeId);

_mockRepo.Setup(r => r.TransactLinksRepository.GetFirstOrDefaultAsync(
It.IsAny<Expression<Func<Streetcode.DAL.Entities.Transactions.TransactionLink, bool>>>(),
null,
false))
.ReturnsAsync((Streetcode.DAL.Entities.Transactions.TransactionLink?)null);

var handler = new GetTransactLinkByStreetcodeIdHandler(
_mockRepo.Object,

Check warning on line 87 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76ZJ&open=AZyu4eC_TsceoUoQ76ZJ&pullRequest=116
_mapper,

Check warning on line 88 in Streetcode/Streetcode.XUnitTest/MediatR/Transactions/TransactionLink/GetByStreetcodeId/GetTransactLinkByStreetcodeIdHandlerTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefix local calls with this

See more on https://sonarcloud.io/project/issues?id=project-studying-dotnet_Streetcode-Server-January-2026&issues=AZyu4eC_TsceoUoQ76ZK&open=AZyu4eC_TsceoUoQ76ZK&pullRequest=116
_mockLogger.Object);

var expectedError = Messages.Error_EntityWithStreetcodeIdNotFound.Format(
nameof(Streetcode.DAL.Entities.Transactions.TransactionLink),
streetcodeId);

// Act
var result = await handler.Handle(
query,
CancellationToken.None);

// Assert
result.IsFailed.Should().BeTrue();
result.Errors.Should().ContainSingle()
.Which.Message.Should().Be(expectedError);

_mockLogger.Verify(x => x.LogError(
query,
expectedError), Times.Once);
}
}
Loading