Ejemplo n.º 1
0
        public static void EnumConvert_ToEnumCheckedOfInt64()
        {
            Assert.Equal(Int64Enum.MinValue, EnumConvert.ToEnumChecked <Int64Enum>(long.MinValue));
            Assert.Equal(Int64Enum.MaxValue, EnumConvert.ToEnumChecked <Int64Enum>(long.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToEnumChecked <Int64Enum>(ulong.MaxValue));
        }
Ejemplo n.º 2
0
        public static void EnumConvert_ToInt64Checked()
        {
            Assert.Equal(long.MinValue, EnumConvert.ToInt64Checked(Int64Enum.MinValue));
            Assert.Equal(long.MaxValue, EnumConvert.ToInt64Checked(Int64Enum.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToInt64Checked(UInt64Enum.MaxValue));
        }
Ejemplo n.º 3
0
        public static void EnumConvert_ToInt64()
        {
            Assert.Equal(long.MinValue, EnumConvert.ToInt64(Int64Enum.MinValue));
            Assert.Equal(long.MaxValue, EnumConvert.ToInt64(Int64Enum.MaxValue));

            Assert.Equal(unchecked ((long)ulong.MaxValue), EnumConvert.ToInt64(UInt64Enum.MaxValue));
        }
Ejemplo n.º 4
0
        public void ModType_ApiOptional_ParsedSuccessfully()
        {
            var _modSource = "optional";
            var modSource  = EnumConvert.ToEnum <WebModType>(_modSource);

            modSource.Should().Be(WebModType.Optional);
        }
Ejemplo n.º 5
0
        public void ModType_ApiClientSide_ParsedSuccessfully()
        {
            var _modSource = "client_side";
            var modSource  = EnumConvert.ToEnum <WebModType>(_modSource);

            modSource.Should().Be(WebModType.ClientSide);
        }
        public void ModSource_ApiDirectory_ParsedSuccessfully()
        {
            var _modSource = "directory";
            var modSource  = EnumConvert.ToEnum <WebModSource>(_modSource);

            modSource.Should().Be(WebModSource.Directory);
        }
Ejemplo n.º 7
0
        public void ModType_ApiRequired_ParsedSuccessfully()
        {
            var _modSource = "required";
            var modSource  = EnumConvert.ToEnum <WebModType>(_modSource);

            modSource.Should().Be(WebModType.Required);
        }
        public void ModSource_ApiSteamWorkshop_ParsedSuccessfully()
        {
            var _modSource = "steam_workshop";
            var modSource  = EnumConvert.ToEnum <WebModSource>(_modSource);

            modSource.Should().Be(WebModSource.SteamWorkshop);
        }
Ejemplo n.º 9
0
        public static void EnumConvert_ToEnumOfInt64()
        {
            Assert.Equal(Int64Enum.MinValue, EnumConvert.ToEnum <Int64Enum>(long.MinValue));
            Assert.Equal(Int64Enum.MaxValue, EnumConvert.ToEnum <Int64Enum>(long.MaxValue));

            Assert.Equal(Int64Enum.UInt64MaxValue, EnumConvert.ToEnum <Int64Enum>(ulong.MaxValue));
        }
Ejemplo n.º 10
0
        private IEnumerable <LogInfo> GetNewInfoBySelf(Guid xxid, int topcount, string uctype, int pageindex)
        {
            UCHomeEntities uc      = new UCHomeEntities();
            List <LogInfo> loglist = new List <LogInfo>();
            var            pn      = uc.UCHome_PersonNew.Join(
                uc.View_Simple_User,
                a => a.AddUser,
                b => b.userid,
                (a, b) => new { a.PKID, a.Title, a.Abstract, a.DeployTime, a.AddUser, a.Hits, a.UCType, a.IsAudit, a.IsShare, a.IsShow, b.xxid })
                                     .Where(u => u.xxid == xxid && u.UCType == uctype && u.IsShow == 1 && u.IsAudit > 1)
                                     .OrderByDescending(u => u.DeployTime).Skip(topcount * (pageindex - 1)).Take(topcount).ToList();

            foreach (var item in pn)
            {
                LogInfo log = new LogInfo();
                log.pkid        = item.PKID;
                log.logtitle    = item.Title;
                log.logabstract = item.Abstract;
                log.logdate     = item.DeployTime;
                log.loghits     = item.Hits;
                log.logisaudit  = EnumConvert.ConvertAudit(item.IsAudit);
                log.logisshare  = EnumConvert.ConvertShare(item.IsShare);
                log.logisshow   = EnumConvert.ConvertShow(item.IsShow);
                log.loguser     = item.AddUser;
                loglist.Add(log);
            }
            return(loglist);
        }
Ejemplo n.º 11
0
        public static void EnumConvert_ToEnumCheckedOfInt16()
        {
            Assert.Equal(Int16Enum.MinValue, EnumConvert.ToEnumChecked <Int16Enum>(short.MinValue));
            Assert.Equal(Int16Enum.MaxValue, EnumConvert.ToEnumChecked <Int16Enum>(short.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToEnumChecked <Int16Enum>(int.MinValue));
            Assert.Throws <OverflowException>(() => EnumConvert.ConvertToEnumChecked <Int16Enum>(ushort.MaxValue));
        }
Ejemplo n.º 12
0
        public static void EnumConvert_ToEnumCheckedOfSByte()
        {
            Assert.Equal(SByteEnum.MinValue, EnumConvert.ToEnumChecked <SByteEnum>(sbyte.MinValue));
            Assert.Equal(SByteEnum.MaxValue, EnumConvert.ToEnumChecked <SByteEnum>(sbyte.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToEnumChecked <SByteEnum>(short.MinValue));
            Assert.Throws <OverflowException>(() => EnumConvert.ToEnumChecked <SByteEnum>(byte.MaxValue));
        }
Ejemplo n.º 13
0
        public static void EnumConvert_ToSByteChecked()
        {
            Assert.Equal(sbyte.MinValue, EnumConvert.ToSByteChecked(SByteEnum.MinValue));
            Assert.Equal(sbyte.MaxValue, EnumConvert.ToSByteChecked(SByteEnum.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToSByteChecked(Int16Enum.MinValue));
            Assert.Throws <OverflowException>(() => EnumConvert.ToSByteChecked(ByteEnum.MaxValue));
        }
Ejemplo n.º 14
0
        public static void EnumConvert_ToEnumCheckedOfUInt32()
        {
            Assert.Equal(UInt32Enum.MinValue, EnumConvert.ToEnumChecked <UInt32Enum>(uint.MinValue));
            Assert.Equal(UInt32Enum.MaxValue, EnumConvert.ToEnumChecked <UInt32Enum>(uint.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToEnumChecked <UInt32Enum>(int.MinValue));
            Assert.Throws <OverflowException>(() => EnumConvert.ToEnumChecked <UInt32Enum>(ulong.MaxValue));
        }
Ejemplo n.º 15
0
        public static void EnumConvert_ToInt32()
        {
            Assert.Equal(int.MinValue, EnumConvert.ToInt32(Int32Enum.MinValue));
            Assert.Equal(int.MaxValue, EnumConvert.ToInt32(Int32Enum.MaxValue));

            Assert.Equal(unchecked ((int)long.MinValue), EnumConvert.ToInt32(Int64Enum.MinValue));
            Assert.Equal(unchecked ((int)uint.MaxValue), EnumConvert.ToInt32(UInt32Enum.MaxValue));
        }
Ejemplo n.º 16
0
        public static void EnumConvert_ToInt16Checked()
        {
            Assert.Equal(short.MinValue, EnumConvert.ToInt16Checked(Int16Enum.MinValue));
            Assert.Equal(short.MaxValue, EnumConvert.ToInt16Checked(Int16Enum.MaxValue));

            Assert.Throws <OverflowException>(() => EnumConvert.ToInt16Checked(Int32Enum.MinValue));
            Assert.Throws <OverflowException>(() => EnumConvert.ToInt16Checked(UInt16Enum.MaxValue));
        }
Ejemplo n.º 17
0
        public static void EnumConvert_ToSByte()
        {
            Assert.Equal(sbyte.MinValue, EnumConvert.ToSByte(SByteEnum.MinValue));
            Assert.Equal(sbyte.MaxValue, EnumConvert.ToSByte(SByteEnum.MaxValue));

            Assert.Equal(unchecked ((sbyte)short.MinValue), EnumConvert.ToSByte(Int16Enum.MinValue));
            Assert.Equal(unchecked ((sbyte)byte.MaxValue), EnumConvert.ToSByte(ByteEnum.MaxValue));
        }
Ejemplo n.º 18
0
        public static void EnumConvert_ToInt16()
        {
            Assert.Equal(short.MinValue, EnumConvert.ToInt16(Int16Enum.MinValue));
            Assert.Equal(short.MaxValue, EnumConvert.ToInt16(Int16Enum.MaxValue));

            Assert.Equal(unchecked ((short)int.MinValue), EnumConvert.ToInt16(Int32Enum.MinValue));
            Assert.Equal(unchecked ((short)ushort.MaxValue), EnumConvert.ToInt16(UInt16Enum.MaxValue));
        }
Ejemplo n.º 19
0
        public static void EnumConvert_ToEnumOfInt32()
        {
            Assert.Equal(Int32Enum.MinValue, EnumConvert.ToEnum <Int32Enum>(int.MinValue));
            Assert.Equal(Int32Enum.MaxValue, EnumConvert.ToEnum <Int32Enum>(int.MaxValue));

            Assert.Equal(Int32Enum.Int64MinValue, EnumConvert.ToEnum <Int32Enum>(long.MinValue));
            Assert.Equal(Int32Enum.UInt32MaxValue, EnumConvert.ToEnum <Int32Enum>(uint.MaxValue));
        }
Ejemplo n.º 20
0
        public static void EnumConvert_ToEnumOfInt16()
        {
            Assert.Equal(Int16Enum.MinValue, EnumConvert.ToEnum <Int16Enum>(short.MinValue));
            Assert.Equal(Int16Enum.MaxValue, EnumConvert.ToEnum <Int16Enum>(short.MaxValue));

            Assert.Equal(Int16Enum.Int32MinValue, EnumConvert.ToEnum <Int16Enum>(int.MinValue));
            Assert.Equal(Int16Enum.UInt16MaxValue, EnumConvert.ToEnum <Int16Enum>(ushort.MaxValue));
        }
Ejemplo n.º 21
0
        public static void EnumConvert_ToEnumOfSByte()
        {
            Assert.Equal(SByteEnum.MinValue, EnumConvert.ToEnum <SByteEnum>(sbyte.MinValue));
            Assert.Equal(SByteEnum.MaxValue, EnumConvert.ToEnum <SByteEnum>(sbyte.MaxValue));

            Assert.Equal(SByteEnum.Int16MinValue, EnumConvert.ToEnum <SByteEnum>(short.MinValue));
            Assert.Equal(SByteEnum.ByteMaxValue, EnumConvert.ToEnum <SByteEnum>(byte.MaxValue));
        }
Ejemplo n.º 22
0
        public static void EnumConvert_ToEnumOfByte()
        {
            Assert.Equal(ByteEnum.MinValue, EnumConvert.ToEnum <ByteEnum>(byte.MinValue));
            Assert.Equal(ByteEnum.MaxValue, EnumConvert.ToEnum <ByteEnum>(byte.MaxValue));

            Assert.Equal(ByteEnum.SByteMinValue, EnumConvert.ToEnum <ByteEnum>(sbyte.MinValue));
            Assert.Equal(ByteEnum.UInt16MaxValue, EnumConvert.ToEnum <ByteEnum>(ushort.MaxValue));
        }
Ejemplo n.º 23
0
        public async Task TestGraphQLClient()
        {
            TestEnv.LogTestMethodStart();
            ServerResponse resp;
            string         thingName;
            var            query1 = "query ($id: Int) { getThing(id: $id) {name kind theFlags} }";
            var            queryM = "query { things {name} }";
            var            vars   = new TDict()
            {
                { "id", 3 }
            };

            // Post requests
            TestEnv.LogTestDescr("Testing Post requests");
            // single thing with query parameter
            resp = await TestEnv.Client.PostAsync(query1, vars);

            resp.EnsureNoErrors();
            var thing = resp.data.getThing;

            thingName = thing.name;
            Assert.AreEqual("Name3", thingName);
            var thingKind = EnumConvert.ToEnum <ThingKind>(thing.kind);

            Assert.AreEqual(ThingKind.KindThree, thingKind, "Invalid kind field value.");
            var flags = EnumConvert.ToEnum <TheFlags>(thing.theFlags);

            Assert.AreEqual(TheFlags.FlagOne | TheFlags.FlagTwo, flags, "Invalid flags field value");

            // list of things
            resp = await TestEnv.Client.PostAsync(queryM, vars);

            resp.EnsureNoErrors();
            thingName = resp.data.things[1].name;
            Assert.AreEqual("Name2", thingName);

            TestEnv.LogTestDescr("Testing Get requests");
            // single thing with query parameter
            resp = await TestEnv.Client.GetAsync(query1, vars);

            resp.EnsureNoErrors();
            thingName = resp.data.getThing.name;
            Assert.AreEqual("Name3", thingName);

            // list of things
            resp = await TestEnv.Client.GetAsync(queryM, vars);

            resp.EnsureNoErrors();
            thingName = resp.data.things[1].name;
            Assert.AreEqual("Name2", thingName);

            TestEnv.LogTestDescr("Testing queries with errors");
            resp = await TestEnv.Client.PostAsync(query1 + " ABCD ", vars);

            var errs = resp.Errors;

            Assert.IsTrue(errs.Count > 0, "Expected syntax error");
        }
Ejemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="builder">Using ILogging builder</param>
 /// <param name="configFile">nlog.config file</param>
 /// <param name="kafkaTaget">Ip and port of Kafka cluster</param>
 /// <param name="applicationStore">Application name and Application Id</param>
 public static void UseNLog(this ILoggingBuilder builder, string configFile, string kafkaTaget, LogSourceTypeEnums applicationStore)
 {
     NLogTargetCustom.RegisterTarget();
     StaticConfiguration.KafkaServer      = kafkaTaget;
     StaticConfiguration.ApplicationStore = new Dictionary <int, string> {
         { (int)applicationStore, (EnumConvert.GetEnumDescription(applicationStore)) }
     };
     builder.AddNLog(configFile);
 }
Ejemplo n.º 25
0
        public void FromCharTest()
        {
            ActiveInactiveType target = EnumConvert <ActiveInactiveType> .FromChar('A');

            Assert.IsTrue(target == ActiveInactiveType.Active);

            target = EnumConvert <ActiveInactiveType> .FromChar('I');

            Assert.IsTrue(target == ActiveInactiveType.Inactive);
        }
Ejemplo n.º 26
0
        public void FromIntTest()
        {
            ActiveInactiveType target = EnumConvert <ActiveInactiveType> .FromInt(Convert.ToInt32('A'));

            Assert.IsTrue(target == ActiveInactiveType.Active);

            target = EnumConvert <ActiveInactiveType> .FromInt(Convert.ToInt32('I'));

            Assert.IsTrue(target == ActiveInactiveType.Inactive);
        }
Ejemplo n.º 27
0
        private IDbDataParameter[] CreateParameters(Dictionary <string, DBParameter> paramObj)
        {
            List <IDbDataParameter> list = new List <IDbDataParameter>();

            foreach (KeyValuePair <string, DBParameter> kv in paramObj)
            {
                IDbDataParameter npgsql = GetDataParameter();
                npgsql.ParameterName = kv.Key.Trim().StartsWith("@") ? kv.Key : "@" + kv.Key;
                npgsql.Value         = kv.Value;
                npgsql.DbType        = EnumConvert.ToEnum <DbType>(kv.Value.DbType);
                npgsql.Direction     = EnumConvert.ToEnum <ParameterDirection>(kv.Value.ParameterDirection);
                list.Add(npgsql);
            }
            return(list.ToArray());
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Sets a property in the specified <see cref="JObject"/>.
        /// </summary>
        /// <typeparam name="TEnum">The type of the enum.</typeparam>
        /// <param name="container">The object to set the property on.</param>
        /// <param name="key">The property name in <paramref name="container"/>.</param>
        /// <param name="value">The enum flags value.</param>
        /// <param name="flag">The flag to search for.</param>
        /// <param name="defaultState">The default state of the flag.</param>
        /// <param name="required">A value indicating whether the property is required.</param>
        /// <param name="invert">A value indicating whether to invert the flag check.</param>
        protected virtual void SetJsonFlag <TEnum>(JObject container, string key, TEnum value, TEnum flag, bool defaultState = false, bool required = false, bool invert = false)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            var v       = EnumConvert.ToUInt64(value);
            var f       = EnumConvert.ToUInt64(flag);
            var present = (v & f) == f;

            if (invert)
            {
                present = !present;
            }

            if (present != defaultState || required)
            {
                container.Add(key, present);
            }
        }
Ejemplo n.º 29
0
        public void ToEnumTest()
        {
            char target = 'A';
            ActiveInactiveType result = EnumConvert <ActiveInactiveType> .ToEnum(target);

            Assert.IsTrue(result == ActiveInactiveType.Active);

            result = EnumConvert <ActiveInactiveType> .ToEnum(Convert.ToInt32(target));

            Assert.IsTrue(result == ActiveInactiveType.Active);

            target = 'I';
            result = EnumConvert <ActiveInactiveType> .ToEnum(target);

            Assert.IsTrue(result == ActiveInactiveType.Inactive);

            result = EnumConvert <ActiveInactiveType> .ToEnum(Convert.ToInt32(target));

            Assert.IsTrue(result == ActiveInactiveType.Inactive);
        }
Ejemplo n.º 30
0
        private LogInfo GetLogInfoBySelf(Guid pid)
        {
            UCHomeEntities   uc   = new UCHomeEntities();
            UCHome_PersonNew item = uc.UCHome_PersonNew.SingleOrDefault(u => u.PKID == pid);
            LogInfo          log  = new LogInfo();

            if (item != null)
            {
                log.pkid        = item.PKID;
                log.logtitle    = item.Title;
                log.logabstract = item.Abstract;
                log.logdate     = item.DeployTime;
                log.loghits     = item.Hits;
                log.logisaudit  = EnumConvert.ConvertAudit(item.IsAudit);
                log.logisshare  = EnumConvert.ConvertShare(item.IsShare);
                log.logisshow   = EnumConvert.ConvertShow(item.IsShow);
                log.loguser     = item.AddUser;
            }
            return(log);
        }