private void TriggerParameters_Create_FromExistingTrigger(NotificationTrigger trigger, TriggerParameters parameters)
        {
            //shouldnt we _actually_ be checking that the values are the same?
            //and, shouldnt we be populating _all_ properties of the trigger first?

            //then, we need to make sure we can clone a trigger into some new parameters and add them successfully
            //and THEN, we need to write some tests for that

            foreach (var paramProp in PrtgAPIHelpers.GetNormalProperties(parameters.GetType()))
            {
                bool found = false;

                foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") ||
                        (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") ||
                        (paramProp.Name == triggerProp.Name))
                    {
                        found = true;
                        Assert.IsTrue(paramProp.GetValue(parameters) != null, $"Parameter '{paramProp}' was null");
                    }
                }

                if (!found)
                {
                    Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'");
                }
            }
        }
示例#2
0
        private void ValidateNewTrigger(TriggerParameters parameters, NotificationTrigger trigger, bool empty)
        {
            foreach (var paramProp in parameters.GetType().GetProperties2())
            {
                bool found = false;

                foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") ||
                        (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") ||
                        (paramProp.Name == triggerProp.Name))
                    {
                        found = true;
                        var paramValue   = paramProp.GetValue(parameters)?.ToString();
                        var triggerValue = triggerProp.GetValue(trigger)?.ToString();

                        if (empty && paramValue == null)
                        {
                            switch (triggerProp.Name)
                            {
                            case nameof(NotificationTrigger.Latency):
                                paramValue = "60";
                                break;

                            case nameof(NotificationTrigger.EscalationLatency):
                                paramValue = "300";
                                break;

                            case nameof(NotificationTrigger.Threshold):
                                paramValue = "0";
                                break;

                            case nameof(NotificationTrigger.RepeatInterval):
                                paramValue = "0";
                                break;
                            }
                        }

                        Assert.AreEqual(paramValue, triggerValue, triggerProp.Name);

                        //when we create a trigger without customization, some fields get default values
                        //we should have verification of those values, but ONLY when we're doing
                        //verification without customization. maybe we should have a bool on validatenewtrigger
                        //that indicates whether this is without customization, and ONLY THEN do we say ok
                        //paramValue can be null but triggerValue can be <something>
                    }
                }

                if (!found)
                {
                    Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'");
                }
            }
        }
示例#3
0
        private void TriggerParameters_Create_FromExistingTrigger(NotificationTrigger trigger, TriggerParameters parameters)
        {
            foreach (var paramProp in parameters.GetType().GetProperties2())
            {
                bool found = false;

                foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") ||
                        (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") ||
                        (paramProp.Name == triggerProp.Name))
                    {
                        found = true;
                        Assert.IsTrue(paramProp.GetValue(parameters) != null, $"Parameter '{paramProp}' was null");
                    }
                }

                if (!found)
                {
                    Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'");
                }
            }
        }