Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
93932c7
add integration tests project
Oct 16, 2023
d9047f1
add client
Sanyyazzz Oct 16, 2023
ed83afd
add test controller and controller tests
Oct 16, 2023
494e7f1
Merge remote-tracking branch 'origin/oleksandr/storage-client' into i…
Oct 16, 2023
354c206
fix
Sanyyazzz Oct 17, 2023
16fd4a5
Merge remote-tracking branch 'origin/oleksandr/storage-client' into c…
Oct 17, 2023
c7b437b
add IStorageClient
Sanyyazzz Oct 17, 2023
3a2c76b
fix storage client
Oct 17, 2023
11f21a9
Merge branch 'integration_tests_project' into oleksandr/storage-client
Sanyyazzz Oct 17, 2023
696a0d6
accept file and content names in client method
Oct 17, 2023
5d7c7e5
Merge remote-tracking branch 'origin/oleksandr/storage-client' into i…
Oct 17, 2023
d239725
add content name property
Oct 17, 2023
9d3185a
return status code when request is failed
Oct 17, 2023
d44f23f
add test for file upload from file info
Oct 17, 2023
1e78e9d
move tests
Oct 17, 2023
8c4d06c
add tests for upload methods with azure
Oct 17, 2023
325ec71
fix tests
Oct 17, 2023
b4b94fd
return downloaded file as stream
Oct 17, 2023
d7e350f
return localFile from download method
Oct 18, 2023
c97748c
return result on download
Oct 18, 2023
29bd582
add base test classes for controller tests
Oct 18, 2023
1fc5cf0
use another controller for base controller
Oct 18, 2023
b2e741c
Merge branch 'develop' into integration_tests_project
Oct 18, 2023
711dbea
use another method for crc calculation
Oct 18, 2023
06801f0
Merge branch 'develop' into integration_tests_project
Oct 18, 2023
1bdf15c
remove duplicated controller
Oct 18, 2023
6ac54c1
remove local folder path and replace it with path from method
Oct 18, 2023
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
27 changes: 27 additions & 0 deletions ManagedCode.Storage.IntegrationTests/Helpers/Crc32Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,31 @@ public static uint Calculate(byte[] bytes)
}
return ~crcValue;
}

public static uint CalculateFileCRC(string filePath)
{
uint crcValue = 0xffffffff;

using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[4096]; // 4KB buffer
int bytesRead;
while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
crcValue = Calculate(buffer, crcValue);
}
}

return ~crcValue; // Return the final CRC value
}

public static uint Calculate(byte[] bytes, uint crcValue = 0xffffffff)
{
foreach (byte by in bytes)
{
byte tableIndex = (byte)(((crcValue) & 0xff) ^ by);
crcValue = Crc32Table[tableIndex] ^ (crcValue >> 8);
}
return crcValue;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal;
using ManagedCode.Communication;
using ManagedCode.Storage.Core;
using ManagedCode.Storage.Core.Models;
Expand All @@ -9,18 +9,18 @@
namespace ManagedCode.Storage.IntegrationTests.TestApp.Controllers.Base;

[ApiController]
public abstract class BaseTestController<TStorage> : BaseController
public abstract class BaseTestController<TStorage> : ControllerBase
where TStorage : IStorage
{
private readonly ResponseContext _responseData;
private readonly int chunkSize;
private readonly string tempFolder;
protected readonly IStorage Storage;
protected readonly ResponseContext ResponseData;
protected readonly int ChunkSize;

protected BaseTestController(TStorage storage) : base(storage)
protected BaseTestController(TStorage storage)
{
_responseData = new ResponseContext();
chunkSize = 100000000;
tempFolder = "C:\\Users\\sasha";
Storage = storage;
ResponseData = new ResponseContext();
ChunkSize = 100000000;
}

[HttpPost("upload")]
Expand Down Expand Up @@ -55,11 +55,11 @@ public async Task<IActionResult> UploadChunks(CancellationToken cancellationToke
try
{
var chunkNumber = Guid.NewGuid().ToString();
string newpath = Path.Combine(tempFolder + "/TEMP", "file" + chunkNumber);
string newpath = Path.Combine(Path.GetTempPath(), "file" + chunkNumber);

await using (FileStream fs = System.IO.File.Create(newpath))
{
byte[] bytes = new byte[chunkSize];
byte[] bytes = new byte[ChunkSize];
int bytesRead = 0;
while ((bytesRead = await Request.Body.ReadAsync(bytes, 0, bytes.Length, cancellationToken)) > 0)
{
Expand All @@ -73,15 +73,15 @@ public async Task<IActionResult> UploadChunks(CancellationToken cancellationToke
// _responseData.IsSuccess = false;
}

return Ok(_responseData);
return Ok(ResponseData);
}

[HttpPost("upload-chunks/complete")]
public async Task<Result> UploadComplete([FromBody] string fileName)
{
try
{
string tempPath = tempFolder + "/TEMP";
string tempPath = Path.GetTempPath();
string newPath = Path.Combine(tempPath, fileName);
// string[] filePaths = Directory.GetFiles(tempPath).Where(p => p.Contains(fileName))
// .OrderBy(p => Int32.Parse(p.Replace(fileName, "$").Split('$')[1])).ToArray();
Expand All @@ -91,7 +91,7 @@ public async Task<Result> UploadComplete([FromBody] string fileName)
MergeChunks(newPath, filePath);
}

System.IO.File.Move(Path.Combine(tempPath, fileName), Path.Combine(tempFolder, fileName));
System.IO.File.Move(Path.Combine(tempPath, fileName), Path.Combine(tempPath, fileName));
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task DownloadFile_WhenFileExists_SaveToTempStorage_ReturnSuccess()
// Assert
downloadedFileResult.IsSuccess.Should().BeTrue();
downloadedFileResult.Value.Should().NotBeNull();
var downloadedFileCRC = Crc32Helper.Calculate(await downloadedFileResult.Value.ReadAllBytesAsync());
var downloadedFileCRC = Crc32Helper.CalculateFileCRC(downloadedFileResult.Value.FilePath);
downloadedFileCRC.Should().Be(fileCRC);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task UploadFileInChunks_WhenFileValid_ReturnSuccess()
var contentName = "file";

await using var localFile = LocalFile.FromRandomNameWithExtension(".txt");
FileHelper.GenerateLocalFile(localFile, 500);
FileHelper.GenerateLocalFile(localFile, 20);

// Act
var result = await storageClient.UploadFileInChunks(localFile.FileStream, _uploadChunksEndpoint, 100000000);
Expand Down