Skip to content

Commit

Permalink
Remove logging. Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Edwards committed Oct 5, 2024
1 parent e0fa79f commit b6585f5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Unit = EasyMonads.Unit;

Expand All @@ -63,23 +62,19 @@ internal class SaveMultipartFileTransferCommandHandler
private readonly IPublisher _publisher;
private readonly ITransferRepository _transferRepository;
private readonly TransferStorageSettings _transferStorageSettings;
private readonly ILogger<SaveMultipartFileTransferCommandHandler> _logger;

public SaveMultipartFileTransferCommandHandler(
DataContext dataContext,
IHashIdService hashIdService,
IPublisher publisher,
ITransferRepository transferRepository,
IOptions<TransferStorageSettings> transferStorageSettings,
ILogger<SaveMultipartFileTransferCommandHandler> logger)
IOptions<TransferStorageSettings> transferStorageSettings)
{
_dataContext = dataContext;
_hashIdService = hashIdService;
_publisher = publisher;
_transferRepository = transferRepository;
_transferStorageSettings = transferStorageSettings.Value;

_logger = logger;
}

public async Task<Either<UploadMultipartFileTransferError, Unit>> Handle(SaveMultipartFileTransferCommand request,
Expand Down Expand Up @@ -144,8 +139,6 @@ private async Task<Either<UploadMultipartFileTransferError, ValidRequestData>> V
long maximumTransferSize = Convert.ToInt64(_transferStorageSettings.MaximumTransferSizeMB * Math.Pow(10, 6));
long updatedTransferSize = _transferRepository.GetTransferPartsSize(itemId.Value, TransferItemType.File, TransferUserType.User)
+ request.CiphertextStream.Length;

_logger.LogError(updatedTransferSize.ToString());

if (updatedTransferSize > maximumTransferSize)
{
Expand Down
10 changes: 1 addition & 9 deletions Crypter.Core/Repositories/TransferRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,13 @@ public long GetTransferPartsSize(Guid id, TransferItemType itemType, TransferUse
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
if (directoryInfo.Exists)
{
foreach (var foo in directoryInfo.EnumerateFiles())
{
_logger.LogError($"Logging file attributes: {foo.Name}, {foo.Length}");
}

long partSize = directoryInfo
return directoryInfo
.EnumerateFiles()
.Select(x => x.Length)
.DefaultIfEmpty(0)
.Sum(x => Convert.ToInt64(x / Math.Pow(10, 6)));
_logger.LogError($"Part size: {partSize}");
return partSize;
}

_logger.LogError("Directory not found");
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void TearDown()
[TestCase(TransferUserType.User)]
public async Task Files_Can_Be_Saved_And_Read_Async(TransferUserType userType)
{
byte[] buffer = new byte[] { 0x01, 0x02, 0x03, 0x04 };
byte[] buffer = [0x01, 0x02, 0x03, 0x04];
Guid itemGuid = Guid.NewGuid();
MemoryStream memoryStream = new MemoryStream(buffer);
bool saveSuccess = await _sut!.SaveTransferAsync(itemGuid, TransferItemType.File, userType, memoryStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ public async Task Upload_Multipart_File_Transfer_Fails_When_Aggregate_Becomes_To
for (int i = 0; i < 9; i++)
{
Either<UploadMultipartFileTransferError, Unit> response =
await _client!.FileTransfer.UploadMultipartFileTransferAsync(hashId, 0, RandomByteStreamOpener());
await _client!.FileTransfer.UploadMultipartFileTransferAsync(hashId, i, RandomByteStreamOpener());
Assert.That(response.IsRight, Is.True);
}

{
Either<UploadMultipartFileTransferError, Unit> response =
await _client!.FileTransfer.UploadMultipartFileTransferAsync(hashId, 0, RandomByteStreamOpener());
await _client!.FileTransfer.UploadMultipartFileTransferAsync(hashId, 10, RandomByteStreamOpener());
Assert.That(response.IsLeft, Is.True);

response.DoLeftOrNeither(
Expand Down

0 comments on commit b6585f5

Please sign in to comment.