I have a web api and I am showing the endpoint as follows:
api / holiday? name = {name}
This is the method to get the controller for web api:
public IQueryable<Holiday> GetHolidayByName(string name) { return db.Holiday.Where(n => string.Equals(n.Name, name)); }
How can I write a unit / integration test for this that checks the names equal? I can verify that the result is not empty, but a bit confusing, how can I verify that the names are equal:
[TestMethod] public void GetHoliday_GetHolidayByName() { // Arrange HolidaysController controller = new HolidaysController(); // Act IQueryable<Holiday> actionResult = controller.GetHolidayByName("Spain"); //Assert Assert.IsNotNull(actionResult); //any attempt to check names are equal results in a fail //For instance this fails var result = controller.GetHolidayByName("Spain") as OkNegotiatedContentResult<Holiday>; Assert.AreEqual("Spain", result.Content.Name); }
c # unit-testing linq asp.net-web-api testing
Kirsty white
source share