Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update legacy manifest file test #605

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 22 additions & 4 deletions tests/Altinn.Broker.Tests/LegacyFileControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Http.Headers;
using System.Net.Http.Json;
Expand Down Expand Up @@ -559,13 +559,31 @@ private async Task UploadFile(string fileTransferId)
}

private async Task<long> UploadZipFile(string fileTransferId) {
var fileBuffer = File.ReadAllBytes("Data/ManifestFileTests/Payload.zip");
using (var content = new ByteArrayContent(fileBuffer))
var payloadFile = await GenerateDummyFile(10240);
using var zipStream = new MemoryStream();
using (var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
{
var zippedFile = zipArchive.CreateEntry("payload.txt");
using (var zippedFileStream = zippedFile.Open())
{
await zippedFileStream.WriteAsync(payloadFile);
}
}
zipStream.Position = 0;
var zipBytes = zipStream.ToArray();
using (var content = new ByteArrayContent(zipStream.ToArray()))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
var uploadResponse = await _senderClient.PostAsync($"broker/api/v1/filetransfer/{fileTransferId}/upload", content);
Assert.True(uploadResponse.IsSuccessStatusCode, await uploadResponse.Content.ReadAsStringAsync());
}
return fileBuffer.Length;
return zipStream.Length;
}

private async Task<byte[]> GenerateDummyFile(long bytes)
{
var fileBuffer = new byte[bytes];
new Random().NextBytes(fileBuffer);
return fileBuffer;
}
}
Loading