@Vivian Qiao,
You should choose A。First, as for A, "when" can guide the adverbial clause of time to modify the matrix, the two sentences happened at the sametime. The structure is "be… when + the past tense"。As for B, "was to do" is used in the past future tense. It is not in accordance with the clause。As for C and D, it is not suitable for the sentence's meaning。