public async Task TestPutVideo_ReturnsSucess() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); controller.Request = new System.Net.Http.HttpRequestMessage { RequestUri = new Uri("http://localhost/api/Video") }; controller.Configuration = new System.Web.Http.HttpConfiguration(); controller.Configuration.Routes.MapHttpRoute( name: "GetVideoByLink", routeTemplate: "api/GetVideo" ); controller.RequestContext.RouteData = new HttpRouteData( route: new HttpRoute(), values: new HttpRouteValueDictionary { { "controller", "Video" } }); var video = GetDemoVideoModelInstance(1); var result = await controller.PostVideo(video) as CreatedAtRouteNegotiatedContentResult <VideoModel>; Assert.IsNotNull(result); Assert.AreEqual(result.RouteName, "GetVideoByLink"); Assert.AreEqual(result.RouteValues["link"], "test.com/check"); Assert.AreEqual(result.RouteValues["user"], "testuser"); }
private void MethodPostVideoAddsVideoInRepo() { _videoServiceMock.Setup(repo => repo.Add(_video4)); var toPost = new ResponseObject { Data = _video4 }; var actionResult = _controller.PostVideo(toPost); Assert.IsType <OkObjectResult>(actionResult); var result = (OkObjectResult)actionResult; var responseObject = (ResponseObject)result.Value; Assert.Equal(_video4, responseObject.Data); _videoServiceMock.Verify(repo => repo.Add(_video4), Times.Once); }
public async Task TestPostVideo() { using (var context = new GuessContext(Options)) { // Make a new video controller VideosController videosController = new VideosController(context, _mapper); // Get the result of PostVideo method ActionResult <Video> result = await videosController.PostVideo(Url); // Check whether the result is null Assert.IsNotNull(result); } }
public async Task TestPostVideo_ReturnError() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); var mockurl = new Mock <UrlHelper>(); mockurl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("https://testlocation"); controller.Url = mockurl.Object; var video = GetDemoVideoModelInstance(1); video.VideoLink = null; var result = await controller.PostVideo(video); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }