예제 #1
0
        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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }