public async void UpdateActiveAsync_OK() { // arrange const string regulationId = "ID"; const string clientId = "me"; var clientRegulation = new ClientRegulation { Id = "0", ClientId = clientId, RegulationId = regulationId, Active = false, Kyc = false }; _clientRegulationRepositoryMock.Setup(o => o.GetAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(clientRegulation); _clientRegulationRepositoryMock.Setup(o => o.UpdateAsync(It.IsAny <IClientRegulation>())) .Returns(Task.CompletedTask); // act await _service.UpdateActiveAsync(clientId, regulationId, true); // assert Assert.True(clientRegulation.Active); }
public async Task SetDefaultAsync(string clientId, string country) { IEnumerable <IClientRegulation> clientRegulations = await _clientRegulationRepository.GetByClientIdAsync(clientId); if (clientRegulations.Any()) { throw new ServiceException("Client already have regulations."); } IWelcomeRegulationRule welcomeRegulationRule = null; if (!string.IsNullOrEmpty(country)) { IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules = await _welcomeRegulationRuleRepository.GetByCountryAsync(country); welcomeRegulationRule = welcomeRegulationRules .OrderByDescending(o => o.Priority) .FirstOrDefault(); } if (welcomeRegulationRule == null) { IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules = await _welcomeRegulationRuleRepository.GetDefaultAsync(); welcomeRegulationRule = welcomeRegulationRules .OrderByDescending(o => o.Priority) .FirstOrDefault(); } if (welcomeRegulationRule == null) { throw new ServiceException("No default regulations."); } var defaultClientRegulation = new ClientRegulation { ClientId = clientId, RegulationId = welcomeRegulationRule.RegulationId, Active = welcomeRegulationRule.Active, Kyc = false }; await _clientRegulationRepository.AddAsync(defaultClientRegulation); await PublishOnChangedAsync(defaultClientRegulation.ClientId); _log.Info(nameof(SetDefaultAsync), $"Default regulation '{defaultClientRegulation.RegulationId}' added for client.", defaultClientRegulation.ClientId); }
public async Task ChangeRegulationAsync(string clientId, string country) { List <IClientRegulation> clientRegulations = (await _clientRegulationRepository.GetByClientIdAsync(clientId)).ToList(); IWelcomeRegulationRule welcomeRegulationRule = (await _welcomeRegulationRuleRepository.GetByCountryAsync(country)) .OrderByDescending(o => o.Priority) .FirstOrDefault(); if (welcomeRegulationRule == null) { IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules = await _welcomeRegulationRuleRepository.GetDefaultAsync(); welcomeRegulationRule = welcomeRegulationRules .OrderByDescending(o => o.Priority) .FirstOrDefault(); } if (welcomeRegulationRule != null && clientRegulations.All(item => item.RegulationId != welcomeRegulationRule.RegulationId)) { foreach (var regulation in clientRegulations.Where(item => item.Kyc == false)) { await _clientRegulationRepository.DeleteAsync(clientId, regulation.RegulationId); } var newRegulation = new ClientRegulation { ClientId = clientId, RegulationId = welcomeRegulationRule.RegulationId, Active = welcomeRegulationRule.Active, Kyc = false }; await _clientRegulationRepository.AddAsync(newRegulation); await PublishOnChangedAsync(clientId); } }