DocSpace-buildtools/products/ASC.Files/Tests/Trash.cs

78 lines
2.6 KiB
C#
Raw Normal View History

using System;
2021-06-29 09:47:32 +00:00
using System.Collections.Generic;
2022-02-23 10:42:14 +00:00
using System.Threading.Tasks;
2020-12-29 16:45:18 +00:00
2022-03-18 15:44:00 +00:00
using ASC.Files.Core.ApiModels.ResponseDto;
2020-12-29 16:45:18 +00:00
using ASC.Web.Files.Services.WCFService.FileOperations;
using NUnit.Framework;
namespace ASC.Files.Tests
{
[TestFixture]
2022-02-23 10:42:14 +00:00
class Trash : BaseFilesTests
{
2022-03-18 15:44:00 +00:00
private FolderDto<int> TestFolder { get; set; }
public FileDto<int> TestFile { get; private set; }
[OneTimeSetUp]
2022-02-23 10:42:14 +00:00
public override async Task SetUp()
{
2022-02-23 10:42:14 +00:00
await base.SetUp();
2022-03-18 15:44:00 +00:00
TestFolder = await FoldersControllerHelper.CreateFolderAsync(GlobalFolderHelper.FolderMy, "TestFolder");
2022-02-23 10:42:14 +00:00
TestFile = await FilesControllerHelper.CreateFileAsync(GlobalFolderHelper.FolderMy, "TestFile", default);
}
[OneTimeSetUp]
public void Authenticate()
{
SecurityContext.AuthenticateMe(CurrentTenant.OwnerId);
}
[OneTimeTearDown]
2022-02-23 10:42:14 +00:00
public async Task TearDown()
{
2022-02-23 10:42:14 +00:00
await DeleteFileAsync(TestFile.Id);
await DeleteFolderAsync(TestFolder.Id);
}
[TestCaseSource(typeof(DocumentData), nameof(DocumentData.GetCreateFolderItems))]
[Category("Folder")]
[Order(1)]
public void CreateFolderReturnsFolderWrapper(string folderTitle)
{
2022-03-18 15:44:00 +00:00
var folderWrapper = Assert.ThrowsAsync<InvalidOperationException>(async () => await FoldersControllerHelper.CreateFolderAsync((int)GlobalFolderHelper.FolderTrash, folderTitle));
Assert.That(folderWrapper.Message == "You don't have enough permission to create");
}
[TestCaseSource(typeof(DocumentData), nameof(DocumentData.GetCreateFileItems))]
[Category("File")]
[Order(2)]
2022-02-23 10:42:14 +00:00
public async Task CreateFileReturnsFolderWrapper(string fileTitle)
{
2022-02-23 10:42:14 +00:00
var fileWrapper = await FilesControllerHelper.CreateFileAsync((int)GlobalFolderHelper.FolderTrash, fileTitle, default);
2020-12-15 11:08:07 +00:00
Assert.AreEqual(fileWrapper.FolderId, GlobalFolderHelper.FolderMy);
}
[Test]
[Category("Folder")]
[Order(2)]
2022-02-23 10:42:14 +00:00
public async Task DeleteFileFromTrash()
{
2022-03-18 15:44:00 +00:00
var Empty = await OperationControllerHelper.EmptyTrashAsync();
2021-06-29 09:47:32 +00:00
List<FileOperationResult> statuses;
while (true)
{
statuses = FileStorageService.GetTasksStatuses();
if (statuses.TrueForAll(r => r.Finished))
break;
2022-02-23 10:42:14 +00:00
await Task.Delay(100);
}
Assert.IsTrue(statuses.TrueForAll(r => string.IsNullOrEmpty(r.Error)));
}
}
}