ASC.Files.Tests: adding a FilesControllersHelperString

This commit is contained in:
maksim 2020-09-23 17:49:15 +03:00
parent 62c1ed21b9
commit 2c53e71fbc
3 changed files with 231 additions and 4 deletions

View File

@ -3,8 +3,10 @@ using ASC.Core;
using ASC.Core.Tenants;
using ASC.Core.Users;
using ASC.Files.Helpers;
using ASC.Files.Model;
using ASC.Files.Tests.Infrastructure;
using ASC.Web.Files.Classes;
using ASC.Web.Files.Services.WCFService.FileOperations;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
@ -14,6 +16,8 @@ using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
namespace ASC.Files.Tests
{
@ -96,7 +100,8 @@ namespace ASC.Files.Tests
private Tenant SetAndGetCurrentTenant()
{
var tenantManager = TestServer.Services.GetService<TenantManager>();
tenantManager.SetCurrentTenant(UserOptions.TenantId);
var tenant = tenantManager.GetTenant(1);
tenantManager.SetCurrentTenant(tenant);
return tenantManager.CurrentTenant;
}
@ -104,7 +109,6 @@ namespace ASC.Files.Tests
private UserInfo GetUser()
{
var user = UserManager.GetUsers(UserOptions.Id);
return user;
}
@ -113,6 +117,28 @@ namespace ASC.Files.Tests
return new Account(User.ID, "maks", true);
}
public BatchModel GetBatchModel(string text)
{
var json = text;
var jsonDocument = JsonDocument.Parse(json);
var root = jsonDocument.RootElement;
var folderIds = root[0].GetProperty("folderIds").EnumerateArray().ToList();
var fileIds = root[1].GetProperty("fileIds").EnumerateArray().ToList();
var destFolderdId = root[2];
var batchModel = new BatchModel
{
FolderIds = folderIds,
FileIds = fileIds,
DestFolderId = destFolderdId,
DeleteAfter = false,
ConflictResolveType = FileConflictResolveType.Overwrite
};
return batchModel;
}
public virtual void TearDown()
{
TestServer.Dispose();

View File

@ -78,7 +78,6 @@ namespace ASC.Files.Tests
DocumentsOptions.FolderOptions.DeleteItems.Immediately);
FileOperationWraper status = null;
foreach (var item in statuses)
{
if (item.OperationType == FileOperationType.Delete)
@ -136,7 +135,6 @@ namespace ASC.Files.Tests
DocumentsOptions.FileOptions.DeleteItems.Immediately);
FileOperationWraper status = null;
foreach (var item in statuses)
{
if (item.OperationType == FileOperationType.Delete)
@ -150,6 +148,52 @@ namespace ASC.Files.Tests
Assert.AreEqual(statusDelete, status.OperationType);
}
[Test]
[Category("section 'My Documents'")]
public void MoveBatchItemsReturnsOperationMoveTest()
{
var json = " [ { \"folderIds\": [ 1, 2, 3 ] }, { \"fileIds\": [ 1 , 2 ] }, { \"destFolderId\": 4 } ]";
var batchModel = GetBatchModel(json);
var statuses = FilesControllerHelper.MoveBatchItems(batchModel);
FileOperationWraper status = null;
foreach (var item in statuses)
{
if (item.OperationType == FileOperationType.Move)
{
status = item;
}
}
var statusMove = FileOperationType.Move;
Assert.IsNotNull(status);
Assert.AreEqual(statusMove, status.OperationType);
}
[Test]
[Category("section 'My Documents'")]
public void CopyBatchItemsReturnsOperationCopyTest()
{
var json = " [ { \"folderIds\": [ 6 ] }, { \"fileIds\": [ 4 , 5 ] }, { \"destFolderId\": 5 } ]";
var batchModel = GetBatchModel(json);
var statuses = FilesControllerHelper.CopyBatchItems(batchModel);
FileOperationWraper status = null;
foreach (var item in statuses)
{
if (item.OperationType == FileOperationType.Copy)
{
status = item;
}
}
var statusCopy = FileOperationType.Copy;
Assert.IsNotNull(status);
Assert.AreEqual(statusCopy, status.OperationType);
}
[TearDown]
public override void TearDown()
{

View File

@ -0,0 +1,157 @@
using ASC.Api.Documents;
using ASC.Files.Core;
using ASC.Files.Tests.Infrastructure;
using ASC.Web.Files.Services.WCFService.FileOperations;
using NUnit.Framework;
namespace ASC.Files.Tests
{
[TestFixture]
public class FilesControllerHelperStringTests : BaseFilesTests<string>
{
[SetUp]
public override void SetUp()
{
base.SetUp();
}
[Test]
[Category("section 'My Documents'")]
public void CreateFolderReturnsFolderWrapperTest()
{
var folderWrapperOne = FilesControllerHelper.CreateFolder(GlobalFolderHelper.FolderMy.ToString(), DocumentsOptions.FolderOptions.CreateItems.TitleOne);
var folderWrapperTwo = FilesControllerHelper.CreateFolder(GlobalFolderHelper.FolderMy.ToString(), DocumentsOptions.FolderOptions.CreateItems.TitleTwo);
Assert.IsNotNull(folderWrapperOne);
Assert.IsNotNull(folderWrapperTwo);
Assert.AreEqual("FolderOne", folderWrapperOne.Title);
Assert.AreEqual("FolderTwo", folderWrapperTwo.Title);
}
[Test]
[Category("section 'My Documents'")]
public void GetFolderReturnsFolderContentWrapperTest()
{
var folderContentWrapper = FilesControllerHelper.GetFolder(
DocumentsOptions.FolderOptions.GetItems.Id.ToString(),
UserOptions.Id,
FilterType.None,
DocumentsOptions.FolderOptions.GetItems.WithSubFolders);
var filesCount = folderContentWrapper.Files.Count;
var foldersCount = folderContentWrapper.Folders.Count;
Assert.IsNotNull(folderContentWrapper);
Assert.AreEqual(0, filesCount);
Assert.AreEqual(0, foldersCount);
}
[Test]
[Category("section 'My Documents'")]
public void GetFolderInfoReturnsFolderWrapperTest()
{
var folderWrapper = FilesControllerHelper.GetFolderInfo(DocumentsOptions.FolderOptions.GetInfoItems.id.ToString());
Assert.IsNotNull(folderWrapper);
Assert.AreEqual(DocumentsOptions.FolderOptions.GetInfoItems.TitleExpected, folderWrapper.Title);
}
[Test]
[Category("section 'My Documents'")]
public void RenameFolderReturnsFolderWrapperTest()
{
var folderWrapper = FilesControllerHelper.RenameFolder(
DocumentsOptions.FolderOptions.RenameItems.Id.ToString(),
DocumentsOptions.FolderOptions.RenameItems.Title);
Assert.IsNotNull(folderWrapper);
Assert.AreEqual(DocumentsOptions.FolderOptions.RenameItems.Title, folderWrapper.Title);
}
[Test]
[Category("section 'My Documents'")]
public void DeleteFolderTest()
{
var statuses = FilesControllerHelper.DeleteFolder(
DocumentsOptions.FolderOptions.DeleteItems.Id.ToString(),
DocumentsOptions.FolderOptions.DeleteItems.DeleteAfter,
DocumentsOptions.FolderOptions.DeleteItems.Immediately);
FileOperationWraper status = null;
foreach (var item in statuses)
{
if (item.OperationType == FileOperationType.Delete)
{
status = item;
}
}
var statusDelete = FileOperationType.Delete;
Assert.IsNotNull(status);
Assert.AreEqual(statusDelete, status.OperationType);
}
[Test]
public void CreateFileReturnsFileWrapperTest()
{
var fileWrapperOne = FilesControllerHelper.CreateFile(GlobalFolderHelper.FolderMy.ToString(), DocumentsOptions.FileOptions.CreateItems.TitleOne);
var fileWrapperTwo = FilesControllerHelper.CreateFile(GlobalFolderHelper.FolderMy.ToString(), DocumentsOptions.FileOptions.CreateItems.TitleTwo);
Assert.IsNotNull(fileWrapperOne);
Assert.IsNotNull(fileWrapperTwo);
Assert.AreEqual("FileOne", fileWrapperOne.Title);
Assert.AreEqual("FileTwo", fileWrapperTwo.Title);
}
[Test]
[Category("section 'My Documents'")]
public void GetFileInfoReturnsFilesWrapperTest()
{
var fileWrapper = FilesControllerHelper.GetFileInfo(DocumentsOptions.FileOptions.GetInfoItems.id.ToString());
Assert.IsNotNull(fileWrapper);
Assert.AreEqual(DocumentsOptions.FileOptions.GetInfoItems.TitleExpected, fileWrapper.Title);
}
[Test]
public void UpdateFileReturnsFileWrapperTest()
{
var fileWrapper = FilesControllerHelper.UpdateFile(
DocumentsOptions.FileOptions.UpdateItems.Id.ToString(),
DocumentsOptions.FileOptions.UpdateItems.Title,
DocumentsOptions.FileOptions.UpdateItems.LastVersion);
Assert.IsNotNull(fileWrapper);
Assert.AreEqual(DocumentsOptions.FileOptions.UpdateItems.Title, fileWrapper.Title);
}
[Test]
[Category("section 'My Documents'")]
public void DeleteFileTest()
{
var statuses = FilesControllerHelper.DeleteFile(
DocumentsOptions.FileOptions.DeleteItems.Id.ToString(),
DocumentsOptions.FileOptions.DeleteItems.DeleteAfter,
DocumentsOptions.FileOptions.DeleteItems.Immediately);
FileOperationWraper status = null;
foreach (var item in statuses)
{
if (item.OperationType == FileOperationType.Delete)
{
status = item;
}
}
var statusDelete = FileOperationType.Delete;
Assert.IsNotNull(status);
Assert.AreEqual(statusDelete, status.OperationType);
}
[TearDown]
public override void TearDown()
{
base.TearDown();
}
}
}