God is all knowing, it is part of His divine nature.
God knows in advance who will obey or refuse His commands.
God knew that Abraham and Moses would obey but He also knew that Cain and King Saul would disobey, nevertheless God still gave them His commands.
So why is Genesis 22:12 written is...