Canonical and microcanonical ensemble descriptions of thermal pairing within BCS and quasiparticle random-phase approximation