BO4ETestProject/TestBOCOMDesign.cs
/// <summary>
///     There must be no fields in BusinessObjects or COMponents where you cannot distinguish no value (null) and initial
///     value (e.g. ENUM default values or integer 0)
/// </summary>
There must be no fields in BusinessObjects or COMponents where you cannot distinguish no value (null) and initial
value
There must be no fields in BusinessObjects or COMponents where you cannot distinguish no value ( null ) and initial value
[TestMethod]
        public void NullableDefaultEnums()
        {
            foreach (var boType in typeof(BusinessObject).Assembly.GetTypes().Where(t => (t.BaseType == typeof(BusinessObject) || t.BaseType == typeof(COM)) && !t.IsAbstract))
            {
                foreach (var obligDefaultField in boType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance).Where(field => field.GetCustomAttributes(typeof(JsonPropertyAttribute), true).Cast<JsonPropertyAttribute>().Any(jpa => jpa.Required == Required.Default)))
                {
                    if (Nullable.GetUnderlyingType(obligDefaultField.PropertyType) != null || obligDefaultField.PropertyType == typeof(string))
                    {
                        continue;
                    }
                    if (!obligDefaultField.PropertyType.IsPrimitive && !obligDefaultField.PropertyType.IsEnum)
                    {
                        continue;
                    }
                    Assert.IsTrue(false, $"The type {obligDefaultField.PropertyType} of {boType.FullName}.{obligDefaultField.Name} is not nullable but not marked as obligatory.");
                }
            }
        }
[ TestMethod ] public void NullableDefaultEnums ( ) { foreach ( var boType in typeof ( BusinessObject ) . Assembly . GetTypes ( ) . Where ( t => ( t . BaseType == typeof ( BusinessObject ) || t . BaseType == typeof ( COM ) ) && ! t . IsAbstract ) ) { foreach ( var obligDefaultField in boType . GetProperties ( BindingFlags . DeclaredOnly | BindingFlags . Public | BindingFlags . Instance ) . Where ( field => field . GetCustomAttributes ( typeof ( JsonPropertyAttribute ) , true ) . Cast < JsonPropertyAttribute > ( ) . Any ( jpa => jpa . Required == Required . Default ) ) ) { if ( Nullable . GetUnderlyingType ( obligDefaultField . PropertyType ) != null || obligDefaultField . PropertyType == typeof ( string ) ) { continue ; } if ( ! obligDefaultField . PropertyType . IsPrimitive && ! obligDefaultField . PropertyType . IsEnum ) { continue ; } Assert . IsTrue ( false , $" The type  { obligDefaultField . PropertyType }  of  { boType . FullName } . { obligDefaultField . Name }  is not nullable but not marked as obligatory. " ) ; } } }
There must be no fields in BusinessObjects or COMponents where you cannot distinguish no value (null) and initial
value (e.g.
There must be no fields in BusinessObjects or COMponents where you cannot distinguish no value ( null ) and initial value ( e . g .
// it is already nullable.  // this is a problem because e.g. for integers you can't distinguish between no value (null) or initial value (0). Same is true for Enum values