private void TriggerParameters_AllProperties_HaveValues(TriggerParameters parameters, Func <PropertyInfo, bool> additionalChecks = null)
        {
            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 the empty notification action");
                }

                else
                {
                    if (!additionalChecks(prop))
                    {
                        Assert.IsTrue(val != null, $"Property '{prop.Name}' had value did not have a value.");
                    }
                }
            }
        }
        private void TriggerParameters_AllProperties_HaveDefault(TriggerParameters parameters, Func <PropertyInfo, bool> additionalChecks = null)
        {
            TestReflectionHelpers.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");
                    }
                }
            }
        }
예제 #3
0
        private string ToAction(string value)
        {
            if (value?.StartsWith("-1|") == true)
            {
                return(((ISerializable)TriggerParameters.EmptyNotificationAction()).GetSerializedFormat());
            }

            return(null);
        }
예제 #4
0
        public object Deserialize(object value)
        {
            if (value == null)
            {
                value = TriggerParameters.EmptyNotificationAction();
            }

            return(value);
        }
예제 #5
0
        public object Serialize(object value)
        {
            if (value == null)
            {
                value = TriggerParameters.EmptyNotificationAction();
            }

            var serializable = value as ISerializable;

            if (serializable != null)
            {
                return(serializable.GetSerializedFormat());
            }
            else
            {
                return(value);
            }
        }
예제 #6
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.");
            }
        }
예제 #7
0
        private void TriggerParameters_Edit_CanSetUnsetValue(TriggerParameters parameters)
        {
            var properties = parameters.GetType().GetProperties2();

            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.");
                }

                prop.SetValue(parameters, ReflectionHelpers.GetDefaultUnderlying(prop.PropertyType));
                Assert.IsTrue(prop.GetValue(parameters) != null, $"Property '{prop.Name}' was null.");
            }
        }
        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) : TestReflectionHelpers.GetDefaultUnderlying(prop.PropertyType);

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