public async Task VideosByIds_Should_Return_BadRequest_If_ModelState_Is_Invalid() { VideoControllerMock mock = VideoControllerMock.Create(); mock.ModelState.AddModelError("test", "test"); IActionResult actionResult = await mock.VideosByIds(new List <int>() { 1, 3, 5 }); 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.VideoService.Verify(service => service.GetVideosByIds(It.IsAny <IList <int> >()), Times.Never); }
public async Task VideosByIds_Should_Call_IVideoService_GetVideosByIds_And_Return_Ok() { VideoControllerMock mock = VideoControllerMock.Create(); IList <int> ids = new List <int>() { 1, 2, 5 }; mock.VideoService.Setup(service => service.GetVideosByIds(It.Is <IList <int> >(vids => vids.Any(i => ids.Contains(i))))).ReturnsAsync(() => new List <VideoModel>()); IActionResult actionResult = await mock.VideosByIds(ids); var okObjectResult = actionResult as OkObjectResult; Assert.NotNull(okObjectResult); var videoModels = okObjectResult.Value as IEnumerable <VideoModel>; Assert.NotNull(videoModels); mock.VideoService.Verify(service => service.GetVideosByIds(It.IsAny <IList <int> >()), Times.Once); }