Skip to content

Commit b72cf97

Browse files
committed
Respond to comment
1 parent 24f9dd9 commit b72cf97

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

_posts/2023-08-14-replacing-mock-and-stub-with-a-fake.html

+27-14
Original file line numberDiff line numberDiff line change
@@ -239,25 +239,38 @@ <h2 id="comments-header">
239239
<div class="comment-content">
240240
<p>
241241
<p>
242-
Hi Mark,
243-
</p>
242+
Hi Mark,
243+
</p>
244244
<p>
245-
Firstly, thank you for another insightful article.
246-
</p>
245+
Firstly, thank you for another insightful article.
246+
</p>
247247
<p>
248-
I'm curious about using Fakes and testing exceptions. In scenarios where dynamic mocks (like Moq) are employed, we can mock a method to throw an exception, allowing us to test the expected behavior of the System Under Test (SUT).
249-
In your example, if we were using Moq, we could create a test to mock the UserRepository's Read method to throw a specific exception (e.g., SqlException). This way, we could ensure that the controller responds appropriately, perhaps with an internal server response.
250-
However, I'm unsure about how to achieve a similar test using Fakes. Is this type of test suitable for Fakes, or do such tests not align with the intended use of Fakes? Personally, I avoid using try-catch blocks in repositories or controllers and prefer handling exceptions in middleware (e.g., ErrorHandler). In such cases, I write separate unit tests for the middleware. Could this be a more fitting approach?
251-
Your guidance would be much appreciated.
252-
</p>
253-
<p>
254-
(And yes, I remember your advice about framing questions —it's in your 'Code that Fits in Your Head' book! :D )
255-
</p>
248+
I'm curious about using Fakes and testing exceptions. In scenarios where dynamic mocks (like Moq) are employed, we can mock a method to throw an exception, allowing us to test the expected behavior of the System Under Test (SUT).
249+
In your example, if we were using Moq, we could create a test to mock the UserRepository's Read method to throw a specific exception (e.g., SqlException). This way, we could ensure that the controller responds appropriately, perhaps with an internal server response.
250+
However, I'm unsure about how to achieve a similar test using Fakes. Is this type of test suitable for Fakes, or do such tests not align with the intended use of Fakes? Personally, I avoid using try-catch blocks in repositories or controllers and prefer handling exceptions in middleware (e.g., ErrorHandler). In such cases, I write separate unit tests for the middleware. Could this be a more fitting approach?
251+
Your guidance would be much appreciated.
252+
</p>
256253
<p>
257-
Thanks
258-
</p>
254+
(And yes, I remember your advice about framing questions —it's in your 'Code that Fits in Your Head' book! :D )
255+
</p>
256+
<p>
257+
Thanks
258+
</p>
259259
</p>
260260
</div>
261261
<div class="comment-date">2024-01-15 03:10 UTC</div>
262262
</div>
263+
264+
<div class="comment" id="d0ac4c5ecf444fb2a18b993ca16822de">
265+
<div class="comment-author"><a href="/">Mark Seemann</a> <a href="#d0ac4c5ecf444fb2a18b993ca16822de">#</a></div>
266+
<div class="comment-content">
267+
<p>
268+
Thank you for writing. That's a question that warrants an article or two. I've now published an article titled <a href="/2024/01/29/error-categories-and-category-errors">Error categories and category errors</a>. It's not a direct answer to your question, but I found it useful to first outline my thinking on errors in general.
269+
</p>
270+
<p>
271+
I'll post an update here when I also have an answer to your specific question.
272+
</p>
273+
</div>
274+
<div class="comment-date">2024-01-30 7:13 UTC</div>
275+
</div>
263276
</div>

0 commit comments

Comments
 (0)