Some options in my order of preference:
Use a SMS api service and let the code retrieve the SMS text from that service.
Probably you do not want to test the TwoFactorAuth, but you want to test the application behind it. Consider building a backdoor which is only enabled in the test environment, so that you can bypass the TFA.
Generate the OTP from code with OTP.Net: https://dev.to/j_sakamoto/selenium-testing---how-to-sign-in-to-two-factor-authentication-2joi
I have read that people try to create an Appium test to retrieve the OTP so that could be another path: https://discuss.appium.io/t/how-to-read-otp-from-messages-using-appium/16949/8
Use a SMS api service and let the code retrieve the SMS text from that service.
Overall this is pretty challenging and makes the test setup complex and contain dependecies, there for I would go for the backdoor option.