public void Setup(ParameterEditorSetupData data)
 {
     m_parameter = data.Parameter as IDynamicEnumParameter;
     if (!data.Parameter.Corrupted)
     {
         m_comboBox.SelectedItem = new TItem(m_parameter.Value, m_parameter.Value);
     }
 }
Example #2
0
        public static void Test()
        {
            Random                 random            = new Random(0);
            Func <string>          randomString      = () => "test" + random.NextDouble().ToString(CultureInfo.InvariantCulture);
            Func <Id <Parameter> > randomParameterId = () =>
            {
                byte[] bytes = new byte[16];
                random.NextBytes(bytes);
                return(Id <Parameter> .FromGuid(new Guid(bytes))); //Not really a guid but should be unique enough for this test
            };


            List <DecimalData>                 decimals          = new List <DecimalData>();
            List <IntegerData>                 integers          = new List <IntegerData>();
            List <EnumerationData>             enums             = new List <EnumerationData>();
            List <EnumerationData>             hiddenEnums       = new List <EnumerationData>();
            List <DynamicEnumerationData>      dynamicEnums      = new List <DynamicEnumerationData>();
            List <LocalDynamicEnumerationData> localDynamicEnums = new List <LocalDynamicEnumerationData>();
            List <LocalizedStringData>         localizedStrings  = new List <LocalizedStringData>();
            List <OtherData> others = new List <OtherData>();

            TypeSet t = new TypeSet();

            Action CheckContents = () =>
            {
                foreach (var x in decimals)
                {
                    CheckIs(t, x.TypeId, dec: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));

                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                    Assert.That(parameter, Is.InstanceOf <IDecimalParameter>());
                    IDecimalParameter p = parameter as IDecimalParameter;
                    Assert.That(p.Min, Is.EqualTo(x.Min));
                    Assert.That(p.Max, Is.EqualTo(x.Max));
                }
                foreach (var x in integers)
                {
                    CheckIs(t, x.TypeId, integer: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));

                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                    Assert.That(parameter, Is.InstanceOf <IIntegerParameter>());
                    IIntegerParameter p = parameter as IIntegerParameter;
                    Assert.That(p.Min, Is.EqualTo(x.Min));
                    Assert.That(p.Max, Is.EqualTo(x.Max));
                }
                foreach (var x in enums)
                {
                    CheckIs(t, x.TypeId, enumeration: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));

                    {
                        IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                        Assert.That(parameter, Is.InstanceOf <IEnumParameter>());
                        IEnumParameter p = parameter as IEnumParameter;
                        Assert.That(p.Options, Is.EquivalentTo(x.Elements.Select(a => a.Guid)));
                    }

                    //Check set parameter creation
                    {
                        IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, ParameterType.ValueSetType.Of(x.TypeId), null, true); //This type shouldn't care about document
                        Assert.That(parameter, Is.InstanceOf <ISetParameter>());
                        ISetParameter p = parameter as ISetParameter;
                        Assert.That(p.Options, Is.EquivalentTo(x.Elements.Select(a => a.Guid)));
                    }
                }
                foreach (var x in dynamicEnums)
                {
                    CheckIs(t, x.TypeId, dynamicEnum: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, null, true); //This type shouldn't care about document
                    Assert.That(parameter, Is.InstanceOf <IDynamicEnumParameter>());
                    IDynamicEnumParameter p = parameter as IDynamicEnumParameter;
                    Assert.That(p.Local, Is.False);
                }
                foreach (var x in localDynamicEnums)
                {
                    CheckIs(t, x.TypeId, localDynamicEnum: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    object     document  = new object();
                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, document, true);
                    Assert.That(parameter, Is.InstanceOf <IDynamicEnumParameter>());
                    IDynamicEnumParameter p = parameter as IDynamicEnumParameter;
                    Assert.That(p.Local, Is.True);
                }
                foreach (var x in localizedStrings)
                {
                    CheckIs(t, x.TypeId, localizedString: true);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    object     document  = new object();
                    IParameter parameter = CheckBasicMake(randomString(), randomParameterId(), randomString(), t, x.TypeId, document, false);
                    Assert.That(parameter, Is.InstanceOf <ILocalizedStringParameter>());
                }
                foreach (var x in others)
                {
                    CheckIs(t, x.TypeId);
                    Assert.That(t.GetTypeName(x.TypeId), Is.EqualTo(x.Name));
                    string     name      = randomString();
                    var        id        = randomParameterId();
                    var        def       = randomString();
                    object     document  = new object();
                    IParameter parameter = CheckBasicMake(name, id, def, t, x.TypeId, document, true);
                    Assert.That(x.LastGeneratorParameters, Is.Not.Null);
                    Assert.That(x.LastGeneratorParameters.name, Is.EqualTo(name));
                    Assert.That(x.LastGeneratorParameters.id, Is.EqualTo(id));
                    Assert.That(x.LastGeneratorParameters.defaultValue, Is.EqualTo(def));
                    Assert.That(x.LastGeneratorParameters.document, Is.EqualTo(document));
                    Assert.That(x.LastGeneratorParameters.createdParameter, Is.EqualTo(parameter));
                    x.LastGeneratorParameters = null;
                }

                Assert.That(t.VisibleDecimals, Is.EquivalentTo(decimals));
                Assert.That(t.VisibleDynamicEnums, Is.EquivalentTo(dynamicEnums));
                CheckEnumsMatch(t.VisibleEnums, enums);
                Assert.That(t.VisibleIntegers, Is.EquivalentTo(integers));
                Assert.That(t.VisibleLocalDynamicEnums, Is.EquivalentTo(localDynamicEnums));
                Assert.That(t.VisibleLocalizedStrings, Is.EquivalentTo(localizedStrings));

                var expected = decimals.Select(x => x.TypeId).
                               Concat(integers.Select(x => x.TypeId)).
                               Concat(enums.Select(x => x.TypeId)).
                               Concat(dynamicEnums.Select(x => x.TypeId)).
                               Concat(localDynamicEnums.Select(x => x.TypeId)).
                               Concat(localizedStrings.Select(x => x.TypeId)).
                               Concat(others.Select(x => x.TypeId)).
                               Concat(enums.Select(x => ParameterType.ValueSetType.Of(x.TypeId))).
                               Concat(hiddenEnums.Select(x => x.TypeId)).          //AllTypes includes hidden types
                               Concat(hiddenEnums.Select(x => ParameterType.ValueSetType.Of(x.TypeId))).
                               ToList();

                Assert.That(t.AllTypes, Is.EquivalentTo(expected));
            };

            ParameterType          modifiedType     = null;
            Action <ParameterType> modifiedCallback = x => { Assert.That(modifiedType, Is.Null); modifiedType = x; };

            t.Modified += modifiedCallback;

            CheckDecimals(decimals, t, CheckContents, ref modifiedType);

            CheckIntegers(integers, t, CheckContents, ref modifiedType);

            CheckEnums(enums, t, CheckContents, ref modifiedType, false);

            CheckEnums(hiddenEnums, t, CheckContents, ref modifiedType, true);

            CheckDynamicEnums(dynamicEnums, t, CheckContents, ref modifiedType);

            CheckLocalDynamicEnums(localDynamicEnums, t, CheckContents, ref modifiedType);

            CheckLocalizedStrings(localizedStrings, t, CheckContents, ref modifiedType);

            CheckOthers(others, t, CheckContents, ref modifiedType);
        }