Ejemplo n.º 1
0
        /// <summary>
        /// Получить аутентифицированного сотрудника
        /// </summary>
        /// <returns></returns>
        public async Task <BaseEmployee> GetEmployee()
        {
            //Получаем имя сотрудника
            string name = GetEmployeeName();
            //Аутентифицируем сотрудника по имени
            var employee = await _autorizeService.AutentificatedUser(name);

            if (employee == null)
            {
                return(null);
            }

            return(employee);
        }
        public void AutorizatedUser_ShoultReturnAutorizeOrNull()
        {
            string name = "Алексей";
            Guid   id   = Guid.NewGuid();

            _repository
            .Setup(method => method.GetEmployeeByNameAsync(name))
            .ReturnsAsync(new StaffEmployee(id, "Алексей", "Алексеев", Departments.IT, 100_000));

            var user         = _service.AutentificatedUser(name).Result;
            var userNull     = _service.AutentificatedUser("").Result;
            var userNullName = _service.AutentificatedUser("Test").Result;

            var result     = _service.GetAuthorization(user);
            var resultNull = _service.GetAuthorization(userNull);

            Assert.IsNotNull(user);
            Assert.IsNull(userNull);
            Assert.IsNull(userNullName);

            Assert.IsNull(resultNull);
            Assert.AreEqual(id, result.UserId);
            Assert.AreEqual(Role.Developer, result.UserRole);
        }