Farmer barred from market over gay marriage goes to court