Direct characterization of quantum dynamics: General theory