2020-11-26 17:30:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-21 23:27:10 +00:00
|
|
|
|
using System.Data.Entity;
|
2020-11-26 17:30:57 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.Json;
|
2020-12-09 21:06:16 +00:00
|
|
|
|
using System.Threading;
|
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-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-09-16 13:19:08 +00:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-12-21 23:27:10 +00:00
|
|
|
|
using Microsoft.AspNetCore.TestHost;
|
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-09-24 08:49:41 +00:00
|
|
|
|
protected IConfiguration Configuration { get; set; }
|
2020-12-21 23:27:10 +00:00
|
|
|
|
|
2020-09-16 13:19:08 +00:00
|
|
|
|
public virtual void SetUp()
|
|
|
|
|
{
|
2020-12-21 23:27:10 +00:00
|
|
|
|
var scope1 = Program.CreateHostBuilder(new string[] { "--pathToConf" ,"..\\..\\..\\..\\..\\..\\config", "--ConnectionStrings:default:connectionString", "Server=localhost;Database=onlyoffice_test;User ID=root;Password=root;Pooling=true;Character Set=utf8;AutoEnlist=false;SSL Mode=none;AllowPublicKeyRetrieval=True", "--migration:enabled", "true" }).Build();
|
|
|
|
|
|
|
|
|
|
var scope = scope1.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-09-16 13:19:08 +00:00
|
|
|
|
|
2020-11-05 00:05:08 +00:00
|
|
|
|
SecurityContext.AuthenticateMe(CurrentTenant.OwnerId);
|
2020-12-21 23:27:10 +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
|
|
|
|
private void Configure(WebHostBuilderContext hostingContext, IConfigurationBuilder config)
|
|
|
|
|
{
|
|
|
|
|
var path = "..\\..\\..\\..\\..\\..\\config";
|
|
|
|
|
|
2020-11-12 03:55:14 +00:00
|
|
|
|
|
2020-09-16 13:19:08 +00:00
|
|
|
|
if (!Path.IsPathRooted(path))
|
|
|
|
|
{
|
|
|
|
|
path = Path.GetFullPath(Path.Combine(hostingContext.HostingEnvironment.ContentRootPath, path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config.SetBasePath(path);
|
|
|
|
|
config
|
|
|
|
|
.AddInMemoryCollection(new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{"pathToConf", path}
|
|
|
|
|
})
|
|
|
|
|
.AddJsonFile("appsettings.json")
|
|
|
|
|
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
|
|
|
|
.AddJsonFile("storage.json")
|
|
|
|
|
.AddJsonFile("kafka.json")
|
|
|
|
|
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
|
|
|
|
.AddEnvironmentVariables();
|
|
|
|
|
|
|
|
|
|
Configuration = config.Build();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
Database.Delete("Server=localhost;Database=onlyoffice_test;User ID=root;Password=root;Pooling=true;");
|
2020-09-16 13:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|