Example #1
0
 public Css.Value GetValue(string name)
 {
     if (SpecifiedValues.TryGetValue(name, out Css.Value result))
     {
         return(result);
     }
     return(null);
 }
Example #2
0
            public void Run()
            {
                foreach (ConstructorInfo constructor in TargetType.GetConstructors())
                {
                    ParameterInfo[] parameters = constructor.GetParameters();

                    object?[] parameterValues = parameters
                                                .Select(p => p.ParameterType)
                                                .Select(t =>
                    {
                        if (SpecifiedValues.TryGetValue(t, out object?value))
                        {
                            return(value);
                        }
                        Mock mock = (Mock)Activator.CreateInstance(typeof(Mock <>).MakeGenericType(t)) !;
                        return(mock.Object);
                    })
                                                .ToArray();

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        object?[] values = parameterValues.ToArray();
                        values[i] = null;

                        if (AllowedNullParameters.Contains(parameters[i].ParameterType) ||
                            parameters[i].HasDefaultValue && parameters[i].DefaultValue is null)
                        {
                            //NB: no exception thrown
                            constructor.Invoke(values);
                        }
                        else
                        {
                            string parameterDisplay      = $"'{parameters[i].Name}' ({parameters[i].ParameterType.Name})";
                            TargetInvocationException ex = Assert.ThrowsException <TargetInvocationException>(new Action(() =>
                            {
                                object?rv = constructor.Invoke(values);
                                throw new Exception($"Expected {nameof(ArgumentNullException)} for null parameter {parameterDisplay} but no exception was thrown");
                            }));
                            if (ex.InnerException is ArgumentNullException argumentNullException)
                            {
                                Assert.AreEqual(parameters[i].Name, argumentNullException.ParamName);
                            }
                            else
                            {
                                throw new Exception($"Thrown argument for {parameterDisplay} was '{ex.InnerException?.GetType().Name}' not {nameof(ArgumentNullException)}.", ex.InnerException);
                            }
                        }
                    }
                }
            }
Example #3
0
        private void LoadSpecifiedValues()
        {
            try
            {
                LstValues.BeginUpdate();
                Enable(false);
                LstValues.Items.Clear();

                LstValues.Items.AddRange(GetObjectCollection(SpecifiedValues.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)));
            }
            finally
            {
                LstValues.EndUpdate();
                Enable(true);
            }
        }
Example #4
0
        private void SpecifyStringValuesDialog_Load(object sender, EventArgs e)
        {
            Text = Title;
            Enable(false);

            SpecifiedValues = string.IsNullOrWhiteSpace(SpecifiedValues) ? string.Empty : SpecifiedValues.Replace("\n", string.Empty);

            LoadSpecifiedValues();
        }