Exemple #1
0
        private static void CheckValue(int[] aRawValues, EnumValueCollection aValues, int anIndex, string anExpectedDisplayString)
        {
            EnumValue enumValue = aValues.AtIndex(anIndex);

            Assert.AreEqual(aRawValues[anIndex], enumValue.Value);
            Assert.AreEqual(anExpectedDisplayString, enumValue.DisplayString);
        }
Exemple #2
0
        public void GetAvailableValuesTest()
        {
            const uint type = 123;

            int[] values = new int[] { 1, 2, 10 };
            EnumValueCollection collection = new EnumValueCollection();

            collection.Add(new EnumValue(1, "1", 0));
            collection.Add(new EnumValue(2, "2", 0));
            collection.Add(new EnumValue(3, "3", 0));
            collection.Add(new EnumValue(10, "10", 0));

            Mockery mockery = new Mockery();
            ICamera camera  = (ICamera)mockery.NewMock(typeof(ICamera));

            Expect.Once.On(camera).Method("GetAvailableValues").With(type).Will(Return.Value(values));

            EnumValueCollection result = EnumValue.GetListFrom(camera, type, collection);

            Assert.AreEqual(values.Length, result.Count);
            Assert.AreEqual(values[0], result[1].Value);
            Assert.AreEqual(values[1], result[2].Value);
            Assert.AreEqual(values[2], result[10].Value);

            mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #3
0
        public void GetExposalAvailableValuesTest()
        {
            int[] rawValues = new int[] { (int)ExposalEnum.tBulb, (int)ExposalEnum.t0dot8, (int)ExposalEnum.t30 };
            Expect.Once.On(_camera).Method("GetAvailableValues").With(EDSDKLib.EDSDK.PropID_Tv).Will(Return.Value(rawValues));

            EnumValueCollection values = Exposal.GetListFrom(_camera);

            Assert.AreEqual(rawValues.Length, values.Count);

            CheckValue(rawValues, values, 0, "Bulb");
            CheckValue(rawValues, values, 1, "0\"8");
            CheckValue(rawValues, values, 2, "30\"");

            _mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #4
0
        public void GetApertureAvailableValuesTest()
        {
            int[] rawValues = new int[] { (int)ApertureEnum.f1, (int)ApertureEnum.f64, (int)ApertureEnum.f9 };
            Expect.Once.On(_camera).Method("GetAvailableValues").With(EDSDKLib.EDSDK.PropID_Av).Will(Return.Value(rawValues));

            EnumValueCollection values = Aperture.GetListFrom(_camera);

            Assert.AreEqual(rawValues.Length, values.Count);

            CheckValue(rawValues, values, 0, "F1");
            CheckValue(rawValues, values, 1, "F64");
            CheckValue(rawValues, values, 2, "F9");

            _mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #5
0
        public void GetIsoAvailableValuesTest()
        {
            int[] rawValues = new int[] { (int)IsoSpeedEnum.iso6, (int)IsoSpeedEnum.iso320, (int)IsoSpeedEnum.iso6400 };
            Expect.Once.On(_camera).Method("GetAvailableValues").With(EDSDKLib.EDSDK.PropID_ISOSpeed).Will(Return.Value(rawValues));

            EnumValueCollection values = IsoSpeed.GetListFrom(_camera);

            Assert.AreEqual(rawValues.Length, values.Count);

            CheckValue(rawValues, values, 0, "Iso 6");
            CheckValue(rawValues, values, 1, "Iso 320");
            CheckValue(rawValues, values, 2, "Iso 6400");

            _mockery.VerifyAllExpectationsHaveBeenMet();
        }
Exemple #6
0
        public static EnumValueCollection GetEnumCollection(Type EnumType)
        {
            FieldInfo[]         fieldinfo           = EnumType.GetFields();
            EnumValueCollection enumValueCollection = new EnumValueCollection();
            string description = null;

            foreach (FieldInfo field in fieldinfo)
            {
                if (field.IsSpecialName)
                {
                    continue;
                }
                DescriptionAttribute[] attributes = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                description = (attributes.Length > 0) ? attributes[0].Description : field.GetValue(null).ToString();
                enumValueCollection.Add(new EnumValue(Convert.ToInt32(field.GetValue(null)), field.GetValue(null).ToString(), description));
            }
            return(enumValueCollection);
        }
Exemple #7
0
 public EnumType(AdsDataTypeEntry entry) : base(DataTypeCategory.Enum, entry)
 {
     int num1;
     Type type = typeof(T);
     if (((type == typeof(byte)) || ((type == typeof(sbyte)) || ((type == typeof(short)) || ((type == typeof(ushort)) || ((type == typeof(int)) || (type == typeof(uint))))))) || (type == typeof(long)))
     {
         num1 = 1;
     }
     else
     {
         num1 = (int) (type == typeof(ulong));
     }
     if (num1 == 0)
     {
         throw new AdsException($"'{type}' is not a valid base type for an enumeration!");
     }
     base.dotnetType = type;
     this._baseTypeId = entry.baseTypeId;
     this._baseTypeName = entry.typeName;
     this._fields = new EnumValueCollection<T>(entry.enums);
 }
Exemple #8
0
            /// <summary>
            /// Returns back a EnumCollection object for the given Enumeration
            /// This EnumCollection object can then be used as a DataSource for the UI
            /// controls
            /// </summary>
            /// <param name="EnumType"></param>
            /// <returns>EnumValueCollection Object</returns>
            public static EnumValueCollection GetEnumCollection(Type EnumType)
            {
                FieldInfo[]         fieldsInfo          = EnumType.GetFields();
                EnumValueCollection enumValueCollection = new EnumValueCollection();
                String description = null;

                // Now loop on all the fields
                foreach (FieldInfo field in fieldsInfo)
                {
                    // Continue only for normal fields
                    if (field.IsSpecialName)
                    {
                        continue;
                    }

                    // Now get all the Description attributes of the Enumeration
                    DescriptionAttribute[] attributes = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);

                    // Generate a friendly name for the Enum value
                    description = (attributes.Length > 0) ? attributes[0].Description : field.GetValue(null).ToString();
                    enumValueCollection.Add(new EnumValue(Convert.ToInt32(field.GetValue(null)), field.GetValue(null).ToString(), description));
                }
                return(enumValueCollection);
            }
Exemple #9
0
 public SelectApertureValuesForBrecketing(EnumValueCollection anAvailableApertureValues)
 {
     InitializeComponent();
     checkedListBox1.Items.AddRange(anAvailableApertureValues.ToArray());
 }
Exemple #10
0
        /// <summary>
        /// <para>Description : Fill Data Source to DropDown list</para>
        /// <para>Created By: Ehsan </para>
        /// <para>Created Date: 09/27/2013 </para>
        /// </summary>
        /// <param name="CurrentDropDownList">DropDownList objcet</param>
        /// <param name="SourceEnums">EnumValueCollection objcet</param>
        /// <param name="IsIncludeDefaultValue">bool is default value include of not</param>
        /// <param name="DefaultValueText">Default</param>
        public static void FillDropDownListFromEnumCollection(DropDownList CurrentDropDownList, EnumValueCollection SourceEnums, bool IsIncludeDefaultValue, string DefaultValueText)
        {
            CurrentDropDownList.Items.Clear();
            foreach (EnumValue objEnumValue in SourceEnums)
            {
                if ((objEnumValue.Value != 0))
                {
                    CurrentDropDownList.Items.Add(new ListItem(objEnumValue.DisplayName, Convert.ToString(objEnumValue.Value)));
                }
            }


            CurrentDropDownList.DataTextField  = "DisplayName";
            CurrentDropDownList.DataValueField = "Value";


            CurrentDropDownList.DataBind();

            if ((IsIncludeDefaultValue))
            {
                CurrentDropDownList.Items.Insert(0,
                                                 DefaultValueText.Trim() != string.Empty
                                                     ? new ListItem(" Select " + DefaultValueText, "0")
                                                     : new ListItem(" Select...", "0"));
            }
        }