Preheat the oven to 350°F (175°C).
Blanch the chopped green beans in boiling water for 2 minutes. Then strain them and rinse immediately with cold water to stop the cooking process. Set aside.
Cook the macaroni noodles or shells in salted boiling water according to package instructions, until al dente. Drain and set aside.
In a large pot or Dutch oven, melt the butter over medium heat. Add the sliced mushrooms and minced garlic, and cook for 1-2 minutes until softened.
Whisk in the flour and cayenne pepper to make a paste. Season generously with salt and black pepper.
Slowly whisk in the milk and vegetable stock, making sure the flour paste is fully incorporated and there are no lumps.
Stir in 12 ounces of the shredded cheese until melted and smooth. Then add the cooked green beans and pasta, and stir until everything is coated with the cheese sauce.
Transfer the mixture to a greased 9x13 inch baking dish. Sprinkle the remaining shredded cheese and fried onions on top.
Cover the dish with aluminum foil and bake for 15 minutes. Then remove the foil and bake for another 15 minutes, or until the cheese is melted and bubbly and the fried onions are golden brown.
Let the casserole cool for a few minutes before serving. Enjoy!