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

added SaveFileAsyncShouldReturnGuidWhenFileCreated #12

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion UnitTests/FileTests/FileServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,35 @@ public async Task SaveAsyncShouldThrowWhenDataIsNull()
await Assert.ThrowsAsync<ArgumentNullException>(task);
}

[Fact]
public async Task SaveFileAsyncShouldReturnGuidWhenFileCreated()
{
var fileService = serviceProvider.GetRequiredService<IFileService>();

// given
var guid = Guid.NewGuid().ToString();
var stringData = "Hello world ";
var byteData = Encoding.ASCII.GetBytes(stringData);

var file = new Cambridge.Test.File.File(
type: EFileType.Document,
filename: guid,
extension: EAllowedExtension.txt,
data: byteData);

// when
var fileId = await fileService.SaveAsync(file, CancellationToken.None);
var existingFilename = $"{fileId}.{file.Extension}";
var result = await fileService.ExistsAsync(existingFilename);
golibjon0226 marked this conversation as resolved.
Show resolved Hide resolved

//should
Assert.True(Guid.TryParse(fileId.ToString(), out Guid guidResult));
golibjon0226 marked this conversation as resolved.
Show resolved Hide resolved
Assert.True(result, "Newly create should exist.");
}

public void Dispose()
{
if(Directory.Exists(PUBLIC_FOLDER))
if (Directory.Exists(PUBLIC_FOLDER))
Directory.Delete(PUBLIC_FOLDER, true);
}
}
Expand Down