Pregnancy testing?

How long after unprotected sex will i be able to a pregnancy test and it be accurate?