public async Task Add(RoleAddUICommand command)
        {
            if (_roleRepository.GetAll().Any(x => x.Name == command.Role.Name && !x.IsDeleted))
            {
                throw new LogicServiceException(ErrorMessage.RoleNameIsExisted);
            }

            var role = Role.Create(command.Role.Name, command.Role.Memo,
                                   _userAuthenticationManager.CurrentUser.UserId, _timeSource.GetCurrentTime());

            using var unitOfWork = _unitOfWorkFactory.GetCurrentUnitOfWork();
            _roleRepository.Add(role);
            await unitOfWork.Commit();
        }
Ejemplo n.º 2
0
        public async Task Add(UserAddUICommand command)
        {
            var newUser = User.Create(command.User.UserName,
                                      _initialPassword,
                                      command.User.TrueName,
                                      command.User.Gender,
                                      command.User.CardId,
                                      command.User.Phone,
                                      command.User.RoleId,
                                                  //_userAuthenticationManager.CurrentUser.UserId,
                                      Guid.Empty, // TODO:后期用IdentityServer4来解决
                                      _timeSource.GetCurrentTime());

            using var unitOfWork = _unitOfWorkFactory.GetCurrentUnitOfWork();
            _userRepository.Add(newUser);
            await unitOfWork.Commit();
        }
Ejemplo n.º 3
0
        public void Choke_SatisfiesRequestsWheNotDepleted()
        {
            var startTime = DateTimeOffset.UtcNow;

            _timeSource.GetCurrentTime().Returns(startTime);

            var choke = new Choke(DataRate.FromBytesPerSecond(10000), new TimeSourceStopwatch(_timeSource));

            // The test is ignorant of the internal buffers but this must surely deplete it.
            for (var i = 0; i < 100; i++)
            {
                choke.RequestBytes(100);
            }

            Assert.IsFalse(choke.RequestBytes(100));

            // After a second there should be some capacity available gain.
            _timeSource.GetCurrentTime().Returns(startTime.AddSeconds(1));

            Assert.IsTrue(choke.RequestBytes(100));
        }
Ejemplo n.º 4
0
 public ExpiringCollectionTests()
 {
     _timeSource.GetCurrentTime().Returns(ci => _now);
 }
Ejemplo n.º 5
0
 public void Restart()
 {
     _elapsedInPreviousRuns = default;
     _startTime             = _timeSource.GetCurrentTime();
 }