❔ how to run a test to test an endpoint and to check in the database that the data been stored
I dont know what the correct way is to do this in aspnet, or if this is how it is done in .net
I want to basically post to an endpointz
, say /blog
Check for a 201 response then check it has been stored in the database.
19 Replies
well
you've just described exactly what you want
so, uhhh
what's the problem?
Fucking piece of shitndiscord wont let me edit my post
I entered too early
lol alright
Okay so i dont know the way to test an endpoint properly when iw ant to check the data has been persisted correctly
Ive been looking and i dont know if im supposed to just test the controller and just bypass testing the actual endpoint
Ive seen examples of just injecting a self created db context into the controller which lets me use transactions to stop tests saving to the db
there's no "proper" way for any of this
that's a decent approach
are you looking for unit testing or integration testing?
how portable do you want these tests to be?
If iw anted to test the endpoint like..
client.PostAsync(...)
How do i go about testing the db?
the same way you do any DB communication
So its jhst fine to use thay context
Im over thinking things i think
quite possibly
Ah okay cheers, ill see how far i get
generally
testing involves either unit testing or integration testing
and there's value in both
I think the problem is i dont quite know how to load the db context in xunit
Or do i just use dbcontext from my infrastructure when the app is loading
not familiar with XUnit, so not sure
Ah okay
but, uhh
it's a DbContext
make it however you like
I dont know how becauee it has its own set of dependencies ,i think ineed ot leanr how the application builder works
(Im a dev from another language)
Im on day 3 of .netting, quite enjoying it so far, cheers for your guidance
I realised i can use the builder anywhere i think
you can construct DbContext objects directly, as long as you can pass in options
you can also just create a skeleton IoC container if you wanna reuse DI setup code
if you're only on day 3 of using .NET you MIIIIIIIGHT be jumping the gun into all of these high-end frameworks
Maybe, but i got another week, once i can write the first test and understand whats ill be flying
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.