Exemple #1
0
        private void TriggerParameters_AllProperties_HaveDefault(TriggerParameters parameters, Func <PropertyInfo, bool> additionalChecks = null)
        {
            TestReflectionUtilities.NullifyProperties(parameters);

            if (additionalChecks == null)
            {
                additionalChecks = p => false;
            }

            foreach (var prop in PrtgAPIHelpers.GetNormalProperties(parameters.GetType()))
            {
                var val = prop.GetValue(parameters);

                if (prop.Name.EndsWith("NotificationAction"))
                {
                    Assert.IsTrue(val.ToString() == TriggerParameters.EmptyNotificationAction().ToString(), $"Property '{prop.Name}' had value {val}");
                }
                else
                {
                    if (!additionalChecks(prop))
                    {
                        Assert.IsTrue(val == null, $"Property '{prop.Name}' was not null");
                    }
                }
            }
        }
Exemple #2
0
        public static void AllPropertiesAreNotDefault(object obj, Func <PropertyInfo, bool> customHandler = null)
        {
            if (customHandler == null)
            {
                customHandler = p => false;
            }

            foreach (var prop in obj.GetType().GetProperties())
            {
                if (!customHandler(prop))
                {
                    Assert.IsFalse(TestReflectionUtilities.IsDefaultValue(prop, obj), $"Property '{prop.Name}' did not have a value.");
                }
            }
        }
Exemple #3
0
        private void TriggerParameters_Edit_CanSetUnsetValue(TriggerParameters parameters)
        {
            var properties = PrtgAPIHelpers.GetNormalProperties(parameters.GetType());

            foreach (var prop in properties)
            {
                prop.SetValue(parameters, null);
                if (prop.Name == nameof(TriggerProperty.OnNotificationAction) || prop.Name == nameof(TriggerProperty.OffNotificationAction) || prop.Name == nameof(TriggerProperty.EscalationNotificationAction))
                {
                    Assert.IsTrue(prop.GetValue(parameters).ToString() == TriggerParameters.EmptyNotificationAction().ToString(), $"Property '{prop.Name}' was not empty.");
                }
                else
                {
                    Assert.IsTrue(prop.GetValue(parameters) == null, $"Property '{prop.Name}' was not null.");
                }

                object defaultValue = null;

                if (prop.PropertyType.Name == nameof(TriggerChannel))
                {
                    defaultValue = new TriggerChannel(1234);
                }
                else if (prop.Name == nameof(VolumeTriggerParameters.UnitSize))
                {
                    if (parameters is VolumeTriggerParameters)
                    {
                        defaultValue = TestReflectionUtilities.GetDefaultUnderlying(typeof(DataVolumeUnit)).ToString().ToEnum <DataUnit>();
                    }
                    else
                    {
                        defaultValue = TestReflectionUtilities.GetDefaultUnderlying(prop.PropertyType);
                    }
                }
                else
                {
                    defaultValue = TestReflectionUtilities.GetDefaultUnderlying(prop.PropertyType);
                }

                prop.SetValue(parameters, defaultValue);
                Assert.IsTrue(prop.GetValue(parameters) != null, $"Property '{prop.Name}' was null.");
            }
        }
Exemple #4
0
        public static void AllPropertiesAndFieldsAreNotDefault(object obj, Func <MemberInfo, bool> customHandler = null)
        {
            if (customHandler == null)
            {
                customHandler = p => false;
            }

            foreach (var prop in obj.GetType().GetProperties(flags).Where(p => !p.GetIndexParameters().Any()))
            {
                if (!customHandler(prop))
                {
                    Assert.IsFalse(TestReflectionUtilities.IsDefaultValue(prop, obj), $"Property '{prop.Name}' did not have a value.");
                }
            }

            foreach (var field in obj.GetType().GetFields(flags))
            {
                if (!customHandler(field))
                {
                    Assert.IsFalse(TestReflectionUtilities.IsDefaultValue(field, obj), $"Property '{field.Name}' did not have a value.");
                }
            }
        }
Exemple #5
0
        private void TriggerParameters_Edit_CanSetUnsetValue(TriggerParameters parameters)
        {
            var properties = PrtgAPIHelpers.GetNormalProperties(parameters.GetType());

            foreach (var prop in properties)
            {
                prop.SetValue(parameters, null);
                if (prop.Name == nameof(TriggerProperty.OnNotificationAction) || prop.Name == nameof(TriggerProperty.OffNotificationAction) || prop.Name == nameof(TriggerProperty.EscalationNotificationAction))
                {
                    Assert.IsTrue(prop.GetValue(parameters).ToString() == TriggerParameters.EmptyNotificationAction().ToString(), $"Property '{prop.Name}' was not empty.");
                }
                else
                {
                    Assert.IsTrue(prop.GetValue(parameters) == null, $"Property '{prop.Name}' was not null.");
                }

                var defaultValue = prop.PropertyType.Name == "TriggerChannel" ? new TriggerChannel(1234) : TestReflectionUtilities.GetDefaultUnderlying(prop.PropertyType);

                prop.SetValue(parameters, defaultValue);
                Assert.IsTrue(prop.GetValue(parameters) != null, $"Property '{prop.Name}' was null.");
            }
        }