Refactoring the creating of an AppContext for tests.