public void WhenUnregisterIsoCurrency_ThenThisMustSucceed() { _ = Currency.FromCode("PEN"); // should work CurrencyBuilder.Unregister("PEN", "ISO-4217"); Action action = () => Currency.FromCode("PEN"); action.Should().Throw <ArgumentException>().WithMessage("*unknown*currency*"); }
public static NodaMoney.Money ToNodaMoney(this HighPrecisionMoney money, MidpointRounding midpointRounding = MidpointRounding.ToEven) { var builder = new CurrencyBuilder(money.CurrencyCode, "HighPrecision"); builder.LoadDataFromCurrency(Currency.FromCode(money.CurrencyCode)); builder.DecimalDigits = money.FractionDigits.GetValueOrDefault(); return(new NodaMoney.Money(money.AmountToDecimal(), builder.Build(), midpointRounding)); }
public void WhenRegisterAsSimpleAsPossible_ThenShouldBeAvailableWithDefaults() { var result = new CurrencyBuilder("BTC4", "ISO-4217").Register(); var bitcoin = Currency.FromCode("BTC4"); bitcoin.Namespace.Should().Be("ISO-4217"); bitcoin.Symbol.Should().Be(Currency.GenericCurrencySign); // ¤ bitcoin.Should().BeEquivalentTo(result); }
public void WhenRegisterExistingCurrency_ThenThrowExeception() { var builder = new CurrencyBuilder("EUR", "ISO-4217"); var euro = Currency.FromCode("EUR"); builder.LoadDataFromCurrency(euro); Action action = () => builder.Register(); action.Should().Throw <InvalidOperationException>().WithMessage("The custom currency is already registered."); }
private void Del_req_base_btn_Click(object sender, EventArgs e) { try { Cond_lbl.Text = intcond; base_dGV.DataSource = CurrencyBuilder.ClearBase(); Cond_lbl.Text += "Обновлено"; } catch (Exception ee) { Cond_lbl.Text += ee.Message; } }
private void Update_direct_btn_Click(object sender, EventArgs e) { Cond_lbl.Text = intcond; try { CurrencyBuilder.UpdateBase_fromTable_xml(dateTimePicker1.Value); Cond_lbl.Text += "Запись произошла"; } catch (Exception ee) { Cond_lbl.Text += ee.Message; } }
private void ToUpload_btn_Click(object sender, EventArgs e) { Cond_lbl.Text = intcond; try { CurrencyBuilder.UpdateBase_fromTable((System.Data.DataTable)dGV_out.DataSource); Cond_lbl.Text += "Запись произошла"; } catch (Exception ee) { Cond_lbl.Text += ee.Message; } }
public void ConvertToMoney() { var builder = new CurrencyBuilder("EUR", "HighPrecision"); builder.LoadDataFromCurrency(Currency.FromCode("EUR")); builder.DecimalDigits = 4; var nm = new NodaMoney.Money(1234.5678m, builder.Build()); var m = nm.ToCtpMoney(); Assert.IsType <Money>(m); Assert.Equal(123457, m.CentAmount); Assert.Equal("EUR", m.CurrencyCode); }
public void WhenSymbolIsEmpty_ThenSymbolMustBeDefaultCurrencySign() { var result = new CurrencyBuilder("BTC5", "ISO-4217") { EnglishName = "Bitcoin", //Symbol = "฿", ISONumber = "123", // iso number DecimalDigits = 8, }.Register(); var bitcoin = Currency.FromCode("BTC5"); bitcoin.Symbol.Should().Be(Currency.GenericCurrencySign); // ¤ bitcoin.Should().BeEquivalentTo(result); }
public Form1() { InitializeComponent(); intcond = Cond_lbl.Text; dateTimePicker1.Value = DateTime.Now; try { base_dGV.DataSource = CurrencyBuilder.LoadBase(); Cond_lbl.Text += "Загружено"; } catch (Exception e) { Cond_lbl.Text += e.Message; } }
public void WhenRegisterBitCoin_ThenShouldBeAvailableByExplicitNamespace() { var builder = new CurrencyBuilder("BTC1", "virtual"); builder.EnglishName = "Bitcoin"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 8; builder.IsObsolete = false; Currency result = builder.Register(); Currency bitcoin = Currency.FromCode("BTC1", "virtual"); bitcoin.Symbol.Should().Be("฿"); bitcoin.ShouldBeEquivalentTo(result); }
public void WhenUnregisterIsoCurrency_ThenThisMustSucceed() { var euro = Currency.FromCode("EUR"); // should work CurrencyBuilder.Unregister("EUR", "ISO-4217"); Action action = () => Currency.FromCode("EUR"); action.ShouldThrow <ArgumentException>().WithMessage("*unknown*currency*"); // register again for other unit-tests var builder = new CurrencyBuilder("EUR", "ISO-4217"); builder.LoadDataFromCurrency(euro); builder.Register(); }
public void WhenBuildBitCoin_ThenItShouldSuccedButNotBeRegistered() { var builder = new CurrencyBuilder("BTC2", "virtual"); builder.EnglishName = "Bitcoin"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 8; builder.IsObsolete = false; Currency result = builder.Build(); result.Symbol.Should().Be("฿"); Action action = () => Currency.FromCode("BTC2", "virtual"); action.ShouldThrow<ArgumentException>().WithMessage("BTC2 is an unknown virtual currency code!"); }
public void WhenRegisterBitCoinInIsoNamespace_ThenShouldBeAvailable() { var builder = new CurrencyBuilder("BTC", "ISO-4217"); builder.EnglishName = "Bitcoin"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 8; Currency result = builder.Register(); Currency bitcoin = Currency.FromCode("BTC"); bitcoin.Symbol.Should().Be("฿"); bitcoin.ShouldBeEquivalentTo(result); }
public void WhenUnregisterCustomCurrency_ThenThisMustSucceed() { var builder = new CurrencyBuilder("XYZ", "virtual"); builder.EnglishName = "Xyz"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 4; builder.Register(); Currency xyz = Currency.FromCode("XYZ", "virtual"); // should work CurrencyBuilder.Unregister("XYZ", "virtual"); Action action = () => Currency.FromCode("XYZ", "virtual"); action.ShouldThrow <ArgumentException>().WithMessage("*unknown*currency*"); }
public void WhenBuildBitCoin_ThenItShouldSuccedButNotBeRegistered() { var builder = new CurrencyBuilder("BTC2", "virtual"); builder.EnglishName = "Bitcoin"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 8; Currency result = builder.Build(); result.Symbol.Should().Be("฿"); Action action = () => Currency.FromCode("BTC2", "virtual"); action.ShouldThrow <ArgumentException>().WithMessage("BTC2 is an unknown virtual currency code!"); }
public void WhenFromExistingCurrency_ThenThisShouldSucceed() { var builder = new CurrencyBuilder("BTC3", "virtual"); var euro = Currency.FromCode("EUR"); builder.LoadDataFromCurrency(euro); builder.Code.Should().Be("BTC3"); builder.Namespace.Should().Be("virtual"); builder.EnglishName.Should().Be(euro.EnglishName); builder.Symbol.Should().Be(euro.Symbol); builder.ISONumber.Should().Be(euro.Number); builder.DecimalDigits.Should().Be(euro.DecimalDigits); builder.IsObsolete.Should().Be(euro.IsObsolete); builder.ValidFrom.Should().Be(euro.ValidFrom); builder.ValidTo.Should().Be(euro.ValidTo); }
public void WhenFromExistingCurrency_ThenThisShouldSucceed() { var builder = new CurrencyBuilder("BTC3", "virtual"); var euro = Currency.FromCode("EUR"); builder.LoadDataFromCurrency(euro); builder.Code.Should().Be("BTC3"); builder.Namespace.Should().Be("virtual"); builder.EnglishName.Should().Be(euro.EnglishName); builder.Symbol.Should().Be(euro.Symbol); builder.ISONumber.Should().Be(euro.Number); builder.DecimalDigits.Should().Be(euro.DecimalDigits); builder.ValidFrom.Should().Be(euro.ValidFrom); builder.ValidTo.Should().Be(euro.ValidTo); }
public void WhenRegisterBitCoin_ThenShouldBeAvailableByExplicitNamespace() { var builder = new CurrencyBuilder("BTC1", "virtual"); builder.EnglishName = "Bitcoin"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 8; builder.IsObsolete = false; Currency result = builder.Register(); Currency bitcoin = Currency.FromCode("BTC1", "virtual"); bitcoin.Symbol.Should().Be("฿"); bitcoin.ShouldBeEquivalentTo(result); }
public void WhenRegisterBitCoin_ThenShouldBeAvailableByExplicitNamespace() { var builder = new CurrencyBuilder("BTC1", "virtual") { EnglishName = "Bitcoin", Symbol = "฿", ISONumber = "123", // iso number DecimalDigits = 8 }; var result = builder.Register(); var bitcoin = Currency.FromCode("BTC1", "virtual"); bitcoin.Symbol.Should().Be("฿"); bitcoin.Should().BeEquivalentTo(result); }
public void WhenReplacingEuroWithCustom_ThenThisShouldSucceed() { Currency oldEuro = CurrencyBuilder.Unregister("EUR", "ISO-4217"); var builder = new CurrencyBuilder("EUR", "ISO-4217"); builder.LoadDataFromCurrency(oldEuro); builder.EnglishName = "New Euro"; builder.DecimalDigits = 1; builder.Register(); Currency newEuro = Currency.FromCode("EUR"); newEuro.Symbol.Should().Be("€"); newEuro.EnglishName.Should().Be("New Euro"); newEuro.DecimalDigits.Should().Be(1); }
public void WhenReplacingEuroWithCustom_ThenThisShouldSucceed() { // Panamanian balboa var oldEuro = CurrencyBuilder.Unregister("PAB", "ISO-4217"); var builder = new CurrencyBuilder("PAB", "ISO-4217"); builder.LoadDataFromCurrency(oldEuro); builder.EnglishName = "New Panamanian balboa"; builder.DecimalDigits = 1; builder.Register(); var newEuro = Currency.FromCode("PAB"); newEuro.Symbol.Should().Be("B/."); newEuro.EnglishName.Should().Be("New Panamanian balboa"); newEuro.DecimalDigits.Should().Be(1); }
public void GivenCurrencyWhenValidatingThenRequiredRelationsMustExist() { var builder = new CurrencyBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); builder.WithIsoCode("BND").Build(); Assert.True(this.Session.Derive(false).HasErrors); builder .WithLocalisedName(new LocalisedTextBuilder(this.Session) .WithText("Brunei Dollar") .WithLocale(new Locales(this.Session).FindBy(M.Locale.Name, Locales.EnglishGreatBritainName)) .Build()); Assert.False(this.Session.Derive(false).HasErrors); }
public void GivenCurrencyWhenValidatingThenRequiredRelationsMustExist() { var builder = new CurrencyBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); builder.WithIsoCode("BND").Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); builder.WithSymbol("$").Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); builder .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession) .WithText("Brunei Dollar") .WithLocale(new Locales(this.DatabaseSession).FindBy(Locales.Meta.Name, Locales.EnglishGreatBritainName)) .Build()); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void WhenReplacingEuroWithCustom_ThenThisShouldSucceed() { Currency oldEuro = CurrencyBuilder.Unregister("EUR", "ISO-4217"); var builder = new CurrencyBuilder("EUR", "ISO-4217"); builder.LoadDataFromCurrency(oldEuro); builder.EnglishName = "New Euro"; builder.DecimalDigits = 1; builder.Register(); Currency newEuro = Currency.FromCode("EUR"); newEuro.Symbol.Should().Be("€"); newEuro.EnglishName.Should().Be("New Euro"); newEuro.DecimalDigits.Should().Be(1); }
private void button1_Click(object sender, EventArgs e) { dGV_out.DataSource = CurrencyBuilder.Former(dateTimePicker1.Value); Update_table_btn.Enabled = true; }
public void WhenUnregisterCustomCurrency_ThenThisMustSucceed() { var builder = new CurrencyBuilder("XYZ", "virtual"); builder.EnglishName = "Xyz"; builder.Symbol = "฿"; builder.ISONumber = "123"; // iso number builder.DecimalDigits = 4; builder.IsObsolete = false; builder.Register(); Currency xyz = Currency.FromCode("XYZ", "virtual"); // should work CurrencyBuilder.Unregister("XYZ", "virtual"); Action action = () => Currency.FromCode("XYZ", "virtual"); action.ShouldThrow<ArgumentException>().WithMessage("*unknown*currency*"); }
public void WhenCurrencyDoesntExist_ThenThisShouldThrow() { Action action = () => CurrencyBuilder.Unregister("ABC", "virtual"); action.ShouldThrow <ArgumentException>().WithMessage("*specifies a currency that is not found*"); }
public void Sync() { var englishNameByCountry = new Dictionary<Country, string>(); var englishNameByCurrency = new Dictionary<Currency, string>(); var englishNameByLanguage = new Dictionary<Language, string>(); var countryByIsoCode = new Dictionary<string, Country>(); foreach (Country country in new Countries(this.Session).Extent()) { countryByIsoCode.Add(country.IsoCode, country); } var languageByIsoCode = new Dictionary<string, Language>(); foreach (Language language in new Languages(this.Session).Extent()) { languageByIsoCode.Add(language.IsoCode, language); } var currencyByIsoCode = new Dictionary<string, Currency>(); foreach (Currency currency in new Currencies(this.Session).Extent()) { currencyByIsoCode.Add(currency.IsoCode, currency); } var localeByName = new Dictionary<string, Locale>(); foreach (Locale locale in new Locales(this.Session).Extent()) { localeByName.Add(locale.Name, locale); } foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { if (cultureInfo.LCID != 127) { var languageIsoCode = cultureInfo.TwoLetterISOLanguageName.ToLower(); Language language; if (!languageByIsoCode.TryGetValue(languageIsoCode, out language)) { language = new LanguageBuilder(this.Session) .WithIsoCode(languageIsoCode) .Build(); languageByIsoCode.Add(languageIsoCode, language); englishNameByLanguage.Add(language, cultureInfo.Parent.EnglishName); } Country country = null; var regionInfo = new RegionInfo(cultureInfo.LCID); // Should be upper, but just in case ... var countryIsoCode = regionInfo.TwoLetterISORegionName.ToUpper(); // sometimes a 2 letter code is a 3 digit code ... if (countryIsoCode.Length == 2) { if (!countryByIsoCode.TryGetValue(countryIsoCode, out country)) { country = new CountryBuilder(this.Session).WithIsoCode(countryIsoCode).Build(); englishNameByCountry.Add(country, regionInfo.EnglishName); countryByIsoCode.Add(countryIsoCode, country); } var currencyIsoCode = regionInfo.ISOCurrencySymbol.ToUpper(); Currency currency; if (!currencyByIsoCode.TryGetValue(currencyIsoCode, out currency)) { currency = new CurrencyBuilder(this.Session).WithIsoCode(currencyIsoCode).WithSymbol(regionInfo.CurrencySymbol).Build(); currencyByIsoCode.Add(currencyIsoCode, currency); englishNameByCurrency.Add(currency, regionInfo.CurrencyEnglishName); } if (country != null) { country.Currency = currency; } } var localeIdentifier = cultureInfo.Name; Locale locale; if (!localeByName.TryGetValue(localeIdentifier, out locale)) { if (country != null && language != null) { locale = new LocaleBuilder(this.Session) .WithName(cultureInfo.Name) .WithCountry(country) .WithLanguage(language) .Build(); localeByName.Add(localeIdentifier, locale); } } else { locale.Name = cultureInfo.Name; locale.Language = language; locale.Country = country; } } } var englishLocale = localeByName[EnglishGreatBritainName]; foreach (var country in countryByIsoCode.Values) { if (englishNameByCountry.ContainsKey(country)) { var enlgishName = englishNameByCountry[country]; var englishCountryName = new LocalisedTextBuilder(this.Session) .WithText(enlgishName) .WithLocale(englishLocale) .Build(); country.Name = enlgishName; country.AddLocalisedName(englishCountryName); } } foreach (var currency in currencyByIsoCode.Values) { if (englishNameByCurrency.ContainsKey(currency)) { var englishName = englishNameByCurrency[currency]; var englishCurrencyName = new LocalisedTextBuilder(this.Session) .WithText(englishName) .WithLocale(englishLocale) .Build(); currency.Name = englishName; currency.AddLocalisedName(englishCurrencyName); } } foreach (var language in languageByIsoCode.Values) { if (englishNameByLanguage.ContainsKey(language)) { var englishName = englishNameByLanguage[language]; var englishLanguageName = new LocalisedTextBuilder(this.Session) .WithText(englishName) .WithLocale(englishLocale) .Build(); language.Name = englishName; language.AddLocalisedName(englishLanguageName); } } }
public void Sync() { var englishNameByCountry = new Dictionary <Country, string>(); var englishNameByCurrency = new Dictionary <Currency, string>(); var englishNameByLanguage = new Dictionary <Language, string>(); var countryByIsoCode = new Dictionary <string, Country>(); foreach (Country country in new Countries(this.Session).Extent()) { countryByIsoCode.Add(country.IsoCode, country); } var languageByIsoCode = new Dictionary <string, Language>(); foreach (Language language in new Languages(this.Session).Extent()) { languageByIsoCode.Add(language.IsoCode, language); } var currencyByIsoCode = new Dictionary <string, Currency>(); foreach (Currency currency in new Currencies(this.Session).Extent()) { currencyByIsoCode.Add(currency.IsoCode, currency); } var localeByName = new Dictionary <string, Locale>(); foreach (Locale locale in new Locales(this.Session).Extent()) { localeByName.Add(locale.Name, locale); } foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) { if (cultureInfo.LCID != 127) { var languageIsoCode = cultureInfo.TwoLetterISOLanguageName.ToLower(); Language language; if (!languageByIsoCode.TryGetValue(languageIsoCode, out language)) { language = new LanguageBuilder(this.Session) .WithIsoCode(languageIsoCode) .Build(); languageByIsoCode.Add(languageIsoCode, language); englishNameByLanguage.Add(language, cultureInfo.Parent.EnglishName); } Country country = null; var regionInfo = new RegionInfo(cultureInfo.LCID); // Should be upper, but just in case ... var countryIsoCode = regionInfo.TwoLetterISORegionName.ToUpper(); // sometimes a 2 letter code is a 3 digit code ... if (countryIsoCode.Length == 2) { if (!countryByIsoCode.TryGetValue(countryIsoCode, out country)) { country = new CountryBuilder(this.Session).WithIsoCode(countryIsoCode).Build(); englishNameByCountry.Add(country, regionInfo.EnglishName); countryByIsoCode.Add(countryIsoCode, country); } var currencyIsoCode = regionInfo.ISOCurrencySymbol.ToUpper(); Currency currency; if (!currencyByIsoCode.TryGetValue(currencyIsoCode, out currency)) { currency = new CurrencyBuilder(this.Session).WithIsoCode(currencyIsoCode).WithSymbol(regionInfo.CurrencySymbol).Build(); currencyByIsoCode.Add(currencyIsoCode, currency); englishNameByCurrency.Add(currency, regionInfo.CurrencyEnglishName); } if (country != null) { country.Currency = currency; } } var localeIdentifier = cultureInfo.Name; Locale locale; if (!localeByName.TryGetValue(localeIdentifier, out locale)) { if (country != null && language != null) { locale = new LocaleBuilder(this.Session) .WithName(cultureInfo.Name) .WithCountry(country) .WithLanguage(language) .Build(); localeByName.Add(localeIdentifier, locale); } } else { locale.Name = cultureInfo.Name; locale.Language = language; locale.Country = country; } } } var englishLocale = localeByName[EnglishGreatBritainName]; foreach (var country in countryByIsoCode.Values) { if (englishNameByCountry.ContainsKey(country)) { var enlgishName = englishNameByCountry[country]; var englishCountryName = new LocalisedTextBuilder(this.Session) .WithText(enlgishName) .WithLocale(englishLocale) .Build(); country.Name = enlgishName; country.AddLocalisedName(englishCountryName); } } foreach (var currency in currencyByIsoCode.Values) { if (englishNameByCurrency.ContainsKey(currency)) { var englishName = englishNameByCurrency[currency]; var englishCurrencyName = new LocalisedTextBuilder(this.Session) .WithText(englishName) .WithLocale(englishLocale) .Build(); currency.Name = englishName; currency.AddLocalisedName(englishCurrencyName); } } foreach (var language in languageByIsoCode.Values) { if (englishNameByLanguage.ContainsKey(language)) { var englishName = englishNameByLanguage[language]; var englishLanguageName = new LocalisedTextBuilder(this.Session) .WithText(englishName) .WithLocale(englishLocale) .Build(); language.Name = englishName; language.AddLocalisedName(englishLanguageName); } } }
public void WhenUnregisterIsoCurrency_ThenThisMustSucceed() { var euro = Currency.FromCode("EUR"); // should work CurrencyBuilder.Unregister("EUR", "ISO-4217"); Action action = () => Currency.FromCode("EUR"); action.ShouldThrow<ArgumentException>().WithMessage("*unknown*currency*"); // register again for other unit-tests var builder = new CurrencyBuilder("EUR", "ISO-4217"); builder.LoadDataFromCurrency(euro); builder.Register(); }
public void WhenCodeIsEmpty_ThenThrowException() { Action action = () => CurrencyBuilder.Unregister("", "ISO-4217"); action.Should().Throw <ArgumentNullException>(); }
public void WhenNamespaceIsEmpty_ThenThrowException() { Action action = () => CurrencyBuilder.Unregister("EUR", ""); action.Should().Throw <ArgumentNullException>(); }