Preheat your oven to 400°F (200°C).
Bring a large pot of heavily salted water to a boil.
While the water heats, place a large skillet over medium-high heat and add the olive oil or butter.
Once hot, add the sliced mushrooms.
Cook, stirring occasionally, until they have released their liquid and started to brown, about 5-7 minutes.
Add the diced onion and minced garlic to the skillet.
Season with salt and pepper.
Reduce the heat to medium and cook until the onion is soft and translucent, about 3-4 minutes.
Pour in the canned tomatoes with their liquid.
Stir everything together and bring the sauce to a simmer.
Reduce the heat to low and let it bubble gently while you cook the pasta.
Add the ziti to the boiling water and cook for about half the time recommended on the package. The pasta should be very firm and not yet pleasant to eat.
Drain the pasta, but don't shake off all the water; a little starchy water helps the sauce cling.
In a large bowl, combine the undercooked pasta with the mushroom-tomato sauce and about half of the grated mozzarella.
Toss well to ensure everything is evenly coated.
Lightly grease a 9x13 inch baking dish.
Pour the pasta mixture into the dish and spread it into an even layer.
Top with the remaining mozzarella and the grated Parmesan cheese.
Bake for 20-30 minutes, or until the cheese is melted, bubbly, and beautifully browned on top.
Let it rest for a few minutes before serving.
Don't overcook the pasta! It should be noticeably underdone and too firm to eat before baking. It will finish cooking in the sauce, resulting in a perfect al dente texture, not mush.
Grate your own mozzarella from a block. Pre-shredded cheeses contain anti-caking agents that prevent them from melting as smoothly and creamily.