Ejemplo n.º 1
0
        public async Task TestGetVideosWithAllTags_ReturnsNotFound()
        {
            var context = new TestContext();

            context.Users.Add(new User
            {
                UserId   = 1,
                Username = "******"
            });
            var controller = new VideosController(context);
            var video      = GetDemoVideoInstance(1);

            context.Videos.Add(GetDemoVideoInstance(1));
            context.Videos.Add(GetDemoVideoInstance(2));
            context.Tags.Add(new Tag {
                TagName = "test", VideoId = 1
            });
            context.Tags.Add(new Tag {
                TagName = "fun", VideoId = 1
            });
            context.Tags.Add(new Tag {
                TagName = "nontest", VideoId = 2
            });
            context.Tags.Add(new Tag {
                TagName = "nonfun", VideoId = 2
            });
            var location = "http://location/";
            var mockUrl  = new Mock <UrlHelper>();

            mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location);
            controller.Url = mockUrl.Object;
            var result = await controller.GetVideosWithAllTags(new List <string> {
                "test", "fun"
            }, "testuser") as OkNegotiatedContentResult <IList <VideoModel> >;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(result.Content.Count, 1);
        }
Ejemplo n.º 2
0
        public async Task TestGetVideosWithAllTags_InvalidParameters__ReturnsBadResult()
        {
            var context = new TestContext();

            context.Users.Add(new User
            {
                UserId   = 1,
                Username = "******"
            });
            var controller = new VideosController(context);
            var video      = GetDemoVideoInstance(1);

            context.Videos.Add(GetDemoVideoInstance(1));
            context.Videos.Add(GetDemoVideoInstance(2));
            context.Tags.Add(new Tag {
                TagName = "test", VideoId = 1
            });
            context.Tags.Add(new Tag {
                TagName = "fun", VideoId = 1
            });
            context.Tags.Add(new Tag {
                TagName = "nontest", VideoId = 2
            });
            context.Tags.Add(new Tag {
                TagName = "nonfun", VideoId = 2
            });
            var location = "http://location/";
            var mockUrl  = new Mock <UrlHelper>();

            mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location);
            controller.Url = mockUrl.Object;
            var result = await controller.GetVideosWithAllTags(new List <string> {
                "test", "fun"
            }, "");

            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
        }