public async Task PeopleByNames_Should_Return_BadRequest_If_ModelState_Is_Invalid() { PersonControllerMock mock = PersonControllerMock.Create(); mock.ModelState.AddModelError("test", "test"); IActionResult actionResult = await mock.PeopleByNames(new List <string>() { "Deniz Özgen", "Mahmut Gündoğdu" }); var badRequestObjectResult = actionResult as BadRequestObjectResult; Assert.NotNull(badRequestObjectResult); var serializableError = badRequestObjectResult.Value as SerializableError; Assert.NotNull(serializableError); Assert.True(((string[])serializableError["test"])[0] == "test"); mock.PersonService.Verify(service => service.GetPeopleByNames(It.IsAny <IList <string> >()), Times.Never); }
public async Task PeopleByNames_Should_Call_IPersonService_GetPeopleByNames_And_Return_Ok() { PersonControllerMock mock = PersonControllerMock.Create(); var people = new List <string>() { "Uğur Aldanmaz", "Özgün Bal" }; mock.PersonService.Setup(service => service.GetPeopleByNames(It.Is <IList <string> >(p => p.Any(ps => people.Contains(ps))))).ReturnsAsync(() => new List <Person>()); IActionResult actionResult = await mock.PeopleByNames(people); var okObjectResult = actionResult as OkObjectResult; Assert.NotNull(okObjectResult); var peopleModels = okObjectResult.Value as IEnumerable <Person>; Assert.NotNull(peopleModels); mock.PersonService.Verify(service => service.GetPeopleByNames(It.IsAny <IList <string> >()), Times.Once); }