Merge pull request #715 from ONLYOFFICE/feature/room_tests

Feature/room tests
This commit is contained in:
Pavel Bannov 2022-07-13 13:03:41 +03:00 committed by GitHub
commit a88d5b6d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 578 additions and 125 deletions

1
.gitignore vendored
View File

@ -17,6 +17,7 @@ Logs/
build/deploy/
/public/debuginfo.md
TestsResults/
/Data.Test
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/PKG-INFO
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/SOURCES.txt
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/dependency_links.txt

View File

@ -208,7 +208,10 @@ public partial class FilesDbContextMySql : Migration
create_on = table.Column<DateTime>(type: "datetime", nullable: false),
url = table.Column<string>(type: "text", nullable: true, collation: "utf8_general_ci")
.Annotation("MySql:CharSet", "utf8"),
tenant_id = table.Column<int>(type: "int", nullable: false)
tenant_id = table.Column<int>(type: "int", nullable: false),
folder_id = table.Column<string>(type: "text", nullable: true, collation: "utf8_general_ci")
.Annotation("MySql:CharSet", "utf8"),
room_type = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{

View File

@ -67,7 +67,6 @@ class FilesApplication : WebApplicationFactory<Program>
public class MySetUpClass
{
protected IServiceScope Scope { get; set; }
private readonly string _pathToProducts = Path.Combine("..", "..", "..", "Data.Test");
[OneTimeSetUp]
public void CreateDb()
@ -102,7 +101,7 @@ public class MySetUpClass
try
{
Directory.Delete(Path.Combine("..", "..", "..", _pathToProducts), true);
Directory.Delete(Path.Combine(Path.Combine("..", "..", "..", "..", "..", "..", "Data.Test")), true);
}
catch { }
}
@ -127,9 +126,9 @@ public class MySetUpClass
public partial class BaseFilesTests
{
protected readonly JsonSerializerOptions _options;
private readonly JsonSerializerOptions _options;
protected UserManager _userManager;
private protected HttpClient _client;
private HttpClient _client;
private readonly string _baseAddress;
private string _cookie;
@ -208,89 +207,29 @@ public partial class BaseFilesTests
return batchModel;
}
protected async Task<T> GetAsync<T>(string url, JsonSerializerOptions options)
protected Task<T> GetAsync<T>(string url)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var request = await _client.GetAsync(url);
var result = await request.Content.ReadFromJsonAsync<SuccessApiResponse>();
if (result.Response is JsonElement jsonElement)
{
return jsonElement.Deserialize<T>(options);
}
throw new Exception("can't parsing result");
return SendAsync<T>(HttpMethod.Get, url);
}
protected async Task<T> GetAsync<T>(string url, HttpContent content, JsonSerializerOptions options)
protected Task<T> PostAsync<T>(string url, object data = null)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseAddress + url),
Method = HttpMethod.Delete,
Content = content
};
var result = await request.Content.ReadFromJsonAsync<SuccessApiResponse>();
if (result.Response is JsonElement jsonElement)
{
return jsonElement.Deserialize<T>(options);
}
throw new Exception("can't parsing result");
return SendAsync<T>(HttpMethod.Post, url, data);
}
protected async Task<T> PostAsync<T>(string url, HttpContent content, JsonSerializerOptions options)
protected Task<T> PutAsync<T>(string url, object data = null)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var response = await _client.PostAsync(url, content);
var result = await response.Content.ReadFromJsonAsync<SuccessApiResponse>();
if (result.Response is JsonElement jsonElement)
{
return jsonElement.Deserialize<T>(options);
}
throw new Exception("can't parsing result");
return SendAsync<T>(HttpMethod.Put, url, data);
}
protected async Task<T> PutAsync<T>(string url, HttpContent content, JsonSerializerOptions options)
protected Task<T> DeleteAsync<T>(string url, object data = null)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var response = await _client.PutAsync(url, content);
var result = await response.Content.ReadFromJsonAsync<SuccessApiResponse>();
if (result.Response is JsonElement jsonElement)
{
return jsonElement.Deserialize<T>(options);
}
throw new Exception("can't parsing result");
return SendAsync<T>(HttpMethod.Delete, url, data);
}
private protected async Task<HttpResponseMessage> DeleteAsync(string url, JsonContent content)
private protected Task<SuccessApiResponse> DeleteAsync(string url, object data = null)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseAddress + url),
Method = HttpMethod.Delete,
Content = content
};
return await _client.SendAsync(request);
}
protected async Task<T> DeleteAsync<T>(string url, JsonContent content, JsonSerializerOptions options)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var response = await DeleteAsync(url, content);
var result = await response.Content.ReadFromJsonAsync<SuccessApiResponse>();
if (result.Response is JsonElement jsonElement)
{
return jsonElement.Deserialize<T>(options);
}
throw new Exception("can't parsing result");
return SendAsync(HttpMethod.Delete, url, data);
}
protected async Task<List<FileOperationResult>> WaitLongOperation()
@ -299,7 +238,7 @@ public partial class BaseFilesTests
while (true)
{
statuses = await GetAsync<List<FileOperationResult>>("fileops", _options);
statuses = await GetAsync<List<FileOperationResult>>("fileops");
if (statuses.TrueForAll(r => r.Finished))
{
@ -309,5 +248,42 @@ public partial class BaseFilesTests
}
return statuses;
}
protected void CheckStatuses(List<FileOperationResult> statuses)
{
Assert.IsTrue(statuses.Count > 0);
Assert.IsTrue(statuses.TrueForAll(r => string.IsNullOrEmpty(r.Error)));
}
protected async Task<T> SendAsync<T>(HttpMethod method, string url, object data = null)
{
var result = await SendAsync(method, url, data);
if (result.Response is JsonElement jsonElement)
{
return jsonElement.Deserialize<T>(_options);
}
throw new Exception("can't parsing result");
}
protected async Task<SuccessApiResponse> SendAsync(HttpMethod method, string url, object data = null)
{
_client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _cookie);
var request = new HttpRequestMessage
{
RequestUri = new Uri(_baseAddress + url),
Method = method,
};
if (data != null)
{
request.Content = JsonContent.Create(data);
}
var response = await _client.SendAsync(request);
return await response.Content.ReadFromJsonAsync<SuccessApiResponse>();
}
}

