I am creating web api for a songsDB and I am trying to test API GET methods which return a Json string of songs in a list. The get method in question uses a linq queries and returns the songs as expected but am unable to write a unit test for this method and many like it with a concern for code coverage also. The app is hosted on azure and the data is being retrieved from an sql db instance in azure. The method displays the 5 cheapest albums in the db in ascending order. Any help is greatly appreciated.
//API GET Method
[HttpGet("leastExpensive")]
[ProducesResponseType(404)]
[ProducesResponseType(200)]
public ActionResult<Tunes> GetCheapestAlbums()
{
var price = _context.Songs
.OrderBy(p => p.Price)
.Select(g => new
{
g.ChartPosition,
g.Artist,
g.Genre,
g.Price
}).Take(5)
.ToList();
if (price == null)
{
return NotFound();
}
else
{
return Ok(price);
}
}
//Json response
[{
"chartPosition":29,"artist":"ABBA","genre":"Pop","price":4.39
},{
"chartPosition":60,"artist":"Amy Whinehouse","genre":"Pop","price":5.05
},{
"chartPosition":10,"artist":"BB King","genre":"Blues","price":5.5
},{
"chartPosition":15,"artist":"Kenny Rogers","genre":"Country","price":5.92
},{
"chartPosition":17,"artist":"Pearl Jam","genre":"Rock","price":6.29
}]
I am looking to assert the Json string as equal