Exemplo n.º 1
0
        public void whenever_a_deprecated_currency_is_obtained_an_event_is_raised()
        {
            bool            called   = false;
            CurrencyIsoCode obsolete = CurrencyIsoCode.XXX;
            EventHandler <ObsoleteCurrencyEventArgs> callback = (sender, e) =>
            {
                called   = true;
                obsolete = e.Code;
            };

            try
            {
                Currency.ObsoleteCurrency += callback;
                Currency.Get("EEK");

                Assert.That(called, Is.True);
                Assert.That(obsolete.ToString(), Is.EqualTo("EEK"));
                Assert.That(obsolete.AsAttributeProvider(), Has.Attribute <ObsoleteAttribute>());
            }
            // DO unsubscribe from global events whenever listening isnot needed anymore
            finally
            {
                Currency.ObsoleteCurrency -= callback;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows setting all field both for constructors and serialization methods.
        /// </summary>
        private void setAllFields(CurrencyIsoCode isoCode, string englishName, string nativeName, string symbol, int significantDecimalDigits, string decimalSeparator, string groupSeparator, int[] groupSizes, int positivePattern, int negativePattern, bool isObsolete, CharacterReference entity)
        {
            IsoCode                  = isoCode;
            EnglishName              = englishName;
            Symbol                   = symbol;
            AlphabeticCode           = IsoSymbol = isoCode.ToString();
            SignificantDecimalDigits = significantDecimalDigits;
            NativeName               = nativeName;
            DecimalSeparator         = decimalSeparator;
            GroupSeparator           = groupSeparator;
            GroupSizes               = groupSizes;
            PositivePattern          = positivePattern;
            NegativePattern          = negativePattern;
            IsObsolete               = isObsolete;
            Entity                   = entity;

            FormatInfo = NumberFormatInfo.ReadOnly(new NumberFormatInfo
            {
                CurrencySymbol           = symbol,
                CurrencyDecimalDigits    = significantDecimalDigits,
                CurrencyDecimalSeparator = decimalSeparator,
                CurrencyGroupSeparator   = groupSeparator,
                CurrencyGroupSizes       = groupSizes,
                CurrencyPositivePattern  = positivePattern,
                CurrencyNegativePattern  = negativePattern,
                NumberDecimalDigits      = significantDecimalDigits,
                NumberDecimalSeparator   = decimalSeparator,
                NumberGroupSeparator     = groupSeparator,
                NumberGroupSizes         = groupSizes,
                NumberNegativePattern    = negativePattern.TranslateNegativePattern(),
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a dictionary of name/value pairs.
        /// </summary>
        /// <remaks>Only instances of <see cref="CurrencyIsoCode"/> are supported.</remaks>
        /// <returns>
        /// An object that contains key/value pairs that represent the object’s data.
        /// </returns>
        /// <param name="obj">The object to serialize.</param>
        /// <param name="serializer">The object that is responsible for the serialization.</param>
        /// <exception cref="InvalidCastException">When the <paramref name="obj"/> cannot be casted to <see cref="CurrencyIsoCode"/>.</exception>
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            CurrencyIsoCode currency = (CurrencyIsoCode)obj;
            IDictionary <string, object> serialized = new Dictionary <string, object>(1)
            {
                { Data.Currency.ISO_CODE, currency.ToString() }
            };

            return(serialized);
        }
 /// <summary>
 /// The alphabetic ISO 4217 code of the <see cref="CurrencyIsoCode"/>
 /// </summary>
 public static string AlphabeticCode(this CurrencyIsoCode isoCode)
 {
     return(isoCode.ToString());
 }
 internal static ICustomAttributeProvider AsAttributeProvider(this CurrencyIsoCode code)
 {
     return(typeof(CurrencyIsoCode).GetField(code.ToString()));
 }