Projekt

Obecné

Profil

Stáhnout (2.2 KB) Statistiky
| Větev: | Tag: | Revize:
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 773d1205 schenkj
19 782b6d38 Vojtěch Bartička
namespace Core.Services
20 773d1205 schenkj
{
21 782b6d38 Vojtěch Bartička
    public class Utils
22
    {
23
    }
24
25
    public static class TestingMapper
26
    {
27
        public static IMapper GetMapper()
28
        {
29
            var mapperConfig = new MapperConfiguration(cfg =>
30
            {
31
                cfg.AddProfile<DocumentProfileEF>();
32
                cfg.AddProfile<UserProfileEF>();
33
                cfg.AddProfile<TagProfileEF>();
34
            });
35
36
            IMapper mapper = mapperConfig.CreateMapper();
37
            return mapper;
38
        }
39
    }
40
    public static class TestingLogger
41 773d1205 schenkj
    {
42 782b6d38 Vojtěch Bartička
        public static ILogger GetLogger() 
43
        {
44
            return new LoggerConfiguration().WriteTo.Console().CreateLogger(); /* logger */
45
        }
46 773d1205 schenkj
    }
47 ea53e0e1 schenkj
48
    public static class TestingUserService
49
    {
50
        private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
51
       
52
        public static IUserService GetUserService()
53
        {
54
            return new UserServiceEF(new DatabaseContext(configuration), TestingLogger.GetLogger(), TestingMapper.GetMapper()); 
55
        }
56
    }
57 ba13a48a schenkj
58
    public static class TestingJwtUtils
59
    {
60
        public static IOptions<JwtConfig> jwtConfig = Options.Create<JwtConfig>(new JwtConfig() { Issuer = "asd", Secret = "WTaDxVUWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKF3AXX9YqM2ukx98mKF" });
61
        public static IJwtUtils GetJwtUtils()
62
        {
63
            ConfigurationManager m = new ConfigurationManager();
64
            m["JwtConfig:Secret"] = "WTaDxVUWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKFWTaDxVU3AXX9YqM2ukx98mKF3AXX9YqM2ukx98mKF";
65
            m["JwtConfig:Issuer"] = "asd";
66
            var tokenValidationParams = JwtUtils.GetTokenValidationParameters(m);
67
            return new JwtUtils(jwtConfig, tokenValidationParams);
68
        }
69
    }
70 773d1205 schenkj
}