Projekt

Obecné

Profil

Stáhnout (2.25 KB) Statistiky
| Větev: | Tag: | Revize:
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 Microsoft.Extensions.Configuration;
15
using Core.Contexts;
16
using Microsoft.Extensions.Options;
17
using Core.Authentication;
18
using Microsoft.EntityFrameworkCore.Design;
19

    
20
using Core.Services;
21

    
22
namespace BackendTesting
23
{
24
    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
    {
45
        public static ILogger GetLogger()
46
        {
47
            return new LoggerConfiguration().WriteTo.Console().CreateLogger(); /* logger */
48
        }
49
    }
50

    
51
    public static class TestingUserService
52
    {
53
        private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
54

    
55
        public static IUserService GetUserService()
56
        {
57
            return new UserServiceEF(new DatabaseContext(configuration), TestingLogger.GetLogger(), TestingMapper.GetMapper());
58
        }
59
    }
60

    
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
}
(6-6/6)