Man you have the most useful tutorials on KZbin and your explanation is one of the best.I learned a tons from your video.Thank you very,very and very much.
@michaelm52785 жыл бұрын
A more detailed video about both integration tests and unit tests would be highly appreciated! Really nice tutorial series so far :)
@dloperab3 жыл бұрын
Thanks for this fantastic series!!! I'm doing the series with .NET 5. If the integration test failed because a 404 error could be because the test is using the real database and not the database configured in memory. You have to change this in the IntegrationTest constructor: var appFactory = new WebApplicationFactory() .WithWebHostBuilder(builder => { builder.ConfigureServices(services => { services.RemoveAll(typeof(DbContextOptions)); services.AddDbContext(options => { options.UseInMemoryDatabase("TestDb"); }); }); }); I'm using the following Nugets for .NET 5: - FluentAssertions - Microsoft.AspNet.WebApi.Client - Microsoft.AspNetCore.Mvc.Testing - Microsoft.EntityFrameworkCore.InMemory
@camcommute2 жыл бұрын
How would u go about this if u are writing tests for a controller that calls a 3rd party?
@PaameRafa2 жыл бұрын
2022 and I still learning from this series! Amazing!
@alokanat5 жыл бұрын
Great videos. Please make a full session just on writing various tests. Would be very useful. Thank you for putting this all together.
@neil33045 жыл бұрын
Thank you for putting the time and effort for creating such amazing content. Feedback: 1.Most advanced level programmers are going to love the speed at which you teach. It might be a good idea to go a little slow to attract more intermediate and novice level programmers. 2. Screen resolution and the focus on the screen can be better. There is no other way other than full sizing your content to view them. Keep up the good work Nick!
@nickchapsas5 жыл бұрын
Thank you so much for the feedback. I am trying to increase the font size more but then it’s hard for me to work in the project so I have to find a balance.
@in-the-sky-2 жыл бұрын
fortunately, theres features to rewind pause and slow the video
@quentincouissinier85333 жыл бұрын
Hey Nick ! You are doing a real great work here. I'm having so much fun learning those new concepts. Thanks a lot, you are making a difference!
@TheJessejunior3 жыл бұрын
hey, I like so much your tutorials, they´re the most clean, direct and yet easy ones in the youtube
@bernardoreva2 жыл бұрын
This is beautiful. Thanks for taking the time and effort to make such an amazing content Nick. Really appreciated.
@babakabbasi54662 жыл бұрын
The whole video was clear and precise. Thanks for sharing this.
@ericwalter62854 жыл бұрын
Fantastic! This was so informative and exactly what I was looking for to get caught up on Core 3 new integration testing features. I'm now subscribed and will check out more of Nick's videos.
@Iliyas5054 жыл бұрын
I think I just found my favorite .Net KZbinr :)
@kuldeepadhikari38494 жыл бұрын
I would love to have an indepth integration test video, especially with real database with docker container spin up !! THanks a lot for this video !
@taraspelenio82594 жыл бұрын
Just checked your video, it was interesting. Will make base class for my integration tests. Other ideas I already used. Thanks.
@kwilderful3 жыл бұрын
Excellent! In Integration testing, another video you can make is how to emulate model binding validation for Web Api's since the testing frameworks don't have that capability.
@Wildxmo4 жыл бұрын
So thankful for this video. This was exactly what I was looking for!
@FlippieCoetser5 жыл бұрын
Super Helpful! The explanation is clear and to the point!
@juliusreischauer3454 жыл бұрын
Amazing! Exactly what I need right now. Well presented too.
@facundo914 жыл бұрын
I usually use Refit to create an SDK for my API. That way I can share it, or I can use it in my other services that consume the API. But the cool think about it, is that I also test against my SDK Project (no my API project) so I force myself to update my SDK to do integration tests. I also use an Odata client to do integration test against my Odata endpoints. Sharing just in case it helps someone.
@bayobizzle4 жыл бұрын
Can you share an open source example?
@alkishadjinicolaou58312 жыл бұрын
Εξαιρετική δουλειά φίλε
@thisisboxingproductions68944 жыл бұрын
Hey Nick! I know this vid is pretty old but maybe you'll se the comment :). I was wondering how would you go about faking httpContext? Lets say the controller need to access HttpContext.User and get some info from it. Would it be possible to add httpcontext as a service or configure it to be part of a controller?
@christophneuland2140 Жыл бұрын
Love this video. One question though: Wouldn't it make more sense to create the value which we expect by calling the Get endpoint directly on the database instead of using the CreatePostAsync endpoint to create our test data? If we'd break CreatePostAsync somehow, test cases for Get would fail aswell wich could cause confusion.
@jamsshhayd5 жыл бұрын
I would like to see how you integrate Single Sign On in a .NET Core application. Anyways, Perfect series of videos! ❤
@martintaylor89244 жыл бұрын
Great tutorial, and filled some gaps in my knowledge perfectly. Thank you so much!
@nove1398 Жыл бұрын
In depth integration!
@laurakolcavova84933 жыл бұрын
My HttpClient was still connected with local DB. I used "services.RemoveAll(typeof(DbContextOptions));" instead of "services.RemoveAll(typeof(DataContext));" and this fixed the problem.
@unbekannt61113 жыл бұрын
Bro ty for this comment. I always received a 500 error code and know I fixed that thanks ur comment.
@haydarsamawe91503 жыл бұрын
thanks you really help me
@TheFeljoy2 жыл бұрын
Cheers, had the same problem and this worked :)
@HoleyMoleyAlex4 жыл бұрын
Sorry another one. As each test is meant to be independent of each other 18:56, can you or anyone think why when I add a 3rd test, the authorisation method fails, because the user we are registering is now already in the database. I thought each test was not meant to affect each other. Is this because the method is in the base class? But why then does this only happen when I create 3 tests, it's fine with 2, I would have expected it to fail on the second authorisation call as the user was created. The hack would be to delete the user once each test is done, but I should not have to do that surely? It's behaving weird with a capital W. Each test works fine if I run them individually so it's definitely being left over from the previous tests.
@expertreviews11123 жыл бұрын
Super useful video!!! Learnt so much
@ViragDesai3 жыл бұрын
Hi Nick. This is great! Thank you. Can you also create videos about clean architecture also? You're amazing!
@gichamba3 жыл бұрын
Thanks! Great video. The follow up unit test video, was it ever posted? Please post link. I can't find it under your videos.
@reezah71354 жыл бұрын
Maybe a new tutorial about Integration testing in ASP.NET Core 3.1? Because it doesn't work this way anymore.
@johnnguyen16554 жыл бұрын
Yes, the Microsoft.AspNetCore.App was using in the video has only .NetCore 2.2 as dependency. I am trying to in stall it on netcore3.1 and getting "Version conflict..." error. Please let me know if you have solution for that.
@andrewsadavoy3884 жыл бұрын
I didn't install the Microsoft.AspNetCore.App package. Instead I only installed: System.Net.Http.Json, Fluent.Assertions, and EF.InMemory. This worked for me. There are other issues in the video but I was able to struggle through without too much trouble.
@rahulsbhatt Жыл бұрын
What would you recommend if I have multiple microservices responsible for one feature which requires to be integrated testing. Will this appoarch hold true/efficient in that case or do you have any other suggestions? Besides great video 👍🙏
@HoleyMoleyAlex4 жыл бұрын
Great tutorial, but I have one question. When we move to an in memory database rather than the SQL database, is it meant to copy the data from my SQL database? I thought the whole point was to start with a blank testing in-memory database (except any data created in OnModelCreating), or have I got the wrong end of the stick, or done something wrong? The problem with copying the data of course is that the development data changes, and therefore could invalidate the tests further down the line. Note: I am using AppDbContext not DbContext. My test fails because it keeps finding data that was in my development database,
@HoleyMoleyAlex4 жыл бұрын
Oh and here's the relevant code: protected BaseIntergrationTests() { var appFactory = new WebApplicationFactory() .WithWebHostBuilder(builder => { builder.ConfigureServices(services => { // Remove the current DB context, so we can then make a new one for an in-memory database. services.RemoveAll(typeof(AppDBContext)); services.AddDbContext(options => { options.UseInMemoryDatabase("TestDB2"); }); }); }); _TestClient = appFactory.CreateClient(); }
@HoleyMoleyAlex4 жыл бұрын
Okay, it turns it was still using the SQL database, not just copying the data. I did a bit of research and it's yet another case of used to work in EF 2, but don't work in 3 thing. Here's the code that works: protected BaseIntergrationTests() { var appFactory = new WebApplicationFactory() .WithWebHostBuilder(builder => { builder.ConfigureServices(services => { // Remove the current DB context, so we can then make a new one for an in-memory database. // This does not work with e.f. 3.*. // services.RemoveAll(typeof(AppDbContext)); var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions)); if (descriptor != null) { services.Remove(descriptor); } services.AddDbContext(options => { options.UseInMemoryDatabase("TestDB2"); }); }); }); _TestClient = appFactory.CreateClient(); }
@HoleyMoleyAlex4 жыл бұрын
Okay Nick has fixed it on his next video where he upgrades from .net core to 3.0, for anyone else who comes across this. kzbin.info/www/bejne/nYrcZouAh6-ehdE
@sachinjangir1662 жыл бұрын
Really nice and informative video, thanks :)
@omarkallel77854 жыл бұрын
Thank you. Very helpful. If you can do other videos on testing and integration testing with docker. Thank you again!
@kuriangrg4 жыл бұрын
In .net core 3.1 "Microsoft.EntityFrameworkCore.InMemory" package can be used to resolve other dependencies caused by "Microsoft.AspNetCore.App". (Microsoft.AspNetCore.App is not supported by .net core 3.1)
@christoph60553 жыл бұрын
Thanks! I was searching for the solution/alternative to that package ^^
@majed500611 ай бұрын
Very helpful, Thanks so much!!
@sulton-max Жыл бұрын
Great work. Thank you
@noorhajhussin7125 жыл бұрын
Thank u Nick,very helpful tutorial :) The video title is Integration test and the code is about unit Test!!
@nickchapsas5 жыл бұрын
It’s actually integration testing through a unit testing framework. It is just using an in memory database for demo purposes. You can simply change that with an actual dB and I would still work as an integration test.
@leandrolagoa5 жыл бұрын
Perfect explanation! You helped me a lot! Thank you so much!
@AshaD23452 жыл бұрын
Older video I know, but how does this work in .NET 6 where you don't necessarily have a startup class anymore?
@mryildiz7022 жыл бұрын
Add the partial class to the end of Program.cs like this: ... app.Run(); public partial class Program { } now you can it like this: WebApplicationFactory
@kehindeadewale27314 жыл бұрын
really good. thank you. is there any difference between calling this approach integration test or a unit test of my controller methods
@nickchapsas4 жыл бұрын
There sure is. A unit test is isolating a unit and it's testing just the unit. Not it's dependencies. This approach will actually test the whole flow including middleware because the application is technically running.
@whoami03333 жыл бұрын
@@nickchapsas Thanks for your video and response! Actually, I have the similar question of Kehinde above. The API endpoints test for the Controller methods is a kind of integration test, instead of an unit test, although we implement that API endpoints test basing on the xUnit framework as well. When implementing such integration test(API test), we were coached to AVOID mocking or faking its dependencies (i.e. in-memory DB) because the goal of integration test is just testing all components' integration-working, which is not like the unit test for testing a function() self only. However, the Microsoft.AspNetCore.Mvc.Testing you introduced in this video, which is absolutely an integration test skill too, recommends in-memory SUT that is using an in-memory database, which is different from the above description we were coached. /so, could you please introduce its reason? In other words, I assume Kehinde's question is "is there any difference between using the Microsoft.AspNetCore.Mvc.Testing you introduced and sending System.Net.Http.HttpClient to the action-methods of controllers, which are both integration tests"? If any mistake above, please correct as well. Thanks!
@tyeasir2 жыл бұрын
It would be nice to be able to access the project solution that you have in this video. The github link is partial code which is tough to work with.
@RyanTuller5 жыл бұрын
Great video man! Keep'em coming
@joenishanth73104 жыл бұрын
Short and useful video :)
@daveventura83434 жыл бұрын
amazing tutorial again. Best man :)
@turbosega3 жыл бұрын
Good and nice explanation. Thanks.
@Pentatonic_Hardcore2 жыл бұрын
Thanks a lot, please do a integration test for .net 6 and grpc, thanks !
@anassalloul65154 жыл бұрын
Great Videos! You helped me a lot, I have a question about how can we initialize automapper with Xunit for Integration Test. Thank You Nick
@Zhovten5 жыл бұрын
wondering what would be the problem here Tweetbook.IntegrationTests.PostsControllerTests.GetAll_WithoutAnyPosts_ReturnsEmptyResponse Source: PostsControllerTests.cs line 18 Duration: 11 sec Message: System.Net.Http.UnsupportedMediaTypeException : No MediaTypeFormatter is available to read an object of type 'AuthSuccessResponse' from content with media type 'text/plain'. Stack Trace: HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken) HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger) HttpContentExtensions.ReadAsAsync[T](HttpContent content, IEnumerable`1 formatters) HttpContentExtensions.ReadAsAsync[T](HttpContent content) IntegrationTest.GetJwtAsync() line 56 IntegrationTest.AuthenticateAsync() line 39 PostsControllerTests.GetAll_WithoutAnyPosts_ReturnsEmptyResponse() line 21 --- End of stack trace from previous location where exception was thrown ---
@nickchapsas5 жыл бұрын
Which .NET Core version are you using?
@Zhovten5 жыл бұрын
@@nickchapsas Tweetbook is 3.1 Tweetbook.IntegrationTest is 3.1 too
@kaiobk884 жыл бұрын
The problem is ReadAsAsync in the GetJwtAsync method, one way is to change it to ReadAsStringAsync and deserialize json like this: var registrationResponseString = await response.Content.ReadAsStringAsync(); var registrationResponse = JsonSerializer.Deserialize(registrationResponseString, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); return registrationResponse.Token;
@tmati78602 жыл бұрын
Does in-memory database compatible with relational databases? for example can we use .Include() ?
@FabioGomesCG4 жыл бұрын
Nice videos man... Ty so much !
@MolaMolaSunnyfish3 жыл бұрын
Guess my only complaint is that the text was a bit hard to read, especially where (I think) it says "requestUri" at about 4:50. I can't tell what puncuation you are using there. I know this is a nearly 2 year old video at this point, but hopefully this still is useful feedback.
@manuelguerrero99173 жыл бұрын
Amazing tutorial.
@sravlca21473 жыл бұрын
very useful video, thanks!
@vinr4 жыл бұрын
If anyone has a problem of not getting inmemory database instead still connecting to the production database, follow this thread and first answer worked for me (i.e. getting the descriptor and removing the descriptor) - I'm using core 3.1 - stackoverflow.com/questions/58375527/override-ef-core-dbcontext-in-asp-net-core-webapplicationfactory
@MohamedAliC2 жыл бұрын
Thanks! that part confused me
@AdolfoGCH4 жыл бұрын
Hi Nick, do you know if is possible to use the Inmemory Option with PostgreSQL database? By the way, as many others I have learned a lot with your videos! thanks in tons!
@maciej_s5 жыл бұрын
I'm enjoying these series, very helpful and since I'm completely new to .NET Core I'm learning a ton! I have, however encountered a problem that I can't seem to be able to overcome. 16:02 my test is failing because the HttpStatusCode is 404. When I set a breakpoint in the PostsControllerTests.cs on line 24, I can see that the RequestUri is set to "localhost/api/v1/posts". I am pretty sure I followed everything you did 1 to 1 yet this is the first time something does not work for me. Would appreciate if you could perhaps suggest what I may be doing wrong.
@michaelskydt69525 жыл бұрын
I also seem to get a 404 when trying to call the WebApi from the IntegrationTest project. Everything works as expected when running the code localhost or in Docker. What i can see is, that there might be some kind of bug in .net core 3.0 when trying to load assemblies, especially trying to get the Controllers in the Tweetbook project. stackoverflow.com/questions/43669633/why-is-testserver-not-able-to-find-controllers-when-controller-is-in-separate-as/58946016#58946016 Unfortunately neither of these solutions work for me :( If any of you guys have a solution for this, please share. And Nick Chapsas this is a very cool tutorial series! Keep up the good work.
@paulmouatib99993 жыл бұрын
Is this work with MSQL Server or PostGres? How does it create a in memory version of a database??
@vamsi86694 жыл бұрын
Hi Nick I am doing all this in an uint test with out using the client factory. But I am still using the in memory database. Do my test still be unit test or will they qualify as integration tests? Thanks for the super helpful tutorials.
@tmati78602 жыл бұрын
Hey Nick, Thank for your great video. Please make a video concerning authorized user create a post that has userId in it and create a integration test for that. Tnaks is advance.
@andrewsadavoy3884 жыл бұрын
First, your videos are excellent. Please keep it up! Second, there's an issue with AspNetCore 3.1: the integration tests seem to use the non-in-memory database using the instructions in the video. This fix worked for me: At 11:58 (kzbin.info/www/bejne/baPSoqebjLGqatU) change the line from: services.RemoveAll(); to: services.RemoveAll(); EDIT: I'm not sure this fix actually works. It fixed the issue with the Identity but I'm still having problems with creating posts.
@gordonfreimann2 жыл бұрын
Hi Nick, is this still valid approach as of today? I need something like this in my project.
@nickchapsas2 жыл бұрын
It sure is
@gordonfreimann2 жыл бұрын
@@nickchapsas thanks :)
@kenank70532 жыл бұрын
You need to consider that the in memory database returns object by reference. This said changes to your domain take place directly even before you call SaveAsync etc.
@gordonfreimann2 жыл бұрын
@@kenank7053 yes i dealt with that and bunch of other problems as well. In the video he says each test resets the in memory db but it didn't. I had to configure more to clean it for each test. Furthermore, creating a second class for other controller caused another issue. They run in parallel which was a problem with the db context. But luckily there's Collection attribute of xunit that solved the issue.
@kenank70532 жыл бұрын
@@gordonfreimann Did you find a feasible way? With this behaviour it is nearly useless
@MrSigmaSharp5 жыл бұрын
A good video you can improve it if you increase the dpi on your machine so that the texts are visible in smaller screens and lower resolution caused by adaptive resolution of you tube
@frankhaugen5 жыл бұрын
This is OK when you are issuing a token from the same microservice. However, what if I have a separate microservice to handle identies, and I need to "fool" it into letting me access the endpoint??
@nickchapsas5 жыл бұрын
All the other microservice has to do is either verify the token signature to prove that it is authentic using a secret or a certificate depending on the token signature encryption type or call the identity microservice to do the signature auth check on its behalf
@edwinparejas31764 жыл бұрын
Hi, How can you customize Visual Studio that way? Can you learn me please ? for example that NUGET window at bottom ... Thanks a lot
@nickchapsas4 жыл бұрын
Hey Edwin, this is not visual studio. This is a different IDE called Rider. It’s made by JetBrains the same guys that made resharper
@edwinparejas31764 жыл бұрын
Nick Chapsas Interesting... Thanks Nick!!
@romanhrytskiv55984 жыл бұрын
How'd you configure that triple-'a' shortcut?
@nickchapsas4 жыл бұрын
I used Rider's templating feature. I think there is a similar one in Visual Studio as well
@halivudestevez24 жыл бұрын
now is it Unit or Integration testing?
@halivudestevez24 жыл бұрын
cant get the difference
@tisurmaster4 жыл бұрын
What about using swagger api testing as a unit test and integration test?
@nickchapsas4 жыл бұрын
Swagger API Testing cannot be considered unit testing in any way. It could technically be used for integration testing but where I think it really shines is end to end testing.
@tisurmaster4 жыл бұрын
@@nickchapsas thanks! Will definitely consider that.
@swaroopshivanna30253 жыл бұрын
I am trying to integration test my .NET 5 project using similar setup to what has been described in the video. The unit test run fine when I run them individually but when I run them all at once first to be executed passes and rest fail, when I debugged it was because the user already existed. I think the context is being shared among the tests but I do not know how to not share it. Any help please?
@pagorbunov2 жыл бұрын
The same issue...
@yltope2 жыл бұрын
Ran into the same issue using Core 6.0. Maybe the behavior of the in-memory database has been changed between major versions as its documentation states now that: "The in-memory database is shared anywhere the same name is used" This sharing causes the second call for registering a user to fail as the user already exists. I made a dirty hack that seems to work: options.UseInMemoryDatabase("TestDb" + this.GetHashCode()); I.e. append the current test instance's hashcode into the name as a new instance is created per test run (and no, Guids do not work for some reason). There most likely is a better way of accomplishing a reset to the in-memory database, but can't be bothered to spend more time investigating.
@abhijithsugunan67684 жыл бұрын
Nick an updated video for .net core 3.1 might he helpful
@serhiihorun62984 жыл бұрын
Thank you!!
@jessecalato46776 ай бұрын
Is all of this still valid, or are there better ways to do this now?
@michelchaghoury96292 жыл бұрын
Hello nick i need your help i want to have a sql server docker instance for testing i have stored orocedures that i want to test can you please help me or nake a vid about that ropic please
@zohashobbar1182 жыл бұрын
its grate thank you
@sushantutub3 жыл бұрын
Hi nick could you please share git link
@MartinBonafede3 жыл бұрын
I don't get it you say in the title ASP.NET Core 5, but the app is in net core 2.2
@nickchapsas3 жыл бұрын
It was originally made in 2.2 times, but the structure and code is still the same in 5. The only things that need updating are in the upvoted comments
@mimimi_everywhere5 жыл бұрын
unfortunately my service is still connected with my local DB and writes the data in there. My problem is also described here: stackoverflow.com/questions/58375527/override-ef-core-dbcontext-in-asp-net-core-webapplicationfactory do you have any solution for that problem? thank you
@vinr4 жыл бұрын
I have the same issue, it doesn't connect to the inmemory db, did you find any solution?
@vinr4 жыл бұрын
Your thread has a solution and it works
@pharaujo24095 жыл бұрын
Excellent content. Could you please share the code?
@nickchapsas5 жыл бұрын
Hello and thanks for your kind words. Unfortunately the code is always out of sync with the videos since I prerecord most of them, so you will never find the code to be accurate to that specific video. I could potentially reupload the code and use snapshots for each video but those videos are meant to be mostly follow along and not a place to grab a piece of code and roll with it.
@nickchapsas5 жыл бұрын
I added the IntegrationTest project in the description if you still need it
@nickchapsas5 жыл бұрын
Hello Pontus, thanks for the feedback. All the videos after part 17 had a snapshot of the code in the description. Sorry I didn't do that earlier.
@kpkeerthi1174 жыл бұрын
can u share this project
@nickchapsas4 жыл бұрын
You can find all the code in the description down below.
@michaelkopljan5784 жыл бұрын
#JetBrainsRider, very good video
@СвятославСамойленко-ц1ы3 жыл бұрын
I'm not sure that it's good approach in integration test to test controllers. I'm prefer to test services (business layer) which are injected to controllers and should be connected to DB. In this case you can interact only with interfaces instead of having route files (do you really use something like this in production?).
@nickchapsas3 жыл бұрын
You are not testing controllers. You are testing endpoints via a special httpclient. You don’t need to mock the databases and in fact you shouldn’t, if you are doing proper integration testing.
@СвятославСамойленко-ц1ы3 жыл бұрын
@Nick Chapsas I mean that usage of controller endpoints don't looks like good idea and prefer to have start testing point of service or another entity which methods are based on interface not on route file. DB state (mock or real) is not important here.
@carlosgarcialalicata3 жыл бұрын
@@СвятославСамойленко-ц1ы are you talking about unit testing or integration testing? Two different things
VScode users: Make sure to restart OmniSharp or package references won't be found.
@Rajeshsingh-ws5th3 жыл бұрын
good, but your display is very small.
@PavanGarigipati3 жыл бұрын
Increase the font otherwise how good you are in teaching that would not reflects.
@gabrielvargas75863 жыл бұрын
up
@DBankx14 жыл бұрын
good video but bro you have to slow down. youre explaining this to people who do not understand the concept. Please take the time to explain to people. it seems you are just reading from a script quickly and typing. No explanation is being done. This video should be named "Asp.net core web api tutorial for intermediate". And also please increase the font!!!!
@contactdrc92402 жыл бұрын
This was supposed to be a good tutorial, but the image is blur, I can not see anyrhing... Too bad!