public void FormatAmountWithCorrectCurrencySymbolWhenUsingCurrencySymbolConstructor()
        {
            foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                // Arrange

                if (cultureInfo.LCID.Equals(127) || cultureInfo.IsNeutralCulture)
                {
                    continue;
                }

                var amount = 10.00M;

                var regionInfo = new RegionInfo(cultureInfo.LCID);

                var currencySymbol = regionInfo.CurrencySymbol;

                var expected = string.Format(cultureInfo, "{0:C}", amount);

                var money = new Money(amount, cultureInfo.Name);

                // Act

                var moneyAsString = money.ToStringWithCurrencySymbol();

                Console.WriteLine($"Culture Name: {cultureInfo.Name}\t\tCurrency Symbol: {currencySymbol}\t\tToString: {moneyAsString}");

                // Assert

                Assert.That(moneyAsString.Equals(expected));
            }
        }
        public void ReturnValue(decimal amount)
        {
            // Arrange & Act

            var money = new Money(amount);

            // Assert

            Assert.That(money.Amount.Equals(amount));
        }
        public void ReturnWithoutCurrencySymbol()
        {
            // Arrange

            var amount = 10.00M;

            var expected = amount.ToString();

            var money = new Money(amount);

            // Act

            var moneyAsString = money.ToString();

            // Assert

            Assert.That(moneyAsString.Equals(expected));
        }
        public void FormatAmountWithCorrectCurrencySymbolWhenUsingCultureInfoConstructor()
        {
            foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                // Arrange

                var amount = 10.00M;

                var expected = string.Format(cultureInfo, "{0:C}", amount);

                var money = new Money(amount, cultureInfo);

                // Act

                var moneyAsString = money.ToStringWithCurrencySymbol();

                Console.WriteLine(moneyAsString);

                // Assert

                Assert.That(moneyAsString.Equals(expected));
            }
        }
Exemple #5
0
 /// <summary>
 /// Determines if two Money objects are equal.
 /// </summary>
 /// <param name="otherMoney">The other money.</param>
 /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns>
 public bool Equals(Money otherMoney)
 {
     return Amount.Equals(otherMoney.Amount) && CultureInfo.Equals(otherMoney.CultureInfo); // The cultures must match!
 }