View File

@ -38,8 +38,7 @@ public partial class BaseFilesTests
[Description("post - files/folder/{folderId} - attempt to create a folder when it is forbidden")]
public async Task CreateFolderReturnsFolderWrapperAsync(int folderId)
{
var response = await _client.PostAsync("folder/" + folderId, JsonContent.Create(new { Title = "test" }));
var result = await response.Content.ReadFromJsonAsync<SuccessApiResponse>();
var result = await SendAsync(HttpMethod.Post, "folder/" + folderId, new { Title = "test" });
Assert.AreEqual(HttpStatusCode.Forbidden, result.StatusCode);
}
@ -52,7 +51,7 @@ public partial class BaseFilesTests
[Order(1)]
public async Task CreateFileReturnsFolderWrapperAsync(int folderId)
{
var file = await PostAsync<FileDto<int>>(folderId + "/file", JsonContent.Create(new { Title = "test" }), _options);
var file = await PostAsync<FileDto<int>>($"{folderId}/file", new { Title = "test" });
Assert.AreEqual(file.FolderId, 1);
}
}

View File

@ -35,7 +35,7 @@ public partial class BaseFilesTests
[Description("post - files/favorites - add file and folder to favorites")]
public async Task AddFavoriteFolderAndFileToFolderWrapper(int folderID, int fileId)
{
var favorite = await PostAsync<bool>("favorites", JsonContent.Create(new { FolderIds = new List<int> { folderID }, FileIds = new List<int> { fileId } }), _options);
var favorite = await PostAsync<bool>("favorites", new { FolderIds = new List<int> { folderID }, FileIds = new List<int> { fileId } });
Assert.IsTrue(favorite);
}
@ -46,7 +46,7 @@ public partial class BaseFilesTests
[Description("delete - files/favorites - delete file and folder from favorites")]
public async Task DeleteFavoriteFolderAndFileToFolderWrapper(int folderID, int fileId)
{
var favorite = await DeleteAsync<bool>("favorites", JsonContent.Create(new { FolderIds = new List<int> { folderID }, FileIds = new List<int> { fileId } }), _options);
var favorite = await DeleteAsync<bool>("favorites", new { FolderIds = new List<int> { folderID }, FileIds = new List<int> { fileId } });
Assert.IsTrue(favorite);
}

View File

@ -71,5 +71,22 @@ public static class DataTests
public const bool Immediately = true;
public const bool Notify = false;
public const string Message = "folder_test";
public const string Message = "test_message";
public const string RoomTitle = "Room_Title";
public const string NewRoomTitle = "New_Room_Title";
public const int CustomRoomId = 5;
public const int RoomId = 18;
public const int RoomIdForDelete = 19;
public const int RoomIdForArchive = 20;
public const int RoomIdForUnpin = 21;
public const int RoomIdForUnarchive = 22;
public const int RoomIdWithTags = 24;
public const string RoomLinkKey = "394892027511.N5UVJ8F6UJPGN0RZKWSOMEYVZVLTZLECGVHHSDSH7ZA";
public const string TagNames = "name1,name2";
public const string Email = "test1@gmail.com";
public const string Image = "appIcon-180.png";
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -35,7 +35,7 @@ public partial class BaseFilesTests
[Description("post - files/folder/{folderId} - create new folder")]
public async Task CreateFolderReturnsFolderWrapper(int folderId, string title)
{
var folder = await PostAsync<FolderDto<int>>("folder/" + folderId, JsonContent.Create(new { Title = title }), _options);
var folder = await PostAsync<FolderDto<int>>($"folder/{folderId}", new { Title = title });
Assert.IsNotNull(folder);
Assert.AreEqual(title, folder.Title);
Assert.AreEqual(folderId, folder.ParentId);
@ -48,7 +48,7 @@ public partial class BaseFilesTests
[Description("get - files/{folderId} - get empty folder / get not empty folder")]
public async Task GetFolderEmptyReturnsFolderContentWrapper(int folderId, int expectedCount)
{
var folder = await GetAsync<FolderContentDto<int>>(folderId.ToString(), _options);
var folder = await GetAsync<FolderContentDto<int>>(folderId.ToString());
Assert.IsNotNull(folder);
Assert.AreEqual(expectedCount, folder.Files.Count);
@ -61,7 +61,7 @@ public partial class BaseFilesTests
[Description("get - files/folder/{folderId} - get folder info")]
public async Task GetFolderInfoReturnsFolderWrapper(int folderId, string folderName, int parentId)
{
var folder = await GetAsync<FolderDto<int>>("folder/" + folderId, _options);
var folder = await GetAsync<FolderDto<int>>($"folder/{folderId}");
Assert.IsNotNull(folder);
Assert.AreEqual(folderName, folder.Title);
@ -75,7 +75,7 @@ public partial class BaseFilesTests
[Description("put - files/folder/{folderId} - rename folder")]
public async Task RenameFolderReturnsFolderWrapper(int folderId, string newTitle)
{
var folder = await PutAsync<FolderDto<int>>("folder/" + folderId, JsonContent.Create(new { Title = newTitle }), _options);
var folder = await PutAsync<FolderDto<int>>($"folder/{folderId}", new { Title = newTitle });
Assert.IsNotNull(folder);
Assert.AreEqual(folderId, folder.Id);
@ -88,9 +88,9 @@ public partial class BaseFilesTests
[Description("delete - files/folder/{folderId} - delete folder")]
public async Task DeleteFolderReturnsFolderWrapper(int folderId, bool deleteAfter, bool immediately)
{
await DeleteAsync("folder/" + folderId, JsonContent.Create(new { DeleteAfter = deleteAfter, Immediately = immediately }));
var statuses = await WaitLongOperation();
Assert.IsTrue(statuses.TrueForAll(r => string.IsNullOrEmpty(r.Error)));
await DeleteAsync($"folder/{folderId}", new { DeleteAfter = deleteAfter, Immediately = immediately });
var statuses = await WaitLongOperation();
CheckStatuses(statuses);
}
[TestCase(DataTests.NewTitle)]
@ -99,7 +99,7 @@ public partial class BaseFilesTests
[Description("post - files/@my/file - create file in myFolder")]
public async Task CreateFileReturnsFileWrapper(string newTitle)
{
var file = await PostAsync<FileDto<int>>("@my/file", JsonContent.Create(new { Title = newTitle }), _options);
var file = await PostAsync<FileDto<int>>("@my/file", new { Title = newTitle });
Assert.IsNotNull(file);
Assert.AreEqual($"{newTitle}.docx", file.Title);
@ -112,7 +112,7 @@ public partial class BaseFilesTests
[Description("get - files/file/{fileId} - get file info")]
public async Task GetFileInfoReturnsFilesWrapper(int fileId, string fileName)
{
var file = await GetAsync<FileDto<int>>("file/" + fileId, _options);
var file = await GetAsync<FileDto<int>>($"file/{fileId}");
Assert.IsNotNull(file);
Assert.AreEqual(fileName, file.Title);
@ -124,7 +124,7 @@ public partial class BaseFilesTests
[Description("put - files/file/{fileId} - update file")]
public async Task UpdateFileReturnsFileWrapper(int fileId, string newTitle, int lastVersion)
{
var file = await PutAsync<FileDto<int>>("file/" + fileId, JsonContent.Create(new { Title = newTitle, LastVersion = lastVersion }), _options);
var file = await PutAsync<FileDto<int>>($"file/{fileId}", new { Title = newTitle, LastVersion = lastVersion });
Assert.IsNotNull(file);
Assert.AreEqual(newTitle + ".docx", file.Title);
@ -136,9 +136,9 @@ public partial class BaseFilesTests
[Description("delete - files/file/{fileId} - delete file")]
public async Task DeleteFileReturnsFileWrapper(int fileId, bool deleteAfter, bool immediately)
{
await DeleteAsync("file/" + fileId, JsonContent.Create(new { DeleteAfter = deleteAfter, Immediately = immediately }));
var statuses = await WaitLongOperation();
Assert.IsTrue(statuses.TrueForAll(r => string.IsNullOrEmpty(r.Error)));
await DeleteAsync($"file/{fileId}", new { DeleteAfter = deleteAfter, Immediately = immediately });
var statuses = await WaitLongOperation();
CheckStatuses(statuses);
}
[TestCase(DataTests.MoveBatchItems)]
@ -148,7 +148,7 @@ public partial class BaseFilesTests
{
var batchModel = GetBatchModel(json);
var statuses = await PutAsync<IEnumerable<FileOperationDto>>("fileops/move", JsonContent.Create(batchModel), _options);
var statuses = await PutAsync<IEnumerable<FileOperationDto>>("fileops/move", batchModel);
FileOperationDto status = null;
foreach (var item in statuses)
@ -171,7 +171,7 @@ public partial class BaseFilesTests
{
var batchModel = GetBatchModel(json);
var statuses = await PutAsync<IEnumerable<FileOperationDto>>("fileops/copy", JsonContent.Create(batchModel), _options);
var statuses = await PutAsync<IEnumerable<FileOperationDto>>("fileops/copy", batchModel);
FileOperationDto status = null;
foreach (var item in statuses)

View File

@ -35,7 +35,7 @@ public partial class BaseFilesTests
[Description("post - file/{fileId}/recent - add file to recent")]
public async Task RecentFileReturnsFolderWrapper(int fileId, string fileName)
{
var file = await PostAsync<FileDto<int>>("file/" + fileId + "/recent", null, _options);
var file = await PostAsync<FileDto<int>>($"file/{fileId}/recent");
Assert.IsNotNull(file);
Assert.AreEqual(fileName, file.Title);
}
@ -46,10 +46,12 @@ public partial class BaseFilesTests
[Description("delete - file/{fileId}/recent - delete file which added to recent")]
public async Task DeleteRecentFileReturnsFolderWrapper(int fileId, string fileTitleExpected)
{
await PostAsync<FileDto<int>>("file/" + fileId + "/recent", null, _options);
await DeleteAsync("file/" + fileId, JsonContent.Create(new { DeleteAfter = false, Immediately = true }));
_ = await WaitLongOperation();
var recents = await GetAsync<FolderContentDto<int>>("@recent", _options);
await PostAsync<FileDto<int>>($"file/{fileId}/recent");
await DeleteAsync($"file/{fileId}", new { DeleteAfter = false, Immediately = true });
await WaitLongOperation();
var recents = await GetAsync<FolderContentDto<int>>("@recent");
Assert.IsTrue(!recents.Files.Any(r => r.Title == fileTitleExpected + ".docx"));
}
@ -58,7 +60,7 @@ public partial class BaseFilesTests
[Order(3)]
public async Task ShareFileToAnotherUserAddToRecent(int fileId, string fileName)
{
var file = await PostAsync<FileDto<int>>("file/" + fileId + "/recent", null, _options);
var file = await PostAsync<FileDto<int>>($"file/{fileId}/recent");
Assert.IsNotNull(file);
Assert.AreEqual(fileName, file.Title);

View File

@ -0,0 +1,215 @@
// (c) Copyright Ascensio System SIA 2010-2022
//
// This program is a free software product.
// You can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
// any third-party rights.
//
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
//
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
//
// The interactive user interfaces in modified source and object code versions of the Program must
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
//
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
// trademark law for use of our trademarks.
//
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
using ASC.Core.Users;
namespace ASC.Files.Tests;
[TestFixture]
public partial class BaseFilesTests
{
[TestCase(DataTests.RoomTitle, DataTests.CustomRoomId)]
[Category("Room")]
[Order(1)]
[Description("post - rooms - create room")]
public async Task CreateRoom(string title, int roomType)
{
var room = await PostAsync<FolderDto<int>>("rooms", new { Title = title, RoomType = roomType });
Assert.IsNotNull(room);
Assert.AreEqual(title, room.Title);
}
[TestCase(DataTests.RoomId, DataTests.NewRoomTitle)]
[Category("Room")]
[Order(2)]
[Description("put - rooms/{id} - rename room")]
public async Task RenameRoom(int id, string newTitle)
{
var room = await PutAsync<FolderDto<int>>($"rooms/{id}", new { Title = newTitle });
Assert.IsNotNull(room);
Assert.AreEqual(newTitle, room.Title);
}
[TestCase(DataTests.RoomIdForDelete, DataTests.DeleteAfter)]
[Category("Room")]
[Order(3)]
[Description("delete - rooms/{id} - delete room")]
public async Task DeleteRoom(int id, bool deleteAfter)
{
await DeleteAsync<FileOperationDto>($"rooms/{id}", new { DeleteAfter = deleteAfter });
var statuses = await WaitLongOperation();
CheckStatuses(statuses);
}
[TestCase(DataTests.RoomIdForArchive, DataTests.DeleteAfter)]
[Category("Room")]
[Order(4)]
[Description("put - rooms/{id}/archive - archive a room")]
public async Task ArchiveRoom(int id, bool deleteAfter)
{
await PutAsync<FileOperationDto>($"rooms/{id}/archive", new { DeleteAfter = deleteAfter });
var statuses = await WaitLongOperation();
CheckStatuses(statuses);
}
[TestCase(DataTests.RoomIdForUnarchive, DataTests.DeleteAfter)]
[Category("Room")]
[Order(5)]
[Description("put - rooms/{id}/archive - unarchive a room")]
public async Task UnarchiveRoom(int id, bool deleteAfter)
{
await PutAsync<FileOperationDto>($"rooms/{id}/unarchive", new { DeleteAfter = deleteAfter });
var statuses = await WaitLongOperation();
CheckStatuses(statuses);
}
[TestCase(DataTests.RoomId, DataTests.Notify, DataTests.Message)]
[Category("Room")]
[Order(6)]
[Description("put - rooms/{id}/share - share a room")]
public async Task ShareRoom(int id, bool notify, string message)
{
var newUser = _userManager.GetUsers(Guid.Parse("005bb3ff-7de3-47d2-9b3d-61b9ec8a76a5"));
var testRoomParamRead = new List<FileShareParams> { new FileShareParams { Access = Core.Security.FileShare.Read, ShareTo = newUser.Id } };
var share = await PutAsync<IEnumerable<FileShareDto>>($"rooms/{id}/share", new { Share = testRoomParamRead, Notify = notify, SharingMessage = message });
Assert.IsNotNull(share);
}
[TestCase]
[Category("Room")]
[Order(7)]
[Description("get - rooms - get all rooms")]
public async Task GetAllRooms()
{
var rooms = await GetAsync<FolderContentDto<int>>($"rooms");
Assert.IsNotNull(rooms);
}
[TestCase(DataTests.RoomId)]
[Category("Room")]
[Order(8)]
[Description("get - rooms/{id} - get room by id")]
public async Task GetRoomById(int id)
{
var room = await GetAsync<FolderContentDto<int>>($"rooms/{id}");
Assert.IsNotNull(room);
}
[TestCase(DataTests.RoomId, DataTests.TagNames)]
[Category("Room")]
[Order(9)]
[Description("put - rooms/{id}/tags - add tags by id")]
public async Task AddTagsById(int id, string tagNames)
{
var folder = await PutAsync<FolderDto<int>>($"rooms/{id}/tags", new { Names = tagNames.Split(',') });
Assert.IsTrue(folder.Tags.Count() == 2);
}
[TestCase(DataTests.RoomIdWithTags, DataTests.TagNames)]
[Category("Room")]
[Order(10)]
[Description("delete - rooms/{id}/tags - delete tags by id")]
public async Task DeleteTagsById(int id, string tagNames)
{
var folder = await DeleteAsync<FolderDto<int>>($"rooms/{id}/tags", new { Names = tagNames.Split(',') });
Assert.IsTrue(folder.Tags.Count() == 0);
}
[TestCase(DataTests.RoomId)]
[Category("Room")]
[Order(11)]
[Description("put - rooms/{id}/pin - pin a room")]
public async Task PinRoom(int id)
{
var folder = await PutAsync<FolderDto<int>>($"rooms/{id}/pin");
Assert.IsTrue(folder.Pinned);
}
[TestCase(DataTests.RoomIdForUnpin)]
[Category("Room")]
[Order(12)]
[Description("put - rooms/{id}/unpin - unpin a room")]
public async Task UnpinRoom(int id)
{
var folder = await PutAsync<FolderDto<int>>($"rooms/{id}/unpin");
Assert.IsFalse(folder.Pinned);
}
[TestCase(DataTests.RoomId, DataTests.Email)]
[Category("Room")]
[Order(13)]
[Description("put - rooms/{id}/links/send - send invitation links to email")]
public async Task SendLink(int id, string email)
{
var invites = await PutAsync<IEnumerable<InviteResultDto>>($"rooms/{id}/links/send", new { Emails = new List<string>() { email }, EmployeeType = EmployeeType.All, Access = Core.Security.FileShare.Read });
Assert.IsTrue(invites.First().Success);
}
[TestCase(DataTests.RoomId, DataTests.RoomLinkKey)]
[Category("Room")]
[Order(14)]
[Description("put - rooms/{id}/share - share a room by link")]
public async Task ShareRoomByLink(int id, string key)
{
var share = await PutAsync<IEnumerable<FileShareDto>>($"rooms/{id}/share", new { Access = Core.Security.FileShare.Read, Key = key });
Assert.IsNotNull(share);
}
[TestCase(DataTests.RoomId)]
[Category("Room")]
[Order(15)]
[Description("get - rooms/{id}/links - get invitation links")]
public async Task GetLink(int id)
{
var invites = await GetAsync<string>($"rooms/{id}/links?access=2");
Assert.IsNotNull(invites);
Assert.IsNotEmpty(invites);
}
//[TestCase(DataTests.RoomId, DataTests.Image)]
//[Category("Room")]
//[Order(16)]
//[Description("post - rooms/{id}/logo - add logo/ delete - rooms/{id}/logo - delete logo")]
//public async Task AddAndDeleteLogo(int id, string image)
//{
// CopyImage(image);
// var room = await PostAsync<FolderDto<int>>($"rooms/{id}/logo", JsonContent.Create(new { TmpFile = image, X = 0, Y = 0, Width = 180, Height = 180 }));
// Assert.IsNotEmpty(room.Logo.Original);
// room = await DeleteAsync<FolderDto<int>>($"rooms/{id}/logo", null);
// Assert.IsEmpty(room.Logo.Original);
//}
//private void CopyImage(string image)
//{
// var imgPath = Path.Combine("..", "..", "..", "Infrastructure", "images", image);
// var destPath = Path.Combine("..", "..", "..", "..", "..", "..", "Data.Test", "Products\\Files\\logos\\00/00/01\\temp");
// Directory.CreateDirectory(destPath);
// File.Copy(imgPath, Path.Combine(destPath, image), true);
//}
}

View File

@ -49,7 +49,7 @@ public partial class BaseFilesTests
[Description("put - files/folder/{folderId}/share - share folder to another user for read")]
public async Task ShareFolderToAnotherUserRead(int folderId, bool notify, string message)
{
var share = await PutAsync<IEnumerable<FileShareDto>>("folder/" + folderId + "/share", JsonContent.Create(new { Share = _testFolderParamRead, Notify = notify, SharingMessage = message }), _options);
var share = await PutAsync<IEnumerable<FileShareDto>>($"folder/{folderId}/share", new { Share = _testFolderParamRead, Notify = notify, SharingMessage = message });
Assert.IsNotNull(share);
}
@ -59,8 +59,7 @@ public partial class BaseFilesTests
[Description("put - files/folder/{folderId} - try to update folder which can only read")]
public async Task RenameSharedFolderReturnsFolderWrapperReadAsync(int folderId)
{
var request = await _client.PutAsync("folder/" + folderId, JsonContent.Create(new { Title = "newName" }));
var result = await request.Content.ReadFromJsonAsync<SuccessApiResponse>();
var result = await SendAsync(HttpMethod.Put, "folder/" + folderId, new { Title = "newName" });
Assert.AreEqual(HttpStatusCode.Forbidden, result.StatusCode);
}
@ -70,7 +69,7 @@ public partial class BaseFilesTests
[Description("put - file/{fileId}/share - share file to another user for read")]
public async Task ShareFileToAnotherUserRead(int fileId, bool notify, string message)
{
var share = await PutAsync<IEnumerable<FileShareDto>>("file/" + fileId + "/share", JsonContent.Create(new { Share = _testFolderParamRead, Notify = notify, SharingMessage = message }), _options);
var share = await PutAsync<IEnumerable<FileShareDto>>($"file/{fileId}/share", new { Share = _testFolderParamRead, Notify = notify, SharingMessage = message });
Assert.IsNotNull(share);
}
@ -80,11 +79,10 @@ public partial class BaseFilesTests
[Description("put - files/file/{fileId} - try to update file which can only read")]
public async Task UpdateSharedFileReturnsFolderWrapperReadAsync(int fileId)
{
var request = await _client.PutAsync("file/" + fileId, JsonContent.Create(new { Title = "newName", LastVersion = 0 }));
var result = await request.Content.ReadFromJsonAsync<SuccessApiResponse>();
var result = await SendAsync(HttpMethod.Put, "file/" + fileId, new { Title = "newName", LastVersion = 0 });
Assert.That(HttpStatusCode.Forbidden == result.StatusCode);
}
}
#endregion
#region Shared Folder and File (Read and Write)
@ -95,7 +93,7 @@ public partial class BaseFilesTests
[Description("put - files/folder/{folderId}/share - share folder to another user for read and write")]
public async Task ShareFolderToAnotherUserReadAndWrite(int folderId, bool notify, string message)
{
var share = await PutAsync<IEnumerable<FileShareDto>>("folder/" + folderId + "/share", JsonContent.Create(new { Share = _testFolderParamReadAndWrite, Notify = notify, SharingMessage = message }), _options);
var share = await PutAsync<IEnumerable<FileShareDto>>($"folder/{folderId}/share", new { Share = _testFolderParamReadAndWrite, Notify = notify, SharingMessage = message });
Assert.IsNotNull(share);
}
@ -105,7 +103,7 @@ public partial class BaseFilesTests
[Description("put - files/folder/{folderId} - rename shared for read and write folder")]
public async Task RenameSharedFolderReturnsFolderWrapperReadAndWrite(int folderId, string newTitle)
{
var sharedFolder = await PutAsync<FolderDto<int>>("folder/" + folderId, JsonContent.Create(new { Title = newTitle }), _options);
var sharedFolder = await PutAsync<FolderDto<int>>($"folder/{folderId}", new { Title = newTitle });
Assert.IsNotNull(sharedFolder);
Assert.AreEqual(newTitle, sharedFolder.Title);
@ -117,7 +115,7 @@ public partial class BaseFilesTests
[Description("put - files/file/{fileId}/share - share file to another user for read and write")]
public async Task ShareFileToAnotherUserReadAndWrite(int fileId, bool notify, string message)
{
var share = await PutAsync<IEnumerable<FileShareDto>>("file/" + fileId + "/share", JsonContent.Create(new { Share = _testFolderParamReadAndWrite, Notify = notify, SharingMessage = message }), _options);
var share = await PutAsync<IEnumerable<FileShareDto>>($"file/{fileId}/share", new { Share = _testFolderParamReadAndWrite, Notify = notify, SharingMessage = message });
Assert.IsNotNull(share);
}
@ -127,7 +125,7 @@ public partial class BaseFilesTests
[Description("put - files/file/{fileId} - update shared for read and write file")]
public async Task UpdateSharedFileReturnsFolderWrapperReadAndWrite(int fileId, string fileTitle, int lastVersion)
{
var sharedFile = await PutAsync<FolderDto<int>>("file/" + fileId, JsonContent.Create(new { Title = fileTitle, LastVersion = lastVersion }), _options);
var sharedFile = await PutAsync<FolderDto<int>>($"file/{fileId}", new { Title = fileTitle, LastVersion = lastVersion });
Assert.IsNotNull(sharedFile);
Assert.AreEqual(fileTitle + ".docx", sharedFile.Title);
@ -141,7 +139,7 @@ public partial class BaseFilesTests
[Description("get - files/folder/{folderId} - get shared folder")]
public async Task GetSharedFolderInfoReturnsFolderWrapperRead(int folderId, string folderName, int parentId)
{
var sharedFolder = await GetAsync<FolderDto<int>>("folder/" + folderId, _options);
var sharedFolder = await GetAsync<FolderDto<int>>($"folder/{folderId}");
Assert.IsNotNull(sharedFolder);
Assert.AreEqual(folderName, sharedFolder.Title);
@ -156,7 +154,7 @@ public partial class BaseFilesTests
[Description("get - files/file/{fileId} - get shared file")]
public async Task GetSharedFileInfoReturnsFolderWrapperRead(int fileId, string fileName)
{
var sharedFile = await GetAsync<FolderDto<int>>("file/" + fileId, _options);
var sharedFile = await GetAsync<FolderDto<int>>($"file/{fileId}");
Assert.IsNotNull(sharedFile);
Assert.AreEqual(fileName, sharedFile.Title);
@ -169,7 +167,7 @@ public partial class BaseFilesTests
[Description("delete - files/file/{fileId} - try delete shared file")]
public async Task DeleteSharedFileReturnsFolderWrapperRead(int fileId, bool deleteAfter, bool immediately)
{
var result = (await DeleteAsync<IEnumerable<FileOperationDto>>("file/" + fileId, JsonContent.Create(new { DeleteAfter = deleteAfter, Immediately = immediately }), _options)).FirstOrDefault();
var result = (await DeleteAsync<IEnumerable<FileOperationDto>>($"file/{fileId}", new { DeleteAfter = deleteAfter, Immediately = immediately })).FirstOrDefault();
await WaitLongOperation(result, FilesCommonResource.ErrorMassage_SecurityException_DeleteFile);
}
@ -181,7 +179,7 @@ public partial class BaseFilesTests
[Description("delete - files/folder/{folderId} - try delete shared folder")]
public async Task DeleteSharedFolderReturnsFolderWrapperRead(int folderId, bool deleteAfter, bool immediately)
{
var result = (await DeleteAsync<IEnumerable<FileOperationDto>>("folder/" + folderId, JsonContent.Create(new { DeleteAfter = deleteAfter, Immediately = immediately }), _options)).FirstOrDefault();
var result = (await DeleteAsync<IEnumerable<FileOperationDto>>($"folder/{folderId}", new { DeleteAfter = deleteAfter, Immediately = immediately })).FirstOrDefault();
await WaitLongOperation(result, FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder);
}

View File

@ -300,6 +300,83 @@ namespace ASC.Core.Common.Migrations
.HasDatabaseName("tenant_id");
b.ToTable("files_security");
});
modelBuilder.Entity("ASC.Files.Core.EF.DbFilesTag", b =>
{
b.Property<int>("Id")
.HasColumnType("int")
.HasColumnName("id");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("char(255)")
.HasColumnName("name")
.UseCollation("utf8_general_ci")
.HasAnnotation("MySql:CharSet", "utf8");
b.Property<string>("Owner")
.IsRequired()
.HasColumnType("char(38)")
.HasColumnName("owner")
.UseCollation("utf8_general_ci")
.HasAnnotation("MySql:CharSet", "utf8");
b.Property<int>("Type")
.HasColumnType("int")
.HasColumnName("flag");
b.Property<int>("TenantId")
.HasColumnType("int")
.HasColumnName("tenant_id");
b.ToTable("files_tag");
});
modelBuilder.Entity("ASC.Files.Core.EF.DbFilesTagLink", b =>
{
b.Property<int>("TenantId")
.HasColumnType("int")
.HasColumnName("tenant_id");
b.Property<int>("TagId")
.HasColumnType("int")
.HasColumnName("tag_id");
b.Property<int>("EntryType")
.HasColumnType("int")
.HasColumnName("entry_type");
b.Property<string>("EntryId")
.IsRequired()
.HasColumnType("varchar(32)")
.HasColumnName("entry_id")
.UseCollation("utf8_general_ci")
.HasAnnotation("MySql:CharSet", "utf8");
b.Property<string>("CreateBy")
.IsRequired()
.HasColumnType("char(38)")
.HasColumnName("create_by")
.UseCollation("utf8_general_ci")
.HasAnnotation("MySql:CharSet", "utf8");
b.Property<string>("CreateBy")
.IsRequired()
.HasColumnType("char(38)")
.HasColumnName("create_by")
.UseCollation("utf8_general_ci")
.HasAnnotation("MySql:CharSet", "utf8");
b.Property<DateTime>("CreateOn")
.HasColumnType("datetime")
.HasColumnName("create_on");
b.Property<int>("Count")
.HasColumnType("int")
.HasColumnName("tag_count");
b.ToTable("files_tag_link");
});
#pragma warning restore 612, 618
}

View File

@ -231,6 +231,126 @@ public partial class TestFilesMigration : Migration
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 16, 6, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 17, 0, "virtualrooms", 14, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 17, 17, 0 });
migrationBuilder.InsertData(
table: "files_bunch_objects",
columns: new[] { "tenant_id", "right_node", "left_node" },
values: new object[] { 1, "files/virtualrooms/", "17" });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 18, 17, "Room_Title", 19, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 18, 18, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 18, 17, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 19, 17, "Room_Title", 19, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 19, 19, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 19, 17, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 20, 17, "Room_Title", 19, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 20, 20, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 20, 17, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 21, 17, "Room_Title", 20, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 21, 21, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 21, 17, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 22, 23, "Room_Title", 19, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 22, 22, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 22, 23, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 23, 17, "arhive", 20, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 23, 23, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 23, 17, 0 });
migrationBuilder.InsertData(
table: "files_folder",
columns: new[] { "id", "parent_id", "title", "folder_type", "create_by", "create_on", "modified_by", "modified_on", "tenant_id", "foldersCount", "filesCount" },
values: new object[] { 24, 17, "Room_Title", 19, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 1, 0, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 24, 24, 0 });
migrationBuilder.InsertData(
table: "files_folder_tree",
columns: new[] { "folder_id", "parent_id", "level" },
values: new object[] { 24, 17, 0 });
migrationBuilder.InsertData(
table: "files_file",
columns: new[] {
@ -326,15 +446,60 @@ public partial class TestFilesMigration : Migration
values: new object[]{
1, "16", 1, "66faa6e4-f133-11ea-b126-00ffeec8b4ef", "005bb3ff-7de3-47d2-9b3d-61b9ec8a76a5", 1, new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842)
});
/*
migrationBuilder.InsertData(
table: "files_tag",
columns: new[]{
"id","tenant_id","name","owner","flag",
},
values: new object[]{
1, 1, "recent", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", 16
});*/
1, 1, "name1", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", 64
});
migrationBuilder.InsertData(
table: "files_tag_link",
columns: new[]{
"tenant_id","tag_id","entry_type","entry_id","create_by","create_on","tag_count",
},
values: new object[]{
1, 1, 1, "24", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 0
});
migrationBuilder.InsertData(
table: "files_tag",
columns: new[]{
"id","tenant_id","name","owner","flag",
},
values: new object[]{
2, 1, "name2", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", 64
});
migrationBuilder.InsertData(
table: "files_tag_link",
columns: new[]{
"tenant_id","tag_id","entry_type","entry_id","create_by","create_on","tag_count",
},
values: new object[]{
1, 2, 1, "24", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 0
});
migrationBuilder.InsertData(
table: "files_tag",
columns: new[]{
"id","tenant_id","name","owner","flag",
},
values: new object[]{
3, 1, "pin", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", 128
});
migrationBuilder.InsertData(
table: "files_tag_link",
columns: new[]{
"tenant_id","tag_id","entry_type","entry_id","create_by","create_on","tag_count",
},
values: new object[]{
1, 3, 1, "21", "66faa6e4-f133-11ea-b126-00ffeec8b4ef", new DateTime(2021, 8, 4, 11, 1, 4, 513, DateTimeKind.Utc).AddTicks(1842), 0
});
}
protected override void Down(MigrationBuilder migrationBuilder)

View File

@ -31,12 +31,12 @@ public partial class BaseFilesTests
{
[Test]
[Category("Folder")]
[Order(1)]
[Order(100)]
[Description("put - files/fileops/emptytrash - empty trash")]
public async Task DeleteFileFromTrash()
{
var Empty = await PutAsync<IEnumerable<FileOperationDto>>("fileops/emptytrash", null, _options);
await PutAsync<IEnumerable<FileOperationDto>>("fileops/emptytrash");
var statuses = await WaitLongOperation();
Assert.IsTrue(statuses.TrueForAll(r => string.IsNullOrEmpty(r.Error)));
CheckStatuses(statuses);
}
}