1
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2
|
using Models.Enums;
|
3
|
using Core.Entities;
|
4
|
using Serilog;
|
5
|
|
6
|
using System;
|
7
|
using System.Collections.Generic;
|
8
|
using System.Linq;
|
9
|
using System.Text;
|
10
|
using System.Threading.Tasks;
|
11
|
using Microsoft.EntityFrameworkCore;
|
12
|
using AutoMapper;
|
13
|
using Core.MapperProfiles;
|
14
|
using Core.Contexts;
|
15
|
using Microsoft.Extensions.Configuration;
|
16
|
using Models.Documents;
|
17
|
using Core.Services;
|
18
|
|
19
|
namespace BackendTesting
|
20
|
{
|
21
|
[TestClass]
|
22
|
public class TagsManagementTesting
|
23
|
{
|
24
|
private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
|
25
|
public DatabaseContext ctx;
|
26
|
//public Core.Services.DocumentService.IDocumentService DS;
|
27
|
//public Core.Services.IUserService US;
|
28
|
public Core.Services.TagService.ITagService TS;
|
29
|
//public DocumentAddRequest docList;
|
30
|
public User user;
|
31
|
|
32
|
//constructor for testing tags and anotations
|
33
|
public TagsManagementTesting()
|
34
|
{
|
35
|
//creating new database
|
36
|
this.ctx = new DatabaseContext(configuration);
|
37
|
//this.DS = new Core.Services.DocumentService.DocumentServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
|
38
|
//this.US = new UserServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
|
39
|
this.TS = new Core.Services.TagService.TagServiceEF(ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
|
40
|
|
41
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
42
|
|
43
|
//ensure the database is fresh without unwanted users from previous testings
|
44
|
ctx.Database.EnsureDeleted();
|
45
|
ctx.Database.EnsureCreated();
|
46
|
|
47
|
//user = new() { Id = Guid.NewGuid(), Name = "aa", Surname = "aa", Password = "aa", Role = ERole.ADMINISTRATOR, Username = "aa" };
|
48
|
//ctx.Users.Add(user);
|
49
|
//ctx.SaveChanges();
|
50
|
|
51
|
//docList = MakeRequest();
|
52
|
//FillUsers();
|
53
|
//ctx.SaveChanges();
|
54
|
}
|
55
|
|
56
|
[TestMethod]
|
57
|
public void GetTagTree_Testing()
|
58
|
{
|
59
|
try
|
60
|
{
|
61
|
//var tagTree = TS.GetTagTree();
|
62
|
|
63
|
//TODO - pridavat kategorie, tagy a podtagy
|
64
|
//kontrolovat zda jsou tam vsechny a spravne
|
65
|
//pripadne je zkusit odebirat (az budou na backendu doresene)
|
66
|
|
67
|
|
68
|
|
69
|
}
|
70
|
catch(Exception ex)
|
71
|
{
|
72
|
Assert.Fail("GetTagTree() failed on exception: " + ex);
|
73
|
}
|
74
|
|
75
|
|
76
|
|
77
|
}
|
78
|
|
79
|
|
80
|
|
81
|
|
82
|
|
83
|
|
84
|
|
85
|
|
86
|
/*
|
87
|
private void FillUsers()
|
88
|
{
|
89
|
var userList = new List<User>();
|
90
|
userList.Add(new User() { Username = "aaa", Name = "aaa", Surname = "aaa", Password = "aaa", Role = Models.Enums.ERole.ANNOTATOR });
|
91
|
userList.Add(new User() { Username = "bbb", Name = "bbb", Surname = "bbb", Password = "bbb", Role = Models.Enums.ERole.ANNOTATOR });
|
92
|
userList.Add(new User() { Username = "ccc", Name = "ccc", Surname = "ccc", Password = "ccc", Role = Models.Enums.ERole.ADMINISTRATOR });
|
93
|
userList.Add(new User() { Username = "ddd", Name = "ddd", Surname = "ddd", Password = "ddd", Role = Models.Enums.ERole.ANNOTATOR });
|
94
|
userList.Add(new User() { Username = "eee", Name = "eee", Surname = "eee", Password = "eee", Role = Models.Enums.ERole.ANNOTATOR });
|
95
|
userList.Add(new User() { Username = "fff", Name = "fff", Surname = "fff", Password = "fff", Role = Models.Enums.ERole.ANNOTATOR });
|
96
|
userList.Add(new User() { Username = "ggg", Name = "ggg", Surname = "ggg", Password = "ggg", Role = Models.Enums.ERole.ANNOTATOR });
|
97
|
userList.Add(new User() { Username = "hhh", Name = "hhh", Surname = "hhh", Password = "hhh", Role = Models.Enums.ERole.ADMINISTRATOR });
|
98
|
userList.Add(new User() { Username = "iii", Name = "iii", Surname = "iii", Password = "iii", Role = Models.Enums.ERole.ADMINISTRATOR });
|
99
|
userList.Add(new User() { Username = "jjj", Name = "jjj", Surname = "jjj", Password = "jjj", Role = Models.Enums.ERole.ADMINISTRATOR });
|
100
|
|
101
|
//filling up the database
|
102
|
foreach (var user in userList)
|
103
|
{
|
104
|
US.CreateUser(user.Username, user.Name, user.Surname, user.Password, user.Role);
|
105
|
}
|
106
|
ctx.SaveChanges();
|
107
|
}
|
108
|
|
109
|
private DocumentAddRequest MakeRequest()
|
110
|
{
|
111
|
docList = new DocumentAddRequest() { Documents = new() };
|
112
|
var dc = new DocumentContent();
|
113
|
string content = "aaa <html> bbb";
|
114
|
content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content));
|
115
|
dc.Content = content;
|
116
|
var dt = new DateTime(2022, 4, 11);
|
117
|
DocumentAddInfo info = new DocumentAddInfo();
|
118
|
info.Name = "a";
|
119
|
info.Content = content;
|
120
|
info.Format = EAddDocumentFormat.TEXTFILE;
|
121
|
docList.Documents.Add(info);
|
122
|
|
123
|
content = "aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb";
|
124
|
dc.Content = content;
|
125
|
dt = new DateTime(2022, 4, 12);
|
126
|
docList.Documents.Add(new DocumentAddInfo() { Name = "b", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
|
127
|
|
128
|
content = "aaa <html> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?>" +
|
129
|
" bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc>" +
|
130
|
" nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html>" +
|
131
|
" <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?>" +
|
132
|
" bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb aaa <html> <xss> \n xdd<abc> nonvalid xml<tag>abc <tag2?> bbb ";
|
133
|
dc.Content = content;
|
134
|
dt = new DateTime(2022, 4, 13);
|
135
|
docList.Documents.Add(new DocumentAddInfo() { Name = "c", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
|
136
|
|
137
|
content = "aaa";
|
138
|
dc.Content = content;
|
139
|
dt = new DateTime(2022, 4, 14);
|
140
|
docList.Documents.Add(new DocumentAddInfo() { Name = "d", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
|
141
|
|
142
|
content = "aaa <html> edfgckvhbjno§mpoizuzcjtjczkutvlzibůuoni§piuoůbzivlutkczjxzcktuvlziůuoi§ouůizvlutckzxjzckguvl h.gjcutfgýíáéphuoůizltukridýžáflizv bbb";
|
143
|
dc.Content = content;
|
144
|
dt = new DateTime(2022, 4, 15);
|
145
|
docList.Documents.Add(new DocumentAddInfo() { Name = "e", Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), Format = EAddDocumentFormat.TEXTFILE });
|
146
|
|
147
|
return docList;
|
148
|
}
|
149
|
*/
|
150
|
}
|
151
|
}
|