Your content is always worth the wait. I trust your goal is to teach TDD by practice with this series, but I do wonder if the world needs more demonstrations of RESTful APIs...maybe a graphql api or a grpc application in the future? Just a thought. Looking forward to this series!
Thanks for the video! The code looks clean, but I want to give feedback to avoid pitfalls when going into more complex application testing: - Unit testing controllers is rarely necessary. This is a controversial topic, but I recommend keeping controller layer as a pass-through for example with mediator pattern and use integration tests to cover the controller code. When doing the design this way there is usually no need to mock anything, just use a real data storage for the tests instead. This makes understanding the code and debugging the failure much easier. - Test behavior, not implementation details. The main test here tests that a service calls an external API when calling the controller method. When testing the controller we are not interested how it gets the users, but the fact that it does so. Now the test is dependent on both controller and service interface code. When the service interface changes, the test breaks even though it will return the users correctly. - When considering the two issues above and the fact that we still need an integration test to make sure that the users are returned correctly to the caller we start to see why unit testing controllers is not a good idea. - Use setup (and teardown) methods to put shared initialization code into one place. The tests are almost the same and are already pretty long for what they do. - TDD is much wider concept than unit testing. I see TDD as a tool to test how the system should behave. You start the process before writing any actual production code. This is tough for development-oriented mind. It is easier to think about testing "did it return 404" or "was that method called" instead of "were the requested details of the users stored returned back to the caller correctly". The commentary, phasing and the code layout is good. Keep posting!
All great points, thanks for sharing. Hopefully I’ll make a follow up sharing integration and e2e tests with a larger codebase in the future. All the best 😀
Hello @Greenthum6 I have a question about this statement: "When the service interface changes, the test breaks even though it will return the users correctly". Imagine we have sarvice A and this service uses service B. How would u write (unit) tests for service A, that will not breaks after changing interface of service B? Are you testing everything with a "balck box tests" (testing income and outcome) without mocking? You wrote that we should not unit test controllers because of integration/e2e tests are covering them. I disagree. Integration/e2e tests are the next layer of tests (they are testing how "integration" with 3-party software works) and they should not be the reason to not write unit tests. Can you help me by showing what I'm missing? I'm ready to change my mind.
@Tantol You are probably confusing the scope of unit and integration tests. Integration tests are for testing two or more units together. Not only 3rd party, but also your own code components. In your example, testing services A and B together is essentially an integration test. If there is already an integration test for testing them together, what value does a unit test add? Controllers should have simple logic and only a very few code paths. You ideally want to test all those code paths with integration tests. Then again, unit tests don't add more value. If you only rely on unit tests, you can't be sure how your code works with the rest of the application. My advice is to start testing at the service level first and add unit tests where they add value. This helps to understand how your service works and how it solves the actual business problem.
@@Greenthum6 "testing services A and B together is essentially an integration test" I meant not togheter. I meant testing only service A that uses service B that I'm mocking in ex.: I would test if my function X from service A calls function Y from service B by mocking and verifying if it was called. And now if I change interface code for service B my tests on service A will not work even if outcome of function Y is the same as before - "When the service interface changes, the test breaks even though it will return the users correctly" My function Y (from service B) still returns same users after interface change. How to test this scenario to prevent breaking tests after interface change? This is where I have struggle for service scenario. For controller scenario now I see your point that this makes no sens to write unit tests on top of integration tests (waste of time and money). But for me it dose not make sense when testing service with mocking. These tests will always break after interface change and those I call unit tests (I'm separating logic by mocking). Or mb. I misinterpreted you and that sentence was only meant with controller in mind? If so I have no more questions.
@Tantol My response was mainly for controller testing. Unit testing a service does not make sense as you unit test only a part of it. When service B changes its interface, your unit test for service A still works since the mock is using the previous interface. When you update the production code in service A to newer service B your unit test may also break at build time, or it could just work depending on the mock code. Service interface changes should be rare, but unavoidable. If you have a lot of mocks there may be some manual rewriting needed. This is where an integration test is often better as it tests more the behavior than the implementation details. As a side note, I hate to read abundant mock code. It is really hard to understand later.
Thanks for a great video. I have kind of the same question as Cris Yapp though. It looks like you changed SetupBasicGetResourceList(List expectedResponse, string endpoint) method off camera so there you are no longer using the endpoint parameter. When left unchanged the test will fail for reasons I do not understand, even though the UsersService is not harcoded with the foo endpoint but using the config. It would be great to get some explanations for this.
Yes, actually I think it was an unnecessary parameter even at beginning, we are giving endpoint to conf ( options ) then giving it to UserService through constructor, that means it will request to endpoint we give, no need to give it also at the mockhandler method call. I guess he noticed and changed it but forgot the record or editing video.
Hi Wes, This is really a great video and helped me a lot to gain a new perspective to approach a problem statement or requirement. You made me fall in love with the TDD approach :D I would really like to see how we can further use this approach to create loosely coupled architecture with a database (SQL / No SQL). Will we see more continuation of this video?
Never return 404 instead of empty lists, it's a bad API design. Do return 404 for not found objects, though (e.g. for GET /users/42 when no user with the ID of 42 exists).
Great video Wes! Glad to se your vids back!.. I just had one question though as I was following along, when you set up the mock HttpMessageHandler and then you created the overloaded function SetUpBasicGetResourceList(List expectedResponse, string endPoint), I noticed that at first you created a custom HttpRequestMessage obj, then passed that in as a parameter in to the handlerMock.Protected().SetUp() instead of using ItExpr.IsAny(), then at the end when the test failed and you returned to that Mock it was changed back to ItExpr.IsAny() and there wasnt a custom HttpRequestMessage obj being used... what did I miss? Keep up the content dude!
I think I understand the most of ot, but I will have to retake that lesson later becasue the part about MockHttpRequest is a little bit too fast and complicated for me. I need to disassemble it into smaller pieces :D Great video though! But im my opinion there are things that you should change a bit : -Go a little slower, I had to stop the recording several times in order to find myself and catchup. -you should Go more into details, because you go like " I do that, and then that" bo no explenation why etc. - sometimes you just click stuff really fast without additional comments. That would also be nice :)
Thanks a lot! Usually I decare tested class and mocks as local variables in test class and create it in constructor. In this case in test method all we have to do - setup mocks, execute method and do assert/verify. If we add new parameter into tested class constructor - refactoring is much easier.
I'd like to help out adding some hot keys and commands to make your coding even swifter: Edit a class or object's name and replace it in all its callings: -}> Ctrl + R + R Add a new file .cs (interface, class, etc) -}> ctrl + shift + A Open the Quick actions and refactorings: -}> Ctrl + . (dot) I'll keep adding more hot keys as I follow the video
hi wes!, just keep on doing what you are doing, honestly this channel needs more views, i learned alot from wes and will always learn more. thank you so much wes!
Hi, I have some comments which are to help future tutorials. I managed to follow up to nearly the end and then boom all went pear shaped. Being a novice I have not the skills to work out the problems. My comments are, perhaps go a little slower, the keyboard clicking and the constant movement of your cursor for no reason is really distracting. It would be nice to have a resource file. Thus for people like me that have followed along but some where missed a key line and it goes wrong we would be able to look at the working code and see where we didn't follow your quick commentary close enough. I mean this by no means to be negative. :) Thanks for the video.
Out of curiosity. Why do you create your project files using the command line, rather than just using Visual Studio GUI? BTW I love your video. Very educational :)
Thanks for this great video! I'm curious about what font / colors / theme settings you use for Visual Studio? Do you have some information on that somewhere? (new subscriber here) All the best!
Hi Wes! I was wondering how I can test CRUD operations following your procedure. Take Delete for example. How should I register mock service when the API returns NoContent Status Code? something like mockService.Setup(service=> service.DeleteUser(id)).Returns()...I don't know how to complete this piece of code after Returns for a Delete Function which is registered as a task without any return object in UserService!
Great teaching and explanation of the material. However, I watched it with some difficulty because the constant keyboard clicking was quite distracting.
Hi Wes, thanks for posting this video I am learning some new concepts here. I am coding along with the video and have ran into a problem at around 1h14m when "GetAllUsers_WhenCalled_InvokesHttpGetRequest()" and "GetAllUsersWhenCalled_ReturnsListOfUsers()" both return the same failed test message. The message reads: "System.ArgumentException : No protected method HttpMessageHandler.SendAsync found whose signature is compatible with the provided arguments (HttpResponseMessage, CancellationToken)." As far as I am aware I have copied the coding perfectly, but it is possible I have made a mistake somewhere. Do you know what is causing these tests to fail? Thanks in advance, Jon
I'm only recently working on wrapping my head around unit testing and TDD more specifically. I'm curious, in GetAllUsers_WhenCalled_ReturnsListOfUsers, would it be good to give the handlerMock a COPY of the expectedResponse Users list and then assert that result and expectedResponse contain the same items? By only asserting the count, you don't know for sure that the list isn't being manipulated in some other way after being returned from the HttpClient. Or is that overkill?
Hi Kevin, great question. I'd say it depends on a few factors! One consideration would be overall application architecture. The minimal API setup seems ideal for thinking small services / microservices pattern.
Does the creating interface IUserService first for that InvokesUserService breaks the tdd pattern? Don't see point in creating mock of something that does not exists, you get build errors and you lose intelisense
Amazing tutorial. So much better than the stupid tutorials that show you some kind of TDD in a command line project with no follow up on how it would be applied to the real world development. Also your way of mocking the HttpClient is something I tried to find a couple of times but failed.
Hi, this has always been a question I have on my mind. Is there any particular reason that you choose to use command line to create new solution and projects vs using Visual Studio or something has a GUI?
Great explanation, Thank you ! Just one question any particular reason why you did not choose MS TEST project in VS instead of XUnit ? Is it a hard rule that we should use XUnit project for TDD or can we do the same with MS Test ?
Hi @Wes, wondering if there would be a TDD video using factories, seeding data? Do you know or anyone here an excellent resource where I can find TDD with factories, mocking, seeding using .NET and that uses .NET CORE 6 or above?
Hello, I've question how do you solve this error on moq "Handler did not return a response message.", I try using same URL Address but still got that error
This is not pure TDD. I think you make things more difficult for people who actually want to look at net core TDD, as a 3rd or 4th language, but actually know TDD ...
Very good content. Thanks a lot for this guide. Just a comment as a viewer on something a bit annoying, too many code highlighting and navigation keyboard tricks, as your keystrokes are very loud. It's sometimes hard to focus on what you're saying seeing you going back and forward and highlighting every piece of code. 😉 Nevertheless, appreciate your effort doing such good video.
It's an awesome content for people getting into testing, but those unnecessary amounts of key presses got me a bit too hard :D Like WHY :D 17:14 - 17:17. Way too loud for me to concentrate on the actual thing that's going on.
Hi Kresno, since I'm mocking out dependencies to test the method calls in isolation, I refer to this as unit testing. I tend to call integration tests those tests which encompass a greater system (e.g. integrating a database, network, or hardware). Thanks for watching!
13:00 - in TDD, you would remove that controller completely, and let tests drive creation of it. 13:20 - premature creation of Helpers and Fixtures 16:23 - explanation of why it's okay to leave the users controller "we know that's what it's going to look like". that's not tdd. that's coming up with code without tests. 24:10 - the "all good" string is not necessary for the tests to pass. 32:10 - you have added the service, the mock and the inject without any tests for that at all. not tdd. you should first write an assertion without ever writing the mock, see the test fail, then implement the service without mocks, and then write another test for the overriden behaviour. in TDD you should not write any code without tests (but you did), and you should not write any more test code that is necessary to make the test fail (which you again did do). Not watching anymore since that's clearly not TDD. it's probably a good start to testing, a good introduction to TDD, but that's not TDD.
Thanks for the tutorial, but why on earth should we spend one hour and a half to write a simple method that returns a list in a real environment? really I can't get my head around it.
in time it takes far less time, of course. and sometimes the answer is likely that you shouldn’t. there always tradeoffs, and everything depends on context.
53:27 to remove all the unnecessary usings you can just press ctrl + k + e. Also, instead of replacing positions of brackets, you can set in IDE how ctrl + k +d should place them
Love it! Very cool! Can you make a video on how to become a .NET developer. In my area there are tons of jobs for .net and I would love to make the switch. Keep it up!
Hello, thank you for creating very educational content. I was wondering what is the console/termain you used in the beginning? The one with the tabbing options on top
hi - in this example tests of the external api takes a place - do you /have a video where you testing dbcontext? My application controllers are handling crud operations on existing db and its tables. I was wondering if you can show how to mock this type of scenario?
how you are able to type this fast ? . I noticed you are using some sort of tool that looks like vim. can you tell the name of the tool. by the way the video is great, easy explanation.
I don't know. Most boring video I have ever seen. How to stretch one or a couple of tests into dozens, and waste a lot of time getting same result of code as on classic. Maybe it wasn't the best example.
Ive been in IT for 20 years but im a new developer. If you plan on getting a job as an SDE, you MUST know how to unit test. Its a MUST. Especially at large companies. If you are just building stuff for yourself, then its fine if you dont test your code. We CANNOT get away with no unit tests and integration tests at work.
Like the explanation and the way you show this subject. But man does this become a cluttered mess and this is just a few lines of actual controller and service code. The TDD code and all it's setup and mocking takes up so moch lines and time. What is a reasonable size this will be when you actually have implemented this on a true production app. I get that this pays off when you modify stuff then without breaking things without you knowing but man, won't this slow down development cycles and drive up cost to triple? Really not trying to dis TDD I really want to use this but I have no reference with production size apps
The only bad thing about this tutorial is: WHY YOU ARE USING GODDAMN JAVA SYNTAX WHILE WRITING C#! Never put curly parentheses next to a component name! 😊
OK, got a really weird bug here / user error - I can't get the project to build / rebuild within Visual Studio. I make an edit e.g. change `return Ok("all good");` to `return Ok(users);` . Save the file. Hit "Run" in Test Explorer and the test is still failed. Run `dotnet test` in the terminal and it actually rebuilds the project and shows the test passing. How do I convince VS to actually rebuild the project?
Your content is always worth the wait. I trust your goal is to teach TDD by practice with this series, but I do wonder if the world needs more demonstrations of RESTful APIs...maybe a graphql api or a grpc application in the future? Just a thought. Looking forward to this series!
great feedback. thanks Natesh!
duh yes we do? The world still uses REST APIs in abundance and alot of us value diff content creators sharing how they go about teaching it.
@@WesDoyle
Can u provide a series of course about Unit Test for C# .
Your course is really helpful, thanks !
Better to focus content and teach one thing at a time.
Well, most Businesses hire devs to make or maintain RestApis.
This is quite possibly one of the best C# TDD examples, with an API/WebRequest I've seen on RUclips.
Thanks for the video! The code looks clean, but I want to give feedback to avoid pitfalls when going into more complex application testing:
- Unit testing controllers is rarely necessary. This is a controversial topic, but I recommend keeping controller layer as a pass-through for example with mediator pattern and use integration tests to cover the controller code. When doing the design this way there is usually no need to mock anything, just use a real data storage for the tests instead. This makes understanding the code and debugging the failure much easier.
- Test behavior, not implementation details. The main test here tests that a service calls an external API when calling the controller method. When testing the controller we are not interested how it gets the users, but the fact that it does so. Now the test is dependent on both controller and service interface code. When the service interface changes, the test breaks even though it will return the users correctly.
- When considering the two issues above and the fact that we still need an integration test to make sure that the users are returned correctly to the caller we start to see why unit testing controllers is not a good idea.
- Use setup (and teardown) methods to put shared initialization code into one place. The tests are almost the same and are already pretty long for what they do.
- TDD is much wider concept than unit testing. I see TDD as a tool to test how the system should behave. You start the process before writing any actual production code. This is tough for development-oriented mind. It is easier to think about testing "did it return 404" or "was that method called" instead of "were the requested details of the users stored returned back to the caller correctly".
The commentary, phasing and the code layout is good. Keep posting!
All great points, thanks for sharing. Hopefully I’ll make a follow up sharing integration and e2e tests with a larger codebase in the future. All the best 😀
Hello @Greenthum6 I have a question about this statement: "When the service interface changes, the test breaks even though it will return the users correctly".
Imagine we have sarvice A and this service uses service B. How would u write (unit) tests for service A, that will not breaks after changing interface of service B? Are you testing everything with a "balck box tests" (testing income and outcome) without mocking?
You wrote that we should not unit test controllers because of integration/e2e tests are covering them. I disagree. Integration/e2e tests are the next layer of tests (they are testing how "integration" with 3-party software works) and they should not be the reason to not write unit tests.
Can you help me by showing what I'm missing? I'm ready to change my mind.
@Tantol You are probably confusing the scope of unit and integration tests. Integration tests are for testing two or more units together. Not only 3rd party, but also your own code components.
In your example, testing services A and B together is essentially an integration test. If there is already an integration test for testing them together, what value does a unit test add?
Controllers should have simple logic and only a very few code paths. You ideally want to test all those code paths with integration tests. Then again, unit tests don't add more value. If you only rely on unit tests, you can't be sure how your code works with the rest of the application.
My advice is to start testing at the service level first and add unit tests where they add value. This helps to understand how your service works and how it solves the actual business problem.
@@Greenthum6 "testing services A and B together is essentially an integration test" I meant not togheter. I meant testing only service A that uses service B that I'm mocking in ex.:
I would test if my function X from service A calls function Y from service B by mocking and verifying if it was called. And now if I change interface code for service B my tests on service A will not work even if outcome of function Y is the same as before - "When the service interface changes, the test breaks even though it will return the users correctly" My function Y (from service B) still returns same users after interface change. How to test this scenario to prevent breaking tests after interface change?
This is where I have struggle for service scenario.
For controller scenario now I see your point that this makes no sens to write unit tests on top of integration tests (waste of time and money).
But for me it dose not make sense when testing service with mocking. These tests will always break after interface change and those I call unit tests (I'm separating logic by mocking).
Or mb. I misinterpreted you and that sentence was only meant with controller in mind? If so I have no more questions.
@Tantol My response was mainly for controller testing. Unit testing a service does not make sense as you unit test only a part of it. When service B changes its interface, your unit test for service A still works since the mock is using the previous interface. When you update the production code in service A to newer service B your unit test may also break at build time, or it could just work depending on the mock code. Service interface changes should be rare, but unavoidable. If you have a lot of mocks there may be some manual rewriting needed. This is where an integration test is often better as it tests more the behavior than the implementation details. As a side note, I hate to read abundant mock code. It is really hard to understand later.
Thanks for watching! What would you like to see next?
Thanks for a great video. I have kind of the same question as Cris Yapp though. It looks like you changed SetupBasicGetResourceList(List expectedResponse, string endpoint) method off camera so there you are no longer using the endpoint parameter. When left unchanged the test will fail for reasons I do not understand, even though the UsersService is not harcoded with the foo endpoint but using the config. It would be great to get some explanations for this.
Yes, actually I think it was an unnecessary parameter even at beginning, we are giving endpoint to conf ( options ) then giving it to UserService through constructor, that means it will request to endpoint we give, no need to give it also at the mockhandler method call. I guess he noticed and changed it but forgot the record or editing video.
Hi Wes,
This is really a great video and helped me a lot to gain a new perspective to approach a problem statement or requirement.
You made me fall in love with the TDD approach :D
I would really like to see how we can further use this approach to create loosely coupled architecture with a database (SQL / No SQL). Will we see more continuation of this video?
Great you're back Wes!! And with great content, as always!!
Never return 404 instead of empty lists, it's a bad API design. Do return 404 for not found objects, though (e.g. for GET /users/42 when no user with the ID of 42 exists).
Thank you Wes, we missed your videos😀
Great video Wes! Glad to se your vids back!.. I just had one question though as I was following along, when you set up the mock HttpMessageHandler and then you created the overloaded function SetUpBasicGetResourceList(List expectedResponse, string endPoint), I noticed that at first you created a custom HttpRequestMessage obj, then passed that in as a parameter in to the handlerMock.Protected().SetUp() instead of using ItExpr.IsAny(), then at the end when the test failed and you returned to that Mock it was changed back to ItExpr.IsAny() and there wasnt a custom HttpRequestMessage obj being used... what did I miss? Keep up the content dude!
Thank you so much for this comment! :)
I kept searching where I deviated from the code and finally found this comment - saved me a lot of headaches!
I think I understand the most of ot, but I will have to retake that lesson later becasue the part about MockHttpRequest is a little bit too fast and complicated for me. I need to disassemble it into smaller pieces :D
Great video though!
But im my opinion there are things that you should change a bit :
-Go a little slower, I had to stop the recording several times in order to find myself and catchup.
-you should Go more into details, because you go like " I do that, and then that" bo no explenation why etc.
- sometimes you just click stuff really fast without additional comments. That would also be nice :)
Welcome back Wes, hope you are well. Strangely I was on your channel the other day and was wondering where you had gone!
Thanks for the message Ryan! More to come!
Thanks a lot! Usually I decare tested class and mocks as local variables in test class and create it in constructor. In this case in test method all we have to do - setup mocks, execute method and do assert/verify. If we add new parameter into tested class constructor - refactoring is much easier.
Great insight on a nice way to set up tests, Eduard.Thanks!
I'd like to help out adding some hot keys and commands to make your coding even swifter:
Edit a class or object's name and replace it in all its callings: -}> Ctrl + R + R
Add a new file .cs (interface, class, etc) -}> ctrl + shift + A
Open the Quick actions and refactorings: -}> Ctrl + . (dot)
I'll keep adding more hot keys as I follow the video
Hi Wes!
Nice to have you back 🙂
Great to be back!
Good explanation on TDD. thanks.
A video on a web api/web dev project that is solid compliant would also be very much appreciated.
Very well explained Wes. Great work. I recently started watching your videos , and love them.
Oh god, this is the exact tutor I need right now.
Thumbs up! But I cannot really understand, why you fight againt your IDE in order to force Javascript-type bracket indentation. :)
This is such a valuable tutorial. Thank you so much.
Glad it was helpful!
Thank you Wes. Good tutorial as usual.
Glad it was helpful! Thanks Jimmy.
Such an awesome and concise video.
Thanks a lot I am now very interest to Apply the TDD Concept in my work.
Thanks a lot, very informative and helpful, perfect ..
hi wes!, just keep on doing what you are doing, honestly this channel needs more views, i learned alot from wes and will always learn more. thank you so much wes!
I appreciate that, Albert!
Hi, I have some comments which are to help future tutorials. I managed to follow up to nearly the end and then boom all went pear shaped. Being a novice I have not the skills to work out the problems.
My comments are, perhaps go a little slower, the keyboard clicking and the constant movement of your cursor for no reason is really distracting. It would be nice to have a resource file. Thus for people like me that have followed along but some where missed a key line and it goes wrong we would be able to look at the working code and see where we didn't follow your quick commentary close enough. I mean this by no means to be negative. :)
Thanks for the video.
Out of curiosity. Why do you create your project files using the command line, rather than just using Visual Studio GUI? BTW I love your video. Very educational :)
Prestigious
it much faster
fantastic video
thank you
Thanks for this great video!
I'm curious about what font / colors / theme settings you use for Visual Studio?
Do you have some information on that somewhere? (new subscriber here)
All the best!
Hi Daniel! I have a repo on my GitHub called dotfiles that contains settings for all of my tooling. All the best to you, thanks for subscribing!
Hi Wes! I was wondering how I can test CRUD operations following your procedure. Take Delete for example. How should I register mock service when the API returns NoContent Status Code? something like mockService.Setup(service=> service.DeleteUser(id)).Returns()...I don't know how to complete this piece of code after Returns for a Delete Function which is registered as a task without any return object in UserService!
AYYYY WES IS BACK!
Great teaching and explanation of the material. However, I watched it with some difficulty because the constant keyboard clicking was quite distracting.
Thumbs up. (Despite unnecessary use of Newtonsoft 😜).
:) Old habits! Thanks for watching!
Thanks for video
Hi Wes, thanks for posting this video I am learning some new concepts here.
I am coding along with the video and have ran into a problem at around 1h14m when "GetAllUsers_WhenCalled_InvokesHttpGetRequest()" and "GetAllUsersWhenCalled_ReturnsListOfUsers()" both return the same failed test message.
The message reads: "System.ArgumentException : No protected method HttpMessageHandler.SendAsync found whose signature is compatible with the provided arguments (HttpResponseMessage, CancellationToken)."
As far as I am aware I have copied the coding perfectly, but it is possible I have made a mistake somewhere.
Do you know what is causing these tests to fail?
Thanks in advance,
Jon
Are you using some Vim emulator for visual studio? If so, which one?
Yes, in VS I use VsVim
@@WesDoyle Thanks
I'm only recently working on wrapping my head around unit testing and TDD more specifically. I'm curious, in GetAllUsers_WhenCalled_ReturnsListOfUsers, would it be good to give the handlerMock a COPY of the expectedResponse Users list and then assert that result and expectedResponse contain the same items? By only asserting the count, you don't know for sure that the list isn't being manipulated in some other way after being returned from the HttpClient. Or is that overkill?
Please change the settings on your editor style preferences so we don't have to watch you move the brackets every single time you add a line of code.
Hi @Wes, what browser and extension did you use to inspect the web API response at 1:38:17?
Hi Tony! I'm using Firefox Developer Edition here. Thanks for watching!
Hi Wes, would you prefer the typical Controller.cs or the new minimal api setup?
Hi Kevin, great question. I'd say it depends on a few factors! One consideration would be overall application architecture. The minimal API setup seems ideal for thinking small services / microservices pattern.
@@WesDoyle Looking forward to have that in your next content. Good to see you back sir!
Wow nice video man =)
Does the creating interface IUserService first for that InvokesUserService breaks the tdd pattern? Don't see point in creating mock of something that does not exists, you get build errors and you lose intelisense
Amazing tutorial. So much better than the stupid tutorials that show you some kind of TDD in a command line project with no follow up on how it would be applied to the real world development. Also your way of mocking the HttpClient is something I tried to find a couple of times but failed.
Hi Wes, what's your theme? It's great !!
Hi, this has always been a question I have on my mind. Is there any particular reason that you choose to use command line to create new solution and projects vs using Visual Studio or something has a GUI?
just for convenience!
why would you go to vs and click through all that shit, if you can just do 3 commands
Great explanation, Thank you ! Just one question any particular reason why you did not choose MS TEST project in VS instead of XUnit ? Is it a hard rule that we should use XUnit project for TDD or can we do the same with MS Test ?
Hi Anusha, MS Test can be used, it’s just a matter of framework preference. Each framework is a bit different! 😄
Hi @Wes, wondering if there would be a TDD video using factories, seeding data? Do you know or anyone here an excellent resource where I can find TDD with factories, mocking, seeding using .NET and that uses .NET CORE 6 or above?
Hello, I've question how do you solve this error on moq "Handler did not return a response message.",
I try using same URL Address but still got that error
getting the same error,
fixed it,
double check the handlerMock 1:35:24 , he changed back to any httpRequestMessage
In PowerShell you can do "dotnet sln add (ls -r **/*.csproj)" instead of "dotnet sln add **/*.csproj"
Great
Why can't find NUnit tutorial
Been a while
Yes indeed, great to hear from you!
This is not pure TDD. I think you make things more difficult for people who actually want to look at net core TDD, as a 3rd or 4th language, but actually know TDD ...
Very good content. Thanks a lot for this guide.
Just a comment as a viewer on something a bit annoying, too many code highlighting and navigation keyboard tricks, as your keystrokes are very loud. It's sometimes hard to focus on what you're saying seeing you going back and forward and highlighting every piece of code. 😉
Nevertheless, appreciate your effort doing such good video.
It's an awesome content for people getting into testing, but those unnecessary amounts of key presses got me a bit too hard :D Like WHY :D 17:14 - 17:17. Way too loud for me to concentrate on the actual thing that's going on.
this feels like integration tests instead if unit tests
Hi Kresno, since I'm mocking out dependencies to test the method calls in isolation, I refer to this as unit testing. I tend to call integration tests those tests which encompass a greater system (e.g. integrating a database, network, or hardware). Thanks for watching!
@@WesDoyle i shouldnt have said that sorry. Im a noob. Plz disregard my comment XD just keep the videos comin bro
@@kresnofatihimani5073 no problem at all! i appreciate the question! all the best
too much drag
13:00 - in TDD, you would remove that controller completely, and let tests drive creation of it.
13:20 - premature creation of Helpers and Fixtures
16:23 - explanation of why it's okay to leave the users controller "we know that's what it's going to look like". that's not tdd. that's coming up with code without tests.
24:10 - the "all good" string is not necessary for the tests to pass.
32:10 - you have added the service, the mock and the inject without any tests for that at all. not tdd. you should first write an assertion without ever writing the mock, see the test fail, then implement the service without mocks, and then write another test for the overriden behaviour. in TDD you should not write any code without tests (but you did), and you should not write any more test code that is necessary to make the test fail (which you again did do).
Not watching anymore since that's clearly not TDD. it's probably a good start to testing, a good introduction to TDD, but that's not TDD.
No source code unless paid. No validation of code unless validated..
Mother of god. Pls, not to use unit tests in this way. It's very very very weak code
In your Get_OnSuccess_InvokeUserServiceExactlyOnce(), you define a sut and result but never do anything with them. Whats the point of this? 42:59
anyone else triggered by Wes moving { up with method names? :D
Ctrl + K + D
😂😂😂
Thanks for video
Thanks for watching!
Thanks for the tutorial, but why on earth should we spend one hour and a half to write a simple method that returns a list in a real environment? really I can't get my head around it.
in time it takes far less time, of course. and sometimes the answer is likely that you shouldn’t. there always tradeoffs, and everything depends on context.
Why the heck do you use Insert on your keyboard so much? Drives me crazy.
Fantastic video though. Appreciate it a lot. Thanks!
I’m using vim
53:27 to remove all the unnecessary usings you can just press ctrl + k + e. Also, instead of replacing positions of brackets, you can set in IDE how ctrl + k +d should place them
ctrl + r + g
thanks! i’m using a combination of vim and resharper keybindings
Please do not place { on the same line as the method, thats nots the dotnet way 🤣…
@@stevehiggin it seems weird to have that in C#.🤣🤣
Love it! Very cool! Can you make a video on how to become a .NET developer. In my area there are tons of jobs for .net and I would love to make the switch. Keep it up!
Great suggestion!
I'd love to see this done with NSubstitute
Hello, thank you for creating very educational content. I was wondering what is the console/termain you used in the beginning? The one with the tabbing options on top
That is windows terminal.
The video is good.
do you program with Java or javascrip? Why fight with visual studio adjusting the curly brackets 😅?
Thank you very much, your content help me because i need learn TDD and you taught very well now i can implement this patterns
hi - in this example tests of the external api takes a place - do you /have a video where you testing dbcontext? My application controllers are handling crud operations on existing db and its tables. I was wondering if you can show how to mock this type of scenario?
how you are able to type this fast ? . I noticed you are using some sort of tool that looks like vim. can you tell the name of the tool.
by the way the video is great, easy explanation.
I don't know. Most boring video I have ever seen. How to stretch one or a couple of tests into dozens, and waste a lot of time getting same result of code as on classic. Maybe it wasn't the best example.
Hey, I came across your videos, they are awesome but you really need to write longer and better titles for visibility
hey, appreciate the video. what fonts are you using?
Hi Wes!, glad to see you back
We hope you create more videos this year..
Its always great to learn from you😊
Hi Vinay Palaksha, thanks for the message! Lots of content planned for this year. All the best
Thank you very much for the great content!
Muy bueno tu video saludos y suscrito
Mehn, how I missed you.
Great example bro!
This is so useful! thank you!
PURE GOLD!!! Loved it!
1:26:00 why are we setting up a near-duplicate of `SetupBasicGetResourceList` rather than just adding an `endpoint` parameter to the original method?
am sorry for my ignorance, i am 40 min into the video and TDD just seems like a waste of time to me...
Ive been in IT for 20 years but im a new developer. If you plan on getting a job as an SDE, you MUST know how to unit test. Its a MUST. Especially at large companies.
If you are just building stuff for yourself, then its fine if you dont test your code. We CANNOT get away with no unit tests and integration tests at work.
Like the explanation and the way you show this subject. But man does this become a cluttered mess and this is just a few lines of actual controller and service code. The TDD code and all it's setup and mocking takes up so moch lines and time.
What is a reasonable size this will be when you actually have implemented this on a true production app. I get that this pays off when you modify stuff then without breaking things without you knowing but man, won't this slow down development cycles and drive up cost to triple?
Really not trying to dis TDD I really want to use this but I have no reference with production size apps
The only bad thing about this tutorial is: WHY YOU ARE USING GODDAMN JAVA SYNTAX WHILE WRITING C#! Never put curly parentheses next to a component name! 😊
This video is great! Thank you for making it for us. I'll definitely check out your other stuff.
Hi there, you mentioned that we can use some factory implementation for repeating (duplicate) code. Do you have example for that?
Thank you for the tutorial but do you have an "INSERT" OCD? Why do you need to press "insert" every other keyboard press?
I was waiting for this! Good to see you back!
Thanks! Great to hear from you. All the best
Great to see you back! Great content as usual.
Thanks, Javier. Great to be back!
Great video, for beginners, shows how easy unit tests can be to how complex unit test could be
Thanks for the video.
Thanks for watching!
Thanks for sharing, Wes!
Thanks for watching, Muyiwa Ishola!
OK, got a really weird bug here / user error - I can't get the project to build / rebuild within Visual Studio. I make an edit e.g. change `return Ok("all good");` to `return Ok(users);` . Save the file. Hit "Run" in Test Explorer and the test is still failed. Run `dotnet test` in the terminal and it actually rebuilds the project and shows the test passing.
How do I convince VS to actually rebuild the project?
Found it. But am more baffled as a result. I had the Solution Explorer in Folder View - which somehow stops the tests from rebuilding the projects...?
Thanks for sharing. This video was very useful for me.
Great video!
Thanks for watching!
Thanks! 👌
👍