Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5e599715

Přidáno uživatelem Jakub Schenk před asi 2 roky(ů)

Prepared for tags testing

tags testing preparations and removal of not used classes prepared before in testing skelet

Zobrazit rozdíly:

Backend/BackendTesting/Constants.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace BackendTesting
8
{
9
    public class Constants
10
    {
11
    }
12
}
Backend/BackendTesting/FiltersTesting.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace BackendTesting
8
{
9
    public class FiltersTesting
10
    {
11
    }
12
}
Backend/BackendTesting/ImportExportTesting.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace BackendTesting
8
{
9
    public class ImportExportTesting
10
    {
11
    }
12
}
Backend/BackendTesting/LoginTesting.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace BackendTesting
8
{
9
    public class LoginTesting
10
    {
11
    }
12
}
Backend/BackendTesting/MainTestingClass.cs
1
using Microsoft.EntityFrameworkCore;
2
using Microsoft.Extensions.Logging;
3
using Microsoft.VisualStudio.TestTools.UnitTesting;
4

  
5
using System;
6
using System.Collections;
7
using System.Collections.Generic;
8
using System.Threading;
9

  
10
namespace BackendTesting
11
{
12

  
13

  
14
    [TestClass]
15
    public class MainTestingClass
16
    {
17
        //public TestContext context = new TestContext();
18
        [TestMethod]
19
        public void runAll()
20
        {
21
            
22

  
23
        } 
24

  
25

  
26
        /*
27
        public IWebDriver fDriver = new FirefoxDriver();
28
        public IWebDriver cDriver = new ChromeDriver();
29
        [TestMethod]
30
        public void DummyTutorial()
31
        {
32
            var webDriver = cDriver; //potrebuje "using selenium a chrome (firefox)
33
            //priprava promennych
34
            By googleSearchBar = By.Name("q");
35
            By googleSearchButton = By.Name("btnK");
36
            By searchName = By.XPath("//h2//span[text()='Elden Ring']");
37
            By googleCoockieAggreementButton = By.Id("L2AGLb");
38

  
39
            //prace s driverem
40
            webDriver.Manage().Window.Maximize();
41
            webDriver.Navigate().GoToUrl("https://www.google.com/");    //zakladni stranka
42
            Thread.Sleep(500);
43

  
44
            webDriver.FindElement(googleCoockieAggreementButton).Click();           //odsouhlaseni coockies
45
            Thread.Sleep(500);
46

  
47
            webDriver.FindElement(googleSearchBar).SendKeys("Elden Ring");          //napsat Elden Ring do hledani
48
            Thread.Sleep(500);
49
            webDriver.FindElement(googleSearchButton).Click();                      //kliknout na button pro poslani prikazu
50
            Thread.Sleep(500);
51

  
52
            var resultText = webDriver.FindElement(searchName);                     //najit pomoci xpath pozadovany element a ulozit si ho
53

  
54
            Assert.IsTrue(resultText.Text == "Elden Ring"); //samotny test pro otestovani stazene hodnoty
55

  
56

  
57
            webDriver.Quit();                                                          //ukonceni webdriveru
58
        }
59
        */
60

  
61
    }
62
}
Backend/BackendTesting/TagsManagementTesting.cs
1
using System;
1
using Microsoft.VisualStudio.TestTools.UnitTesting;
2
using Models.Enums;
3
using Core.Entities;
4
using Serilog;
5

  
6
using System;
2 7
using System.Collections.Generic;
3 8
using System.Linq;
4 9
using System.Text;
5 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;
6 18

  
7 19
namespace BackendTesting
8 20
{
21
    [TestClass]
9 22
    public class TagsManagementTesting
10 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
        */
11 150
    }
12 151
}

Také k dispozici: Unified diff