Integration testing | ASP.NET Core 5 REST API Tutorial 15

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ค. 2024
  • Become a Patreon and get source code access: / nickchapsas
    Check out my courses: dometrain.com
    Hello everybody I'm Nick and today I will show you how you can get started with integration tests in ASP.NET core. We will be using the in-memory TestServer method which is provided by the use of the WebApplicationFactory class. It's a very cool method and I'd like to share it with you.
    Source code: gist.github.com/Elfocrash/101...
    Don't forget to comment, like and subscribe :)
    Social media:
    Follow me on GitHub: bit.ly/ChapsasGitHub
    Follow me on Twitter: bit.ly/ChapsasTwitter
    Connect on LinkedIn: bit.ly/ChapsasLinkedIn
    #tutorial #rest #api #testing

ความคิดเห็น • 154

  • @michaelm5278
    @michaelm5278 4 ปีที่แล้ว +44

    A more detailed video about both integration tests and unit tests would be highly appreciated! Really nice tutorial series so far :)

  •  4 ปีที่แล้ว +56

    Man you have the most useful tutorials on TH-cam and your explanation is one of the best.I learned a tons from your video.Thank you very,very and very much.

  • @quentincouissinier8533
    @quentincouissinier8533 3 ปีที่แล้ว +2

    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!

  • @alokanat
    @alokanat 4 ปีที่แล้ว +7

    Great videos. Please make a full session just on writing various tests. Would be very useful. Thank you for putting this all together.

  • @dloperab
    @dloperab 3 ปีที่แล้ว +13

    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

    • @David-rz4vc
      @David-rz4vc 2 ปีที่แล้ว

      How would u go about this if u are writing tests for a controller that calls a 3rd party?

  • @bernardoreva
    @bernardoreva 2 ปีที่แล้ว

    This is beautiful. Thanks for taking the time and effort to make such an amazing content Nick. Really appreciated.

  • @PaameRafa
    @PaameRafa 2 ปีที่แล้ว +2

    2022 and I still learning from this series! Amazing!

  • @TheJessejunior
    @TheJessejunior 3 ปีที่แล้ว

    hey, I like so much your tutorials, they´re the most clean, direct and yet easy ones in the youtube

  • @ericwalter6285
    @ericwalter6285 4 ปีที่แล้ว +3

    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.

  • @martintaylor8924
    @martintaylor8924 4 ปีที่แล้ว

    Great tutorial, and filled some gaps in my knowledge perfectly. Thank you so much!

  • @FlippieCoetser
    @FlippieCoetser 4 ปีที่แล้ว

    Super Helpful! The explanation is clear and to the point!

  • @juliusreischauer345
    @juliusreischauer345 3 ปีที่แล้ว

    Amazing! Exactly what I need right now. Well presented too.

  • @Wildxmo
    @Wildxmo 3 ปีที่แล้ว

    So thankful for this video. This was exactly what I was looking for!

  • @babakabbasi5466
    @babakabbasi5466 ปีที่แล้ว

    The whole video was clear and precise. Thanks for sharing this.

  • @taraspelenio8259
    @taraspelenio8259 3 ปีที่แล้ว

    Just checked your video, it was interesting. Will make base class for my integration tests. Other ideas I already used. Thanks.

  • @kuldeepadhikari3849
    @kuldeepadhikari3849 4 ปีที่แล้ว

    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 !

  • @leandrolagoa
    @leandrolagoa 4 ปีที่แล้ว

    Perfect explanation! You helped me a lot!
    Thank you so much!

  • @neil3304
    @neil3304 4 ปีที่แล้ว +5

    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!

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +2

      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-
      @in-the-sky- ปีที่แล้ว

      fortunately, theres features to rewind pause and slow the video

  • @laurakolcavova8493
    @laurakolcavova8493 3 ปีที่แล้ว +6

    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.

    • @unbekannt6111
      @unbekannt6111 3 ปีที่แล้ว

      Bro ty for this comment. I always received a 500 error code and know I fixed that thanks ur comment.

    • @haydarsamawe9150
      @haydarsamawe9150 2 ปีที่แล้ว

      thanks you really help me

    • @TheFeljoy
      @TheFeljoy 2 ปีที่แล้ว

      Cheers, had the same problem and this worked :)

  • @RyanTuller
    @RyanTuller 5 ปีที่แล้ว

    Great video man! Keep'em coming

  • @Iliyas505
    @Iliyas505 4 ปีที่แล้ว

    I think I just found my favorite .Net TH-camr :)

  • @expertreviews1112
    @expertreviews1112 2 ปีที่แล้ว

    Super useful video!!! Learnt so much

  • @jamsshhayd
    @jamsshhayd 4 ปีที่แล้ว +1

    I would like to see how you integrate Single Sign On in a .NET Core application. Anyways, Perfect series of videos! ❤

  • @sachinjangir166
    @sachinjangir166 2 ปีที่แล้ว

    Really nice and informative video, thanks :)

  • @kwilderful
    @kwilderful 3 ปีที่แล้ว

    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.

  • @ViragDesai
    @ViragDesai 3 ปีที่แล้ว +1

    Hi Nick. This is great! Thank you. Can you also create videos about clean architecture also? You're amazing!

  • @majed5006
    @majed5006 6 หลายเดือนก่อน

    Very helpful, Thanks so much!!

  • @omarkallel7785
    @omarkallel7785 4 ปีที่แล้ว

    Thank you. Very helpful.
    If you can do other videos on testing and integration testing with docker. Thank you again!

  • @sultonbekrakhimov6623
    @sultonbekrakhimov6623 ปีที่แล้ว

    Great work. Thank you

  • @turbosega
    @turbosega 3 ปีที่แล้ว

    Good and nice explanation. Thanks.

  • @daveventura8343
    @daveventura8343 3 ปีที่แล้ว

    amazing tutorial again. Best man :)

  • @FabioGomesCG
    @FabioGomesCG 3 ปีที่แล้ว

    Nice videos man... Ty so much !

  • @joenishanth7310
    @joenishanth7310 4 ปีที่แล้ว

    Short and useful video :)

  • @sravlca2147
    @sravlca2147 3 ปีที่แล้ว

    very useful video, thanks!

  • @nove1398
    @nove1398 ปีที่แล้ว

    In depth integration!

  • @manuelguerrero9917
    @manuelguerrero9917 3 ปีที่แล้ว

    Amazing tutorial.

  • @anassalloul6515
    @anassalloul6515 3 ปีที่แล้ว

    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

  • @alkishadjinicolaou5831
    @alkishadjinicolaou5831 2 ปีที่แล้ว

    Εξαιρετική δουλειά φίλε

  • @gichamba
    @gichamba 3 ปีที่แล้ว

    Thanks! Great video. The follow up unit test video, was it ever posted? Please post link. I can't find it under your videos.

  • @facundo91
    @facundo91 4 ปีที่แล้ว +2

    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.

    • @bayobizzle
      @bayobizzle 4 ปีที่แล้ว

      Can you share an open source example?

  • @noorhajhussin712
    @noorhajhussin712 4 ปีที่แล้ว

    Thank u Nick,very helpful tutorial :)
    The video title is Integration test and the code is about unit Test!!

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +2

      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.

  • @AdolfoGCH
    @AdolfoGCH 4 ปีที่แล้ว

    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!

  • @serhiihorun6298
    @serhiihorun6298 4 ปีที่แล้ว

    Thank you!!

  • @MrSigmaSharp
    @MrSigmaSharp 4 ปีที่แล้ว

    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

  • @Abs0lutespy
    @Abs0lutespy 3 ปีที่แล้ว +1

    Hey Nick, really educational video. I'm stuck at 12:45. You are removing your context and are adding a new one on an inmemory db. I'm trying to do the same with a live test db and I can't seem to make it work. It keeps reading the original startup file and breaks.

  • @vamsi8669
    @vamsi8669 4 ปีที่แล้ว

    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.

  • @thisisboxingproductions6894
    @thisisboxingproductions6894 3 ปีที่แล้ว

    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?

  • @Pentatonic_Hardcore
    @Pentatonic_Hardcore 2 ปีที่แล้ว

    Thanks a lot, please do a integration test for .net 6 and grpc, thanks !

  • @zohashobbar118
    @zohashobbar118 ปีที่แล้ว

    its grate thank you

  • @reezah7135
    @reezah7135 4 ปีที่แล้ว +8

    Maybe a new tutorial about Integration testing in ASP.NET Core 3.1? Because it doesn't work this way anymore.

    • @johnnguyen1655
      @johnnguyen1655 4 ปีที่แล้ว +1

      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.

    • @andrewsadavoy388
      @andrewsadavoy388 4 ปีที่แล้ว +2

      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.

  • @christophneuland2140
    @christophneuland2140 8 หลายเดือนก่อน

    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.

  • @tyeasir
    @tyeasir ปีที่แล้ว

    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.

  • @HoleyMoleyAlex
    @HoleyMoleyAlex 3 ปีที่แล้ว

    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.

  • @tmati7860
    @tmati7860 2 ปีที่แล้ว

    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.

  • @kehindeadewale2731
    @kehindeadewale2731 3 ปีที่แล้ว +1

    really good. thank you. is there any difference between calling this approach integration test or a unit test of my controller methods

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว +1

      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.

    • @whoami0333
      @whoami0333 3 ปีที่แล้ว

      ​@@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!

  • @rahulsbhatt
    @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 👍🙏

  • @vinr
    @vinr 4 ปีที่แล้ว +1

    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

    • @MohamedAliC
      @MohamedAliC 2 ปีที่แล้ว

      Thanks! that part confused me

  • @HoleyMoleyAlex
    @HoleyMoleyAlex 3 ปีที่แล้ว +1

    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,

    • @HoleyMoleyAlex
      @HoleyMoleyAlex 3 ปีที่แล้ว

      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();
      }

    • @HoleyMoleyAlex
      @HoleyMoleyAlex 3 ปีที่แล้ว +3

      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();
      }

    • @HoleyMoleyAlex
      @HoleyMoleyAlex 3 ปีที่แล้ว +1

      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. th-cam.com/video/gYy5XJRJkOo/w-d-xo.html

  • @asdfasg
    @asdfasg ปีที่แล้ว

    how do you write integration tests to lambda functions that are only triggered by sqs or sns events?

  • @kuriangrg
    @kuriangrg 3 ปีที่แล้ว +2

    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)

    • @christoph6055
      @christoph6055 2 ปีที่แล้ว +1

      Thanks! I was searching for the solution/alternative to that package ^^

  • @paulmouatib9999
    @paulmouatib9999 2 ปีที่แล้ว

    Is this work with MSQL Server or PostGres? How does it create a in memory version of a database??

  • @tmati7860
    @tmati7860 2 ปีที่แล้ว

    Does in-memory database compatible with relational databases? for example can we use .Include() ?

  • @abhijithsugunan6768
    @abhijithsugunan6768 4 ปีที่แล้ว +1

    Nick an updated video for .net core 3.1 might he helpful

  • @frankhaugen
    @frankhaugen 4 ปีที่แล้ว

    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??

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      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

  • @AshaD2345
    @AshaD2345 2 ปีที่แล้ว +1

    Older video I know, but how does this work in .NET 6 where you don't necessarily have a startup class anymore?

    • @mryildiz702
      @mryildiz702 2 ปีที่แล้ว

      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

  • @andrewsadavoy388
    @andrewsadavoy388 4 ปีที่แล้ว +1

    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 (th-cam.com/video/7roqteWLw4s/w-d-xo.html) 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.

  • @MolaMolaSunnyfish
    @MolaMolaSunnyfish 3 ปีที่แล้ว

    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.

  • @michaelkopljan578
    @michaelkopljan578 4 ปีที่แล้ว

    #JetBrainsRider, very good video

  • @edwinparejas3176
    @edwinparejas3176 3 ปีที่แล้ว

    Hi, How can you customize Visual Studio that way? Can you learn me please ? for example that NUGET window at bottom ... Thanks a lot

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว +1

      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

    • @edwinparejas3176
      @edwinparejas3176 3 ปีที่แล้ว

      Nick Chapsas Interesting... Thanks Nick!!

  • @romanhrytskiv5598
    @romanhrytskiv5598 4 ปีที่แล้ว

    How'd you configure that triple-'a' shortcut?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      I used Rider's templating feature. I think there is a similar one in Visual Studio as well

  • @michelchaghoury9629
    @michelchaghoury9629 2 ปีที่แล้ว

    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

  • @swaroopshivanna3025
    @swaroopshivanna3025 2 ปีที่แล้ว

    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?

    • @pagorbunov
      @pagorbunov 2 ปีที่แล้ว

      The same issue...

    • @yltope
      @yltope ปีที่แล้ว

      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.

  • @Zhovten
    @Zhovten 4 ปีที่แล้ว +2

    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 ---

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      Which .NET Core version are you using?

    • @Zhovten
      @Zhovten 4 ปีที่แล้ว

      @@nickchapsas Tweetbook is 3.1 Tweetbook.IntegrationTest is 3.1 too

    • @kaiobk88
      @kaiobk88 4 ปีที่แล้ว +2

      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;

  • @tisurmaster
    @tisurmaster 4 ปีที่แล้ว

    What about using swagger api testing as a unit test and integration test?

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +2

      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.

    • @tisurmaster
      @tisurmaster 4 ปีที่แล้ว +1

      @@nickchapsas thanks! Will definitely consider that.

  • @sushantutub
    @sushantutub 2 ปีที่แล้ว

    Hi nick could you please share git link

  • @jessecalato4677
    @jessecalato4677 หลายเดือนก่อน

    Is all of this still valid, or are there better ways to do this now?

  • @maciej_s
    @maciej_s 4 ปีที่แล้ว +1

    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.

    • @michaelskydt6952
      @michaelskydt6952 4 ปีที่แล้ว

      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.

  • @mimimi_everywhere
    @mimimi_everywhere 4 ปีที่แล้ว +2

    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

    • @vinr
      @vinr 4 ปีที่แล้ว +1

      I have the same issue, it doesn't connect to the inmemory db, did you find any solution?

    • @vinr
      @vinr 4 ปีที่แล้ว +2

      Your thread has a solution and it works

  • @MartinBonafede
    @MartinBonafede 3 ปีที่แล้ว

    I don't get it you say in the title ASP.NET Core 5, but the app is in net core 2.2

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      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

  • @halivudestevez2
    @halivudestevez2 3 ปีที่แล้ว +1

    now is it Unit or Integration testing?

  • @pharaujo2409
    @pharaujo2409 5 ปีที่แล้ว +1

    Excellent content. Could you please share the code?

    • @nickchapsas
      @nickchapsas  5 ปีที่แล้ว +2

      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.

    • @nickchapsas
      @nickchapsas  5 ปีที่แล้ว +2

      I added the IntegrationTest project in the description if you still need it

    • @nickchapsas
      @nickchapsas  5 ปีที่แล้ว +1

      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.

  • @gordonfreimann
    @gordonfreimann 2 ปีที่แล้ว +1

    Hi Nick, is this still valid approach as of today? I need something like this in my project.

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +1

      It sure is

    • @gordonfreimann
      @gordonfreimann 2 ปีที่แล้ว

      @@nickchapsas thanks :)

    • @kenank7053
      @kenank7053 2 ปีที่แล้ว

      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.

    • @gordonfreimann
      @gordonfreimann 2 ปีที่แล้ว

      @@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.

    • @kenank7053
      @kenank7053 2 ปีที่แล้ว

      @@gordonfreimann Did you find a feasible way? With this behaviour it is nearly useless

  • @kpkeerthi117
    @kpkeerthi117 4 ปีที่แล้ว

    can u share this project

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      You can find all the code in the description down below.

  • @nitchiecanceran6907
    @nitchiecanceran6907 5 ปีที่แล้ว

    Can you share the codes?

    • @nickchapsas
      @nickchapsas  5 ปีที่แล้ว

      gist.github.com/Elfocrash/101ffc29947832545cdaebcb259c2f44

  • @Rajeshsingh-ws5th
    @Rajeshsingh-ws5th 3 ปีที่แล้ว

    good, but your display is very small.

  • @gabrielvargas7586
    @gabrielvargas7586 3 ปีที่แล้ว

    up

  • @hasanen9
    @hasanen9 5 ปีที่แล้ว

    can you share source code

    • @nickchapsas
      @nickchapsas  5 ปีที่แล้ว

      gist.github.com/Elfocrash/101ffc29947832545cdaebcb259c2f44

  • @teddysmith7939
    @teddysmith7939 3 ปีที่แล้ว

    VScode users: Make sure to restart OmniSharp or package references won't be found.

  • @PavanGarigipati
    @PavanGarigipati 3 ปีที่แล้ว

    Increase the font otherwise how good you are in teaching that would not reflects.

  • @contactdrc9240
    @contactdrc9240 ปีที่แล้ว

    This was supposed to be a good tutorial, but the image is blur, I can not see anyrhing... Too bad!

  • @user-pp3mz6id2p
    @user-pp3mz6id2p 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?).

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว +1

      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.

    • @user-pp3mz6id2p
      @user-pp3mz6id2p 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.

    • @carlosgarcialalicata
      @carlosgarcialalicata 2 ปีที่แล้ว

      @@user-pp3mz6id2p are you talking about unit testing or integration testing? Two different things

  • @DBankx1
    @DBankx1 3 ปีที่แล้ว

    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!!!!