Esempio n. 1
0
        public ArticlesControllerTest()
        {
            var logFactory = LoggerFactory.Create(builder => builder.AddConsole());
            var logger     = logFactory.CreateLogger <ArticlesController>();
            var notificationServiceFake = new NotificationServiceFake();
            var databaseService         = new DatabaseServiceFake();

            var requestModel = new RegisterRequest()
            {
                Email = "*****@*****.**", Name = "Tester", Password = "******"
            };
            var user = new User(requestModel)
            {
                Id = ObjectId.GenerateNewId().ToString()
            };

            var currentUser = databaseService.SaveUserAsync(user).Result;

            var claims = new[]
            {
                new Claim(ClaimTypes.Name, currentUser.Name),
                new Claim(ClaimTypes.NameIdentifier, currentUser.Id)
            };

            var httpContextAccessFake = new HttpContextAccessorFake(claims);

            currentUserId = httpContextAccessFake.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;



            ariclesController = new ArticlesController(httpContextAccessFake, databaseService, logger);
        }
Esempio n. 2
0
        public UsersControllerTest()
        {
            var logFactory              = LoggerFactory.Create(builder => builder.AddConsole());
            var logger                  = logFactory.CreateLogger <UsersController>();
            var httpContextAccessFake   = new HttpContextAccessorFake();
            var databaseService         = new DatabaseServiceFake();
            var notificationServiceFake = new NotificationServiceFake();

            jwtTokenHelper = new JwtTokenHelper(new JwtSettingsFake());

            usersController = new UsersController(httpContextAccessFake, databaseService, jwtTokenHelper, notificationServiceFake, logger);
        }
        public CommentsControllerTest()
        {
            var logFactory = LoggerFactory.Create(builder => builder.AddConsole());
            var logger     = logFactory.CreateLogger <CommentsController>();
            var notificationServiceFake = new NotificationServiceFake();
            var databaseService         = new DatabaseServiceFake();

            var requestModel = new RegisterRequest()
            {
                Email = "*****@*****.**", Name = "Tester", Password = "******"
            };
            var user = new User(requestModel)
            {
                Id = ObjectId.GenerateNewId().ToString()
            };

            var currentUser = databaseService.SaveUserAsync(user).Result;

            var articleRequest = new ArticleBasicInfo()
            {
                Title = "title", Abstract = "abstract", Content = "content"
            };
            var article = new Article(articleRequest, currentUserId);

            article.Id = SAMPLE_ARTICLE_ID;
            var sampleArticle = databaseService.SaveArticleAsync(article).Result;

            var claims = new[]
            {
                new Claim(ClaimTypes.Name, currentUser.Name),
                new Claim(ClaimTypes.NameIdentifier, currentUser.Id)
            };

            var httpContextAccessFake = new HttpContextAccessorFake(claims);

            currentUserId = httpContextAccessFake.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            commentsController = new CommentsController(httpContextAccessFake, databaseService, logger);
        }