< Summary

Class:SVETA.Api.Controllers.TestDatasets
Assembly:SVETA.Api
File(s):/opt/dev/sveta_api_build/SVETA.Api/Controllers/TestDatasetsController.cs
Covered lines:0
Uncovered lines:41
Coverable lines:41
Total lines:129
Line coverage:0% (0 of 41)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodLine coverage Branch coverage
.ctor(...)0%100%
GetUserInfo()0%0%
ReturnStatusCode()0%100%

File(s)

/opt/dev/sveta_api_build/SVETA.Api/Controllers/TestDatasetsController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading.Tasks;
 5using Microsoft.AspNetCore.Http;
 6using Microsoft.AspNetCore.Mvc;
 7using Microsoft.Extensions.Logging;
 8using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 9using WinSolutions.Sveta.Server.Services.Interfaces;
 10using WinSolutions.Sveta.Server.Data.DataModel.Kinds;
 11using Swashbuckle.AspNetCore.Annotations;
 12using System.Net;
 13using System.Net.Http;
 14using System.Net.Http.Headers;
 15
 16namespace SVETA.Api.Controllers
 17{
 18    //Контроллер для генерации и удаления данных для ручных тестов
 19    [Route("api/v1/TestDatasets")]
 20    [ApiController]
 21    public class TestDatasets : SvetaController
 22    {
 23        private readonly IContragentService _contragentService;
 24        private readonly ISupplyContractService _supplyContractService;
 25        private readonly IDepartmentService _departmentService;
 26        private readonly IClusterService _clusterService;
 27        private readonly ICategoryService _categoryService;
 28        private readonly IBrandService _brandService;
 29        private readonly IGoodService _goodService;
 30        private readonly IDirectoriesService _dirService;
 31        private readonly ITaxSystemService _taxSystemService;
 32        private readonly IAddressService _addressService;
 33        private readonly IGoodSettingService _serviceGoodSetting;
 34        private readonly ICategoryRatioService _serviceCategoryRatio;
 35
 36
 37        List<Contragent> _contragentList;
 38        List<Department> _departmentList;
 39        List<Category> _categoriesList;
 40        List<Good> _goodList;
 41        RecordsState _activeState;
 42
 43
 44        public TestDatasets(
 45            IContragentService contragentService,
 46            ISupplyContractService supplyContractService,
 47            IDepartmentService departmentService,
 48            IClusterService clusterService,
 49            ICategoryService categoryService,
 50            IBrandService brandService,
 51            IGoodService goodService,
 52            IDirectoriesService dirService,
 53            ITaxSystemService taxSystemService,
 54            IAddressService addressService,
 55            IGoodSettingService serviceGoodSetting,
 56            ICategoryRatioService serviceCategoryRatio,
 57            ILogger<GoodsController> logger
 058        ): base(logger)
 059        {
 060            _contragentService = contragentService;
 061            _supplyContractService = supplyContractService;
 062            _departmentService = departmentService;
 063            _clusterService = clusterService;
 064            _categoryService = categoryService;
 065            _brandService = brandService;
 066            _goodService = goodService;
 067            _dirService = dirService;
 068            _taxSystemService = taxSystemService;
 069            _addressService = addressService;
 070            _serviceGoodSetting = serviceGoodSetting;
 071            _serviceCategoryRatio = serviceCategoryRatio;
 72
 073            _contragentList = new List<Contragent>();
 074            _departmentList = new List<Department>();
 075            _categoriesList = new List<Category>();
 076            _goodList = new List<Good>();
 077        }
 78
 79
 80
 81        /// <summary>
 82        /// Создаёт запрос на user-info к ВТБК
 83        /// </summary>
 84        /// <remarks>author: nko</remarks>
 85        /// <param name="token">access_token для доступа к сервису</param>
 86        [HttpGet("{token}")]
 87        [SwaggerResponse(200, "Успешно")]
 88        [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(string))]
 89        public async Task<IActionResult> GetUserInfo(string token)
 090        {
 91            try
 092            {
 093                HttpClient client = new HttpClient();
 094                string res = "Error";
 95
 096                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
 097                HttpResponseMessage response = await client.GetAsync("https://stage.id.vtbconnect.ru/connect/userinfo");
 098                if (response.IsSuccessStatusCode)
 099                {
 0100                    res = await response.Content.ReadAsStringAsync();
 0101                }
 0102                return Ok(res);
 103            }
 0104            catch(Exception e)
 0105            {
 0106                return ServerError(e);
 107            }
 0108        }
 109        /// <summary>
 110        /// Возвращает ошибку с соответствующим статус кодом
 111        /// </summary>
 112        /// <remarks>author: nko</remarks>
 113        /// <param name="code">Код желаемого кода ответа</param>
 114        [HttpGet("StatusCode/{code}")]
 115        [SwaggerResponse(200, "Успешно")]
 116        [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(string))]
 117        public async Task<IActionResult> ReturnStatusCode(int code)
 0118        {
 119            try
 0120            {
 0121                return StatusCode(code);
 122            }
 0123            catch(Exception e)
 0124            {
 0125                return ServerError(e);
 126            }
 0127        }
 128    }
 129}