Пример #1
0
        public async void SetDefaultAsync_Choose_Regulation_Rule_With_Most_Priority()
        {
            // arrange
            const string clientId = "me";
            const string country  = "uk";

            WelcomeRegulationRule rule1 = Create("1", "reg_1", country, true, 10);
            WelcomeRegulationRule rule2 = Create("2", "reg_2", country, true, 100);

            IClientRegulation result = null;

            _clientRegulationRepositoryMock.Setup(o => o.GetByClientIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <ClientRegulation>());

            _clientRegulationRepositoryMock.Setup(o => o.AddAsync(It.IsAny <IClientRegulation>()))
            .Returns(Task.CompletedTask)
            .Callback((IClientRegulation o) => result = o);

            _welcomeRegulationRuleRepositoryMock.Setup(o => o.GetByCountryAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <WelcomeRegulationRule>
            {
                rule1,
                rule2
            });

            // act
            await _service.SetDefaultAsync(clientId, country);

            // assert
            Assert.NotNull(result);
            Assert.Equal(result.RegulationId, rule2.RegulationId);
            Assert.Equal(result.Active, rule2.Active);
        }
Пример #2
0
        public async void AddAsync_Ok()
        {
            // arrange
            const string regulationId = "ID";
            const string clientId     = "me";

            IClientRegulation result = null;

            _regulationRepositoryMock.Setup(o => o.GetAsync(It.IsAny <string>()))
            .ReturnsAsync(new Core.Domain.Regulation
            {
                Id = regulationId
            });

            _clientRegulationRepositoryMock.Setup(o => o.AddAsync(It.IsAny <IClientRegulation>()))
            .Returns(Task.FromResult(false))
            .Callback((IClientRegulation p) => result = p);

            // act
            await _service.AddAsync(new ClientRegulation
            {
                ClientId     = clientId,
                RegulationId = regulationId
            });

            // assert
            Assert.NotNull(result);
        }
Пример #3
0
        public async Task <IClientRegulation> GetAsync(string clientId, string regulationId)
        {
            IClientRegulation clientRegulation = await _clientRegulationRepository.GetAsync(clientId, regulationId);

            if (clientRegulation == null)
            {
                throw new ServiceException("Client regulation not found.");
            }

            return(clientRegulation);
        }
Пример #4
0
        public Task UpdateAsync(IClientRegulation clientRegulation)
        {
            string partitionKey = GetPartitionKey(clientRegulation.ClientId);
            string rowKey       = GetRowKey(clientRegulation.RegulationId);

            return(_tableStorage.MergeAsync(partitionKey, rowKey, entity =>
            {
                entity.Kyc = clientRegulation.Kyc;
                entity.Active = clientRegulation.Active;
                return entity;
            }));
        }
Пример #5
0
 private static ClientRegulationEntity Create(IClientRegulation clientRegulation)
 {
     return(new ClientRegulationEntity
     {
         RowKey = GetRowKey(clientRegulation.RegulationId),
         PartitionKey = GetPartitionKey(clientRegulation.ClientId),
         ClientId = clientRegulation.ClientId,
         RegulationId = clientRegulation.RegulationId,
         Kyc = false,
         Active = clientRegulation.Active
     });
 }
Пример #6
0
        public async Task UpdateActiveAsync(string clientId, string regulationId, bool state)
        {
            IClientRegulation clientRegulation = await _clientRegulationRepository.GetAsync(clientId, regulationId);

            if (clientRegulation == null)
            {
                throw new ServiceException("Client regulation not found.");
            }

            clientRegulation.Active = state;

            await _clientRegulationRepository.UpdateAsync(clientRegulation);

            await PublishOnChangedAsync(clientId);
        }
Пример #7
0
        public async Task AddAsync(IClientRegulation clientRegulation)
        {
            IRegulation result = await _regulationRepository.GetAsync(clientRegulation.RegulationId);

            if (result == null)
            {
                throw new ServiceException("Regulation not found.");
            }

            if (await _clientRegulationRepository.GetAsync(clientRegulation.ClientId, clientRegulation.RegulationId) != null)
            {
                throw new ServiceException("Client regulation already exists.");
            }

            await _clientRegulationRepository.AddAsync(clientRegulation);

            await PublishOnChangedAsync(clientRegulation.ClientId);

            _log.Info(nameof(AddAsync), $"Regulation '{clientRegulation.RegulationId}' added for client.", clientRegulation.ClientId);
        }
Пример #8
0
        public async Task DeleteAsync(string clientId, string regulationId)
        {
            IClientRegulation clientRegulation = await _clientRegulationRepository.GetAsync(clientId, regulationId);

            if (clientRegulation == null)
            {
                throw new ServiceException("Client regulation not found.");
            }

            if (clientRegulation.Kyc)
            {
                throw new ServiceException("Can not delete KYC client regulation.");
            }

            if (clientRegulation.Active)
            {
                throw new ServiceException("Can not delete active client regulation.");
            }

            await _clientRegulationRepository.DeleteAsync(clientId, regulationId);

            await PublishOnChangedAsync(clientId);
        }
Пример #9
0
 public Task AddAsync(IClientRegulation clientRegulation)
 {
     return(_tableStorage.InsertThrowConflict(Create(clientRegulation)));
 }