Skip to content

Commit

Permalink
add test and edit readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Gramli committed Jun 18, 2024
1 parent a340e8e commit 87ecc0e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ REST API solution demonstrates how to create clean and modern API with Clean Arc

Example API allows to **upload/download files with .txt, .json, .csv, .xml, .yml extensions** and get collection of uploaded files. Also allow to **convert between json, xml, yml formats**.

Two methods for downloading files are demonstrated:
* Using the **GetFileAsync** extension method, which returns the file as a byte array.
* Using the **GetJsonFileAsync** method, which returns the file inside a JSON object. The file is converted to a Base64 string to preserve encoding.

# Menu
* [Get Started](#get-started)
* [Motivation](#motivation)
Expand Down
2 changes: 1 addition & 1 deletion src/File.Domain/Commands/AddFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace File.Domain.Commands
{
public sealed class AddFilesCommand
{
public IEnumerable<IFile> Files { get; init; } = Enumerable.Empty<IFile>();
public IEnumerable<IFile> Files { get; init; } = [];

public AddFilesCommand(IEnumerable<IFile> files)
{
Expand Down
2 changes: 1 addition & 1 deletion src/File.Domain/Http/DataResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class DataResponse<T>
{
public T? Data { get; init; }

public IList<string> Errors { get; init; } = new List<string>();
public IList<string> Errors { get; init; } = [];
}
}
2 changes: 1 addition & 1 deletion src/File.Domain/Options/AllowedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public sealed class AllowedFile

public string ContentType { get; set; } = string.Empty;

public string[] CanBeExportedTo { get; set; } = new string[0];
public string[] CanBeExportedTo { get; set; } = [];
}
}
25 changes: 25 additions & 0 deletions src/Tests/SystemTests/File.API.SystemTests/Tests/DownloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using File.API.SystemTests.Extensions;
using File.Domain.Dtos;
using File.Domain.Http;
using System.Net.Http.Json;

namespace File.API.SystemTests.Tests
{
Expand Down Expand Up @@ -29,5 +30,29 @@ public async Task DownloadFileAsync()
//Assert
Assert.True(stream.Length > 0);
}

[Fact]
public async Task DownloadJsonFileAsync()
{
//Arrange
using var uploadResponse = (await _httpClient.UploadAssetsFile("new.json"))
.EnsureSuccessStatusCode();

using var fileInfo = await _httpClient.GetAsync("file/v1/files-info");
var fileToDownload = (await fileInfo.GetResponseData<DataResponse<IEnumerable<FileInfoDto>>>())?.Data?.First();

if (fileToDownload is null)
{
Assert.Fail("Downloaded file is empty.");
}

//Act
using var response = await _httpClient.GetAsync($"file/v1/downloadAsJson/?id={fileToDownload.Id}");
var responseFile = await response.Content.ReadFromJsonAsync<DataResponse<StringContentFileDto>>();

//Assert
Assert.True(responseFile!.Data!.Data.Length > 0);
Assert.NotEmpty(responseFile!.Data!.FileName);
}
}
}

0 comments on commit 87ecc0e

Please sign in to comment.