コード例 #1
0
        public void AssertDefined_UndefinedNumericValue_Exception()
        {
            byte bValue = 100;

            Assert.That(() => Enumeration.AssertDefined <ByteEnum>(bValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            sbyte sbValue = 100;

            Assert.That(() => Enumeration.AssertDefined <SByteEnum>(sbValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            short sValue = 100;

            Assert.That(() => Enumeration.AssertDefined <ShortEnum>(sValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            ushort usValue = 100;

            Assert.That(() => Enumeration.AssertDefined <UShortEnum>(usValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            int iValue = 100;

            Assert.That(() => Enumeration.AssertDefined <IntEnum>(iValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            uint uiValue = 100;

            Assert.That(() => Enumeration.AssertDefined <UIntEnum>(uiValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            long lValue = 100;

            Assert.That(() => Enumeration.AssertDefined <LongEnum>(lValue), Throws.InstanceOf <InvalidEnumArgumentException>());
            ulong ulValue = 100;

            Assert.That(() => Enumeration.AssertDefined <ULongEnum>(ulValue), Throws.InstanceOf <InvalidEnumArgumentException>());
        }
コード例 #2
0
        public void AssertDefined_DefinedNumericValue_NoException()
        {
            byte bValue = 1;

            Assert.That(() => Enumeration.AssertDefined <ByteEnum>(bValue), Throws.Nothing);
            sbyte sbValue = 1;

            Assert.That(() => Enumeration.AssertDefined <SByteEnum>(sbValue), Throws.Nothing);
            short sValue = 1;

            Assert.That(() => Enumeration.AssertDefined <ShortEnum>(sValue), Throws.Nothing);
            ushort usValue = 1;

            Assert.That(() => Enumeration.AssertDefined <UShortEnum>(usValue), Throws.Nothing);
            int iValue = 1;

            Assert.That(() => Enumeration.AssertDefined <IntEnum>(iValue), Throws.Nothing);
            uint uiValue = 1;

            Assert.That(() => Enumeration.AssertDefined <UIntEnum>(uiValue), Throws.Nothing);
            long lValue = 1;

            Assert.That(() => Enumeration.AssertDefined <LongEnum>(lValue), Throws.Nothing);
            ulong ulValue = 1;

            Assert.That(() => Enumeration.AssertDefined <ULongEnum>(ulValue), Throws.Nothing);
        }
コード例 #3
0
        public void AssertDefined_DefinedWrongCasingName_Exception()
        {
            string wrongCasing = "ordinal";

            Assert.That(() => Enumeration.AssertDefined <StringComparison>(wrongCasing), Throws.InstanceOf <InvalidEnumArgumentException>());
            Assert.That(() => Enumeration.AssertDefined <StringComparison>(wrongCasing, false), Throws.InstanceOf <InvalidEnumArgumentException>());
        }
コード例 #4
0
        public void AssertDefined_NotDefinedEnum_Exception()
        {
            Test1 notDefined = (Test1)50;

            Assert.That(() => Enumeration.AssertDefined(notDefined), Throws.InstanceOf <InvalidEnumArgumentException>()
                        .With.Property("Message").Contains("50")
                        .And.With.Property("Message").Contains(typeof(Test1).Name));
        }
コード例 #5
0
        public void AssertDefined_UndefinedEnumValue_Exception()
        {
            var undefined = (StringComparison)100;

            Assert.That(() => Enumeration.AssertDefined(undefined), Throws.InstanceOf <InvalidEnumArgumentException>()
                        .With.Message.Contain("100")
                        .And.With.Message.Contain("StringComparison"));
        }
コード例 #6
0
        public void AssertDefined_NotDefinedEnum_Exception()
        {
            Test1 notDefined = (Test1)50;

            Assert.That(() => Enumeration.AssertDefined(notDefined), Throws.ArgumentException
                        .With.Message.Contains("50")
                        .And.With.Message.Contains(typeof(Test1).Name));
        }
コード例 #7
0
        public void AssertDefined_DefinedEnum_NoException()
        {
            Test1 defined = Test1.Value1;

            Assert.That(() => Enumeration.AssertDefined(defined), Throws.Nothing);

            defined = (Test1)1;
            Assert.That(() => Enumeration.AssertDefined(defined), Throws.Nothing);
        }
コード例 #8
0
 public void Enqueue(TPriorityEnum priority, TValue item)
 {
     Enumeration.AssertDefined <TPriorityEnum>(priority);
     lock (this._list)
     {
         this._list[priority].Enqueue(item);
         Interlocked.Increment(ref this._count);
     }
 }
コード例 #9
0
        /// <summary>
        /// Initializes an instance of <see cref="ExchangeRate"/> with the provided information.
        /// </summary>
        /// <param name="from">Base currency, the currency from which the conversion is performed.</param>
        /// <param name="to">Quote currency, the currency which the conversion is performed to.</param>
        /// <param name="rate">A non-negative <see cref="decimal"/> instance representing the relative vaue of <paramref name="from"/> against <paramref name="to"/>.</param>
        /// <example>{from}= EUR, {to}= USD, {rate}=1.2500, represented as "EUR/USD 1.2500" means that one euro is exchanged for 1.2500 US dollars.</example>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="from"/> or <paramref name="to"/> are undefined currencies.</exception>
        /// <exception cref="ArgumentException"><paramref name="rate"/> is negative.</exception>
        public ExchangeRate(CurrencyIsoCode from, CurrencyIsoCode to, decimal rate)
        {
            Guard.AgainstArgument("rate", rate < 0, "Non-negative");
            Enumeration.AssertDefined(from);
            Enumeration.AssertDefined(to);

            From = from;
            To   = to;
            Rate = rate;
        }
コード例 #10
0
        private void setAllFields(decimal amount, CurrencyIsoCode currency, ObsoleteCurrencyEventBehavior eventBehavior)
        {
            Enumeration.AssertDefined(currency);
            if (eventBehavior == ObsoleteCurrencyEventBehavior.Raise)
            {
                Currency.RaiseIfObsolete(currency);
            }

            Amount       = amount;
            CurrencyCode = currency;
        }
コード例 #11
0
        public static Currency Get(CurrencyIsoCode isoCode)
        {
            Enumeration.AssertDefined(isoCode);

            Currency currency = _cache.GetOrAdd(isoCode, () =>
            {
                var built = init(isoCode, _provider.Get);
                if (built == null)
                {
                    throw new MisconfiguredCurrencyException(isoCode);
                }
                return(built);
            });

            RaiseIfObsolete(isoCode);
            return(currency);
        }
コード例 #12
0
 public void AssertDefined_DefinedValue_NoException()
 {
     Assert.That(() => Enumeration.AssertDefined <Test1>("Value1"), Throws.Nothing);
 }
コード例 #13
0
 public void AsseryDefined_NotEnumType_Exception()
 {
     Assert.That(() => Enumeration.AssertDefined <int>(1), Throws.InstanceOf <ArgumentException>());
 }
コード例 #14
0
        public void Explore()
        {
            Assert.That(Enumeration.IsEnum <ActionTargets>(), Is.True);
            Assert.That(Enumeration.IsEnum <int>(), Is.False);
            Assert.That(Enumeration.AssertEnum <ActionTargets>, Throws.Nothing);
            Assert.That(Enumeration.AssertEnum <int>, Throws
                        .InstanceOf <ArgumentException>()
                        .With.Message.Contains("Int32"));
            Assert.That(Enumeration.IsFlags <ZeroFlags>(), Is.True);
            Assert.That(Enumeration.IsFlags <IntEnum>(), Is.False);
            Assert.That(Enumeration.AssertFlags <ZeroFlags>, Throws.Nothing);
            Assert.That(Enumeration.AssertFlags <IntEnum>, Throws
                        .ArgumentException
                        .With.Message.Contains("IntEnum"));

            Assert.That(Enumeration.IsDefined(StringComparison.Ordinal), Is.True);
            Assert.That(Enumeration.IsDefined((StringComparison)100), Is.False);
            Assert.That(Enumeration.IsDefined <LongEnum>(1L), Is.True);
            Assert.That(Enumeration.IsDefined <StringComparison>("undefined"), Is.False);
            Assert.That(Enumeration.IsDefined <StringComparison>("oRDinaL", ignoreCase: true), Is.True);

            Assert.That(() => Enumeration.AssertDefined(StringComparison.Ordinal), Throws.Nothing);
            Assert.That(() => Enumeration.AssertDefined <StringComparison>("ordinal"), Throws
                        .InstanceOf <InvalidEnumArgumentException>()
                        .With.Message.Contains("ordinal")
                        .And.With.Message.Contains("StringComparison"));

            Assert.That(Enumeration.GetName(StringComparison.Ordinal), Is.EqualTo("Ordinal"));
            Assert.That(Enumeration.GetName <ULongEnum>(1UL), Is.EqualTo("Two"));
            Assert.That(() => Enumeration.GetName <IntEnum>(100), Throws.InstanceOf <InvalidEnumArgumentException>());

            Assert.That(Enumeration.GetValues <StringSplitOptions>(), Is.EquivalentTo(
                            new[] { StringSplitOptions.None, StringSplitOptions.RemoveEmptyEntries }));
            Assert.That(Enumeration.GetValue <ULongEnum, ulong>(ULongEnum.Two), Is.EqualTo(1UL));

            Assert.That(Enumeration.Cast <ByteEnum>((byte)1), Is.EqualTo(ByteEnum.Two));
            StringComparison?value;

            Assert.That(Enumeration.TryCast(100, out value), Is.False);

            Assert.That(Enumeration.Parse <ActionTargets>("Suite"), Is.EqualTo(ActionTargets.Suite));
            Assert.That(() => Enumeration.Parse <ActionTargets>("SUIte", ignoreCase: false),
                        Throws.InstanceOf <InvalidEnumArgumentException>());
            Assert.That(Enumeration.Parse <StringComparison>("4"), Is.EqualTo(StringComparison.Ordinal));
            ActionTargets?parsed;

            Assert.That(() => Enumeration.TryParse("100", out parsed), Is.False);
            Assert.That(Enumeration.TryParse("suiTE", true, out parsed), Is.True);

            var         fourNotSet = NoZeroFlags.Three;
            NoZeroFlags fourSet    = fourNotSet.SetFlag(NoZeroFlags.Four);

            Assert.That(fourSet.HasFlag(NoZeroFlags.Four), Is.True);

            NoZeroFlags fourUnset = fourSet.UnsetFlag(NoZeroFlags.Four);

            Assert.That(fourUnset.HasFlag(NoZeroFlags.Four), Is.False);

            fourSet = fourUnset.ToggleFlag(NoZeroFlags.Four);
            Assert.That(fourSet.HasFlag(NoZeroFlags.Four), Is.True);
            fourNotSet = fourSet.ToggleFlag(NoZeroFlags.Four);
            Assert.That(fourNotSet.HasFlag(NoZeroFlags.Four), Is.False);

            Assert.That(fourSet.GetFlags(), Is.EquivalentTo(new[] { NoZeroFlags.Three, NoZeroFlags.Four }));
        }
コード例 #15
0
ファイル: Html.cs プロジェクト: amittal09/Utility
 public static string Write(this HtmlTextWriterAttribute attr)
 {
     Enumeration.AssertDefined <HtmlTextWriterAttribute>(attr);
     return(attr.ToString().ToLowerInvariant());
 }
コード例 #16
0
        public void AssertDefined_DefinedWrongCasingNameWhenIgnoredCasing_NoException()
        {
            string wrongCasing = "ordinal";

            Assert.That(() => Enumeration.AssertDefined <StringComparison>(wrongCasing, true), Throws.Nothing);
        }
コード例 #17
0
        public void AssertDefined_DefinedName_NoException()
        {
            string defined = "Ordinal";

            Assert.That(() => Enumeration.AssertDefined <StringComparison>(defined), Throws.Nothing);
        }
コード例 #18
0
        public void AssertDefined_UndefinedName_Exception()
        {
            string undefined = "undefined";

            Assert.That(() => Enumeration.AssertDefined <StringComparison>(undefined), Throws.InstanceOf <InvalidEnumArgumentException>());
        }
コード例 #19
0
 public void AssertDefined_WrongCase_Exception()
 {
     Assert.That(() => Enumeration.AssertDefined <Test1>("value1"),
                 Throws.InstanceOf <InvalidEnumArgumentException>().With.Property("Message").Contains("value1"));
 }
コード例 #20
0
ファイル: Html.cs プロジェクト: amittal09/Utility
 public static string Write(this HtmlTextWriterTag tag)
 {
     Enumeration.AssertDefined <HtmlTextWriterTag>(tag);
     return(tag.ToString().ToLowerInvariant());
 }
コード例 #21
0
 public void AssertDefined_NotDefinedValue_Exception()
 {
     // for strings, use the representation
     Assert.That(() => Enumeration.AssertDefined <Test1>("notDefined"),
                 Throws.InstanceOf <InvalidEnumArgumentException>().With.Property("Message").Contains("notDefined"));
 }
コード例 #22
0
 public void AssertDefined_NotDefinedValue_Exception()
 {
     // for strings, use the representation
     Assert.That(() => Enumeration.AssertDefined <Test1>("notDefined"),
                 Throws.ArgumentException.With.Message.Contains("notDefined"));
 }
コード例 #23
0
        public void AssertDefined_DefinedEnumValue_NoException()
        {
            var defined = StringComparison.Ordinal;

            Assert.That(() => Enumeration.AssertDefined(defined), Throws.Nothing);
        }
コード例 #24
0
        public void AssertDefined_UnderlyingValueMissmatch_Exception()
        {
            long lValue = 100;

            Assert.That(() => Enumeration.AssertDefined <ByteEnum>(lValue), Throws.ArgumentException);
        }
コード例 #25
0
 public void AssertDefined_NumericalValueInsteadOfRepresentation_NoException()
 {
     // for strings, use the representation
     Assert.That(() => Enumeration.AssertDefined <Test1>("1"), Throws.Nothing);
 }