-
Hey guys! I'm have a method in my business layer that i'm want to test it. I'm using the package to throw a TooManyRequest result something like:
When i'm call the method, i'm want that result of the request be a TooManyRequests return. Specifially, i'm trying to do a test case for my if condition in my unit test:
How to do that? The first code don't work. Glad for a help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @Raphsodyz . I ran your code and it's working properly. When we call the mocked url the return is 429 (Too many requests). Verify if the URL passed to the You said it's not working, but didn't show the error message. Could you complete the example with the error message? |
Beta Was this translation helpful? Give feedback.
I think the error is in your code.
You are trying to read the property
LaunchView.Exception
inAssert.IsType<AggregateException>(result.Exception);
but you are not saving the value of the exception in this property and returning it gracefully.When the status code is not 200 you throw an exception and not catching it.
The correct way to test it is by calling
Assert.ThrowsAsync
if you are using XUnit or equivalent in another package.Pay attention to await too. You are using an async method and not awaiting. So at line
var result = busine…