2020-12-25 10:48:04 +00:00
|
|
|
|
using System;
|
2020-11-26 17:30:57 +00:00
|
|
|
|
using System.Linq;
|
2020-12-25 10:48:04 +00:00
|
|
|
|
using System.Reflection;
|
2020-11-26 17:30:57 +00:00
|
|
|
|
using System.Text.Json;
|
2020-12-09 21:06:16 +00:00
|
|
|
|
using System.Threading;
|
2020-12-24 00:21:29 +00:00
|
|
|
|
|
2020-11-26 17:30:57 +00:00
|
|
|
|
using ASC.Common.Security.Authentication;
|
2020-09-16 13:19:08 +00:00
|
|
|
|
using ASC.Core;
|
2020-12-21 23:27:10 +00:00
|
|
|
|
using ASC.Core.Common.EF;
|
2020-12-24 00:21:29 +00:00
|
|
|
|
using ASC.Core.Common.EF.Context;
|
2020-09-16 13:19:08 +00:00
|
|
|
|
using ASC.Core.Tenants;
|
|
|
|
|
using ASC.Core.Users;
|
|
|
|
|
using ASC.Files.Helpers;
|
2020-09-23 14:49:15 +00:00
|
|
|
|
using ASC.Files.Model;
|
2020-09-18 13:26:30 +00:00
|
|
|
|
using ASC.Files.Tests.Infrastructure;
|
2020-09-16 13:19:08 +00:00
|
|
|
|
using ASC.Web.Files.Classes;
|
2020-12-01 14:09:50 +00:00
|
|
|
|
using ASC.Web.Files.Services.WCFService;
|
2020-11-26 17:30:57 +00:00
|
|
|
|
using ASC.Web.Files.Services.WCFService.FileOperations;
|
2020-12-25 10:48:04 +00:00
|
|
|
|
|
2020-12-21 23:27:10 +00:00
|
|
|
|
using Microsoft.AspNetCore.TestHost;
|
2020-12-24 00:21:29 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
2020-09-16 13:19:08 +00:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2020-12-21 23:27:10 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-11-26 17:30:57 +00:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2020-12-21 23:27:10 +00:00
|
|
|
|
|
2020-09-16 13:19:08 +00:00
|
|
|
|
namespace ASC.Files.Tests
|
|
|
|
|
{
|
2020-11-19 02:53:50 +00:00
|
|
|
|
public class BaseFilesTests
|
2020-09-16 13:19:08 +00:00
|
|
|
|
{
|
2020-11-19 02:53:50 +00:00
|
|
|
|
protected FilesControllerHelper<int> FilesControllerHelper { get; set; }
|
2020-12-21 23:27:10 +00:00
|
|
|
|
protected TestServer TestServer { get; set; }
|
|
|
|
|
|
|
|
|
|
public BaseDbContext baseDbContext;
|
|
|
|
|
|
|
|
|
|
|
2020-12-01 14:09:50 +00:00
|
|
|
|
protected GlobalFolderHelper GlobalFolderHelper { get; set; }
|
|
|
|
|
protected FileStorageService<int> FileStorageService { get; set; }
|
2020-09-17 14:56:51 +00:00
|
|
|
|
protected UserManager UserManager { get; set; }
|
2020-09-16 13:19:08 +00:00
|
|
|
|
protected Tenant CurrentTenant { get; set; }
|
|
|
|
|
protected UserInfo User { get; set; }
|
|
|
|
|
protected SecurityContext SecurityContext { get; set; }
|
2020-09-18 13:26:30 +00:00
|
|
|
|
protected UserOptions UserOptions { get; set; }
|
2020-09-16 13:19:08 +00:00
|
|
|
|
protected IAccount Account { get; set; }
|
2020-12-24 00:21:29 +00:00
|
|
|
|
protected IConfiguration Configuration { get; set; }
|
|
|
|
|
protected IServiceScope scope { get; set; }
|
|
|
|
|
|
|
|
|
|
const string con = "Server=localhost;Database=onlyoffice_test;User ID = root; Password=root;Pooling=true;";
|
2020-09-16 13:19:08 +00:00
|
|
|
|
public virtual void SetUp()
|
|
|
|
|
{
|
2020-12-25 10:48:04 +00:00
|
|
|
|
var host = Program.CreateHostBuilder(new string[] {
|
|
|
|
|
"--pathToConf" ,"..\\..\\..\\..\\..\\..\\config",
|
|
|
|
|
"--ConnectionStrings:default:connectionString", con,
|
|
|
|
|
"--migration:enabled", "true" }).Build();
|
|
|
|
|
|
|
|
|
|
Migrate(host.Services);
|
|
|
|
|
|
|
|
|
|
scope = host.Services.CreateScope();
|
|
|
|
|
|
2020-11-12 03:55:14 +00:00
|
|
|
|
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
|
|
|
|
|
var tenant = tenantManager.GetTenant(1);
|
|
|
|
|
tenantManager.SetCurrentTenant(tenant);
|
|
|
|
|
CurrentTenant = tenant;
|
|
|
|
|
|
2020-11-19 02:53:50 +00:00
|
|
|
|
FilesControllerHelper = scope.ServiceProvider.GetService<FilesControllerHelper<int>>();
|
2020-11-12 03:55:14 +00:00
|
|
|
|
GlobalFolderHelper = scope.ServiceProvider.GetService<GlobalFolderHelper>();
|
|
|
|
|
UserManager = scope.ServiceProvider.GetService<UserManager>();
|
|
|
|
|
SecurityContext = scope.ServiceProvider.GetService<SecurityContext>();
|
|
|
|
|
UserOptions = scope.ServiceProvider.GetService<IOptions<UserOptions>>().Value;
|
2020-12-01 14:09:50 +00:00
|
|
|
|
FileStorageService = scope.ServiceProvider.GetService<FileStorageService<int>>();
|
2020-12-24 00:21:29 +00:00
|
|
|
|
|
|
|
|
|
|
2020-12-25 10:48:04 +00:00
|
|
|
|
SecurityContext.AuthenticateMe(CurrentTenant.OwnerId);
|
2020-12-21 23:27:10 +00:00
|
|
|
|
}
|
2020-12-25 10:48:04 +00:00
|
|
|
|
|
2020-12-09 21:06:16 +00:00
|
|
|
|
public void DeleteFolder(int folder, bool deleteAfter, bool DeleteEmmediatly)
|
|
|
|
|
{
|
|
|
|
|
FilesControllerHelper.DeleteFolder(folder, deleteAfter, DeleteEmmediatly);
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var statuses = FileStorageService.GetTasksStatuses();
|
|
|
|
|
|
|
|
|
|
if (statuses.TrueForAll(r => r.Finished))
|
|
|
|
|
break;
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void DeleteFile(int file, bool deleteAfter, bool DeleteEmmediatly)
|
|
|
|
|
{
|
|
|
|
|
FilesControllerHelper.DeleteFile(file, deleteAfter, DeleteEmmediatly);
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var statuses = FileStorageService.GetTasksStatuses();
|
|
|
|
|
|
|
|
|
|
if (statuses.TrueForAll(r => r.Finished))
|
|
|
|
|
break;
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-16 13:19:08 +00:00
|
|
|
|
|
2020-09-23 14:49:15 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2020-12-21 23:27:10 +00:00
|
|
|
|
|
2020-09-16 13:19:08 +00:00
|
|
|
|
public virtual void TearDown()
|
2020-12-21 23:27:10 +00:00
|
|
|
|
{
|
2020-12-25 10:48:04 +00:00
|
|
|
|
var context = scope.ServiceProvider.GetService<DbContextManager<TenantDbContext>>();
|
|
|
|
|
context.Value.Database.EnsureDeleted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Migrate(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
using var scope = serviceProvider.CreateScope();
|
|
|
|
|
|
|
|
|
|
var configuration = scope.ServiceProvider.GetService<IConfiguration>();
|
|
|
|
|
|
|
|
|
|
TenantMigrate();
|
|
|
|
|
|
|
|
|
|
configuration["testAssembly"] = Assembly.GetExecutingAssembly().GetName().Name;
|
|
|
|
|
TenantMigrate();
|
|
|
|
|
configuration["testAssembly"] = "";
|
|
|
|
|
|
|
|
|
|
void TenantMigrate()
|
|
|
|
|
{
|
|
|
|
|
using (var db = scope.ServiceProvider.GetService<DbContextManager<TenantDbContext>>())
|
|
|
|
|
{
|
|
|
|
|
db.Value.Migrate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-16 13:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|