1 |
782b6d38
|
Vojtěch Bartička
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2 |
|
|
using Models.Enums;
|
3 |
|
|
using Core.Entities;
|
4 |
|
|
using Serilog;
|
5 |
|
|
|
6 |
|
|
using System;
|
7 |
773d1205
|
schenkj
|
using System.Collections.Generic;
|
8 |
|
|
using System.Linq;
|
9 |
|
|
using System.Text;
|
10 |
|
|
using System.Threading.Tasks;
|
11 |
782b6d38
|
Vojtěch Bartička
|
using Microsoft.EntityFrameworkCore;
|
12 |
|
|
using AutoMapper;
|
13 |
|
|
using Core.MapperProfiles;
|
14 |
ea53e0e1
|
schenkj
|
using Microsoft.Extensions.Configuration;
|
15 |
|
|
using Core.Contexts;
|
16 |
ba13a48a
|
schenkj
|
using Microsoft.Extensions.Options;
|
17 |
|
|
using Core.Authentication;
|
18 |
0f58bb56
|
schenkj
|
using Microsoft.EntityFrameworkCore.Design;
|
19 |
773d1205
|
schenkj
|
|
20 |
065f6462
|
schenkj
|
using Core.Services;
|
21 |
|
|
|
22 |
|
|
namespace BackendTesting
|
23 |
773d1205
|
schenkj
|
{
|
24 |
782b6d38
|
Vojtěch Bartička
|
public class Utils
|
25 |
|
|
{
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
public static class TestingMapper
|
29 |
|
|
{
|
30 |
|
|
public static IMapper GetMapper()
|
31 |
|
|
{
|
32 |
|
|
var mapperConfig = new MapperConfiguration(cfg =>
|
33 |
|
|
{
|
34 |
|
|
cfg.AddProfile<DocumentProfileEF>();
|
35 |
|
|
cfg.AddProfile<UserProfileEF>();
|
36 |
|
|
cfg.AddProfile<TagProfileEF>();
|
37 |
|
|
});
|
38 |
|
|
|
39 |
|
|
IMapper mapper = mapperConfig.CreateMapper();
|
40 |
|
|
return mapper;
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
public static class TestingLogger
|
44 |
773d1205
|
schenkj
|
{
|
45 |
0f58bb56
|
schenkj
|
public static ILogger GetLogger()
|
46 |
782b6d38
|
Vojtěch Bartička
|
{
|
47 |
|
|
return new LoggerConfiguration().WriteTo.Console().CreateLogger(); /* logger */
|
48 |
|
|
}
|
49 |
773d1205
|
schenkj
|
}
|
50 |
ea53e0e1
|
schenkj
|
|
51 |
|
|
public static class TestingUserService
|
52 |
|
|
{
|
53 |
|
|
private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
|
54 |
0f58bb56
|
schenkj
|
|
55 |
ea53e0e1
|
schenkj
|
public static IUserService GetUserService()
|
56 |
|
|
{
|
57 |
0f58bb56
|
schenkj
|
return new UserServiceEF(new DatabaseContext(configuration), TestingLogger.GetLogger(), TestingMapper.GetMapper());
|
58 |
ea53e0e1
|
schenkj
|
}
|
59 |
|
|
}
|
60 |
ba13a48a
|
schenkj
|
|
61 |
|
|
public static class TestingJwtUtils
|
62 |
|
|
{
|
63 |
|
|
public static IOptions<JwtConfig> jwtConfig = Options.Create<JwtConfig>(new JwtConfig() { Issuer = "asd", Secret = "WTaDxVUWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKF3AXX9YqM2ukx98mKF" });
|
64 |
|
|
public static IJwtUtils GetJwtUtils()
|
65 |
|
|
{
|
66 |
|
|
ConfigurationManager m = new ConfigurationManager();
|
67 |
|
|
m["JwtConfig:Secret"] = "WTaDxVUWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKF3AXX9YqM2ukx98mKF";
|
68 |
|
|
m["JwtConfig:Issuer"] = "asd";
|
69 |
|
|
var tokenValidationParams = JwtUtils.GetTokenValidationParameters(m);
|
70 |
|
|
return new JwtUtils(jwtConfig, tokenValidationParams);
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
773d1205
|
schenkj
|
}
|