private void MethodGetVideosWithoutParamsReturnsAllVideos() { _videoServiceMock.Setup(repo => repo.GetAll()).Returns(_videos); var actionResult = _controller.GetVideos(null); Assert.IsType <OkObjectResult>(actionResult); var result = (OkObjectResult)actionResult; var responseObject = (ResponseObject)result.Value; Assert.Equal(_videos, responseObject.Data); }
public async Task TestGetVideos_NoSuchUser_ReturnsBadRequest() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); var controller = new VideosController(context); controller.Url = mockUrl.Object; context.Videos.Add(GetDemoVideoInstance(1)); context.Videos.Add(GetDemoVideoInstance(2)); context.Videos.Add(GetDemoVideoInstance(3)); var result = await controller.GetVideos("nosuchuser"); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }
public async Task TestGetVideos_ReturnVideos() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); var controller = new VideosController(context); controller.Url = mockUrl.Object; context.Videos.Add(GetDemoVideoInstance(1)); context.Videos.Add(GetDemoVideoInstance(2)); context.Videos.Add(GetDemoVideoInstance(3)); var result = await controller.GetVideos("testuser") as OkNegotiatedContentResult <IList <VideoModel> >; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(result.Content.Count, 3); }