pregancy test working

if you have sex one night,think condom stuffed up, so take a pregnancy test and it say positive therefore get morning after pill. would that work.or not because if i says pregnant you cant stop it once happened. AND how long after ejaqualation are you pregnant. thankyou x