Sujeet Raman

Sujeet Raman

  • 752
  • 927
  • 354.1k

How to write a unittest for a controller methode in .NET core?

May 19 2021 2:59 PM
Hi, here i am trying to understand how i can write unite test for my web api controller methode.As i am new to this i was gone through enough articles but that made me more confused stage.
I have a StudentController in my api.Which will take a bunch of student details as input and will return some other details.Butlater in my controller post methode input type may be automaticaly come,like from any pipeline call or any api..but the model format is diffrent and i want to test that kind using unit test
In Unit test i have to check how i can pass diffrent type of input style. that is like
var student=new student
{
name="Tom"
class="5B"
Id="S99"
} ,
var Home=new home
{
Fathername="GeorgeTom"
Mothername="carla"
houseno="H23"
}
...
i need to pass this kind of input and test in unit test .May be i have to change this to json object and pass.But i want to find the possibiliteis of passing these kind of input model using unit test.
where i have to start?
How I can pass this model?
Thanks a lot!!!

Answers (1)