Пример #1
0
        public async Task TestGetVideoWithAnyTag_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(2));
            context.Videos.Add(GetDemoVideoInstance(1));



            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 result = await controller.GetVideosWithAnyTag(new List <string> {
                "test", "nonfun"
            }, "testuser") as OkNegotiatedContentResult <IList <VideoModel> >;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(result.Content.Count, 2);
        }
Пример #2
0
        public async Task TestGetVideoWithAnyTag_InvalidParameters_ReturnsBadResult()
        {
            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(2));
            context.Videos.Add(GetDemoVideoInstance(1));



            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 result = await controller.GetVideosWithAnyTag(new List <string> {
                "nosuchtag", "nosuchtag2"
            }, null);

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