public void GetCurrencyValidationRegexTest(string cultureInfoStr, int maxGoups, int maxDecimalPoints, string expected) { CultureInfo cultureInfo = new CultureInfo(cultureInfoStr); CurrencyValidator currencyValidator = new CurrencyValidator(cultureInfo, maxGoups, maxDecimalPoints); Assert.Equal(currencyValidator.GetCurrencyValidationRegex(), expected); }
public void IsValidTest(string cultureInfoStr, string amountInNumbers, bool expected) { CultureInfo cultureInfo = new CultureInfo(cultureInfoStr); CurrencyValidator currencyValidator = new CurrencyValidator(cultureInfo, 6, 2); Assert.Equal(currencyValidator.IsValid(amountInNumbers), expected); }
public MoneyCoverter(CultureInfo cultureInfo, int maxGroupCount, int maxCurrencyDigits) { this.cultureInfo = cultureInfo; groupCount = maxGroupCount; currencyDigits = maxCurrencyDigits; currencyValidator = new CurrencyValidator(this.cultureInfo, groupCount, currencyDigits); }
public void GetCurrencyValidationRegexArguementTest() { CultureInfo cultureInfo = CultureInfo.CurrentCulture; Assert.Throws <ArgumentException>(() => { CurrencyValidator currencyValidator = new CurrencyValidator(cultureInfo, 0, 2); }); Assert.Throws <ArgumentException>(() => { CurrencyValidator currencyValidator = new CurrencyValidator(cultureInfo, 1, 0); }); }
public void IsValidCurrencyInvalidInput() { ICurrencyValidator validator = new CurrencyValidator(); string name = "USX"; bool result = validator.IsCurrencyValid(name); Assert.False(result); }
public void IsValidCurrency() { ICurrencyValidator validator = new CurrencyValidator(); string name = "USD"; bool result = validator.IsCurrencyValid(name); Assert.True(result); }
public void WhenCurrencyNotSupported_ShouldReturnFalse(string currencyCode) { // Arrange var subject = new CurrencyValidator(); // Act var result = subject.IsCurrencySupported(currencyCode); // Assert Assert.That(result, Is.False); }
public string ConvertCurrencyToWords(decimal currency) { if (!CurrencyValidator.IsValid(currency)) { throw new InvalidOperationException("Currency is out of range!"); } int dollars = (int)Math.Floor(currency); int cents = (int)((currency - dollars) * 100); return($"{GetDollarPartString(dollars)}{GetCentsPartString(cents)}"); }
public IDataResult <Currency> Create(CurrencyDto currencyDto) { var validator = new CurrencyValidator(); var validateResult = validator.Validate(currencyDto); if (!validateResult.IsValid) { var errorResults = ValidationHelper.GetErrors(validateResult.Errors); return(new ErrorDataResult <Currency>("Para birimi ekleme işlemi başarısız oldu.", errorResults)); } currencyDto.Code = currencyDto.Code.ToUpper(); var addedCurrency = _currencyDal.Add(Mapping.Mapper.Map <Currency>(currencyDto)); return(new SuccessDataResult <Currency>(addedCurrency, "Para birimi başarıyla eklendi.")); }
public void SetUp() { // Boilerplate _mockRepository = new MockRepository(MockBehavior.Strict); _fixture = new Fixture(); // Mock setup _options = _mockRepository.Create <IOptionsMonitor <SupportedCurrencyProvider> >(); // Mock default SetupMockDefaults(); // Sut instantiation _currencyValidator = new CurrencyValidator( _options.Object ); }
public ResponseBase <TBL_SLI_CURRENCY> Insert(TBL_SLI_CURRENCY currency) { CurrencyValidator validator; try { validator = new CurrencyValidator(); _results = validator.Validate(currency); if (_results.IsValid) { currency.BIT_ACTIVE = true; currency.VCH_NAME = currency.VCH_NAME.ToUpper(); currency.VCH_SYMBOL = currency.VCH_SYMBOL.ToUpper(); var currencyFound = _context.TBL_SLI_CURRENCY.Where(x => x.VCH_NAME.Contains(currency.VCH_NAME)).FirstOrDefault(); _response = new UtilityResponse <TBL_SLI_CURRENCY>().SetResponseBaseForUniqueValidation(); if (currencyFound == null) { _context.TBL_SLI_CURRENCY.Add(currency); _context.SaveChanges(); _response = new UtilityResponse <TBL_SLI_CURRENCY>().SetResponseBaseForObj(currency); } } else { _response = new UtilityResponse <TBL_SLI_CURRENCY>().SetResponseBaseFunctionalErrors(_results); } return(_response); } catch (Exception ex) { _response = new UtilityResponse <TBL_SLI_CURRENCY>().SetResponseBaseForException(ex); return(_response); } finally { _response = null; _results = null; validator = null; _context.Database.Connection.Close(); } }
public IActionResult Get( double amount, String baseCurrency, String targetCurrency) { _logger.LogInformation($"[START] Search Params: amount:{amount}; baseCurrency:${baseCurrency}; targetCurrency: {targetCurrency};"); var errors = CurrencyValidator.ValidateInput(baseCurrency, targetCurrency); if (errors.Count() == 0) { CurrencyManager converter = new CurrencyManager(); CurrencyConverterResponse res = new CurrencyConverterResponse(); res.conversion = converter.Convert(amount, baseCurrency, targetCurrency); _logger.LogInformation($"[END] conversion:{res.conversion};"); return(Ok(res)); } else { return(BadRequest(new { errors })); } }
public CurrencyService(ICurrencyRepository currencyRepository) { this._currencyRepository = currencyRepository; _avaiableCurrencies = _currencyRepository.GetAll(); _validator = new CurrencyValidator(); }
public void Setup() { this.currencyValidator = new CurrencyValidator(); }
public CurrencyValidatorShould(ITestOutputHelper output) { _output = output; _sut = new CurrencyValidator(); Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="CurrencyServices" /> class. /// </summary> /// <param name="repository">The repository.</param> public CurrencyServices(IRepositoryCurrency repository) { this.repository = repository; this.validator = new CurrencyValidator(); }
/// <summary> /// Sets the value of the IsValid property. /// </summary> private void SetIsValid() { IsValid = CurrencyValidator.IsValid(USDCurrency); }