public void BuildComponentType_ThrowsArgumentException_WithExpectedFailures(Type type, string keywordPattern)
 {
     Assert.That(
         () => TypeManager.BuildComponentType(type),
         Throws.ArgumentException.With.Message.Matches(keywordPattern)
         );
 }
        public void BuildComponentType_ThrowsArgumentException_WithExpectedFailures(
            Type type, string messageStartsWith
            )
        {
            var e = Assert.Throws <ArgumentException>(() => TypeManager.BuildComponentType(type));

            Assert.That(e.Message, new StartsWithConstraint(messageStartsWith));
        }
        public void BuildComponentType_WithComponent_WhenUnityEngineComponentTypeIsCorrect_DoesNotThrowException()
        {
            var componentType = TypeManager.UnityEngineComponentType;

            TypeManager.UnityEngineComponentType = typeof(UnityEngine.Component);
            try
            {
                TypeManager.BuildComponentType(typeof(UnityEngine.Transform));
            }
            finally
            {
                TypeManager.UnityEngineComponentType = componentType;
            }
        }
        public void BuildComponentType_WithClass_WhenUnityEngineComponentTypeIsNull_ThrowsArgumentException(Type type)
        {
            var componentType = TypeManager.UnityEngineComponentType;

            TypeManager.UnityEngineComponentType = null;
            try
            {
                var e = Assert.Throws <ArgumentException>(() => TypeManager.BuildComponentType(type));
                Assert.That(e.Message, new StartsWithConstraint($"{type} cannot be used from EntityManager. If it inherits UnityEngine.Component"));
            }
            finally
            {
                TypeManager.UnityEngineComponentType = componentType;
            }
        }
        public void BuildComponentType_WithNonComponent_WhenUnityEngineComponentTypeIsCorrect_ThrowsArgumentException()
        {
            var componentType = TypeManager.UnityEngineComponentType;

            TypeManager.UnityEngineComponentType = typeof(UnityEngine.Component);
            try
            {
                var type = typeof(TypeManagerTests);
                var e    = Assert.Throws <ArgumentException>(() => TypeManager.BuildComponentType(type));
                Assert.That(e.Message, new StartsWithConstraint($"{type} must inherit {typeof(UnityEngine.Component)}"));
            }
            finally
            {
                TypeManager.UnityEngineComponentType = componentType;
            }
        }
        public void BuildComponentType_WithClass_WhenUnityEngineComponentTypeIsNull_ThrowsArgumentException(Type type)
        {
            var componentType = TypeManager.UnityEngineComponentType;

            TypeManager.UnityEngineComponentType = null;
            try
            {
                Assert.That(
                    () => TypeManager.BuildComponentType(type),
                    Throws.ArgumentException.With.Message.Matches($"\\bregister\\b.*\\b{nameof(TypeManager.UnityEngineComponentType)}\\b")
                    );
            }
            finally
            {
                TypeManager.UnityEngineComponentType = componentType;
            }
        }
        public void BuildComponentType_WithNonComponent_WhenUnityEngineComponentTypeIsCorrect_ThrowsArgumentException()
        {
            var componentType = TypeManager.UnityEngineComponentType;

            TypeManager.UnityEngineComponentType = typeof(UnityEngine.Component);
            try
            {
                var type = typeof(TypeManagerTests);
                Assert.That(
                    () => TypeManager.BuildComponentType(type),
                    Throws.ArgumentException.With.Message.Matches($"\\bmust inherit {typeof(UnityEngine.Component)}\\b")
                    );
            }
            finally
            {
                TypeManager.UnityEngineComponentType = componentType;
            }
        }