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");
                    }
                }
            }
        }
Example #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(TestReflectionHelpers.IsDefaultValue(prop, obj), $"Property '{prop.Name}' did not have a value.");
                }
            }
        }
        public IEnumerator WhenAssetBundleLoadedThroughUWR_NoMainThreadFileIO()
        {
            AsyncOperationHandle <GameObject> h;

            try
            {
                TestReflectionHelpers.SetResritctMainThreadFileIO(true);
                h = m_Addressables.LoadAssetAsync <GameObject>(GetForceUWRAddrName(0));
                yield return(h);
            }
            finally
            {
                TestReflectionHelpers.SetResritctMainThreadFileIO(false);
            }
            h.Release();
        }
Example #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(TestReflectionHelpers.IsDefaultValue(prop, obj), $"Property '{prop.Name}' did not have a value.");
                }
            }

            foreach (var field in obj.GetType().GetFields(flags))
            {
                if (!customHandler(field))
                {
                    Assert.IsFalse(TestReflectionHelpers.IsDefaultValue(field, obj), $"Property '{field.Name}' did not have a value.");
                }
            }
        }
        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.");
            }
        }