Пример #1
0
        public void TestFunctionality()
        {
            var mockTagsService = new Mock <ITagsService>();

            mockTagsService.Setup(x => x.FiterTagsByNames <SearchTagDataModel>("nature"))
            .Returns(new System.Collections.Generic.List <SearchTagDataModel>()
            {
                new SearchTagDataModel()
                {
                    Id   = "1",
                    Name = "nature",
                },
                new SearchTagDataModel()
                {
                    Id   = "2",
                    Name = "nature background",
                },
            });
            mockTagsService.Setup(x => x.FiterTagsByNames <SearchTagDataModel>("people"))
            .Returns(new System.Collections.Generic.List <SearchTagDataModel>()
            {
                new SearchTagDataModel()
                {
                    Id   = "1",
                    Name = "people",
                },
            });

            TagsController controller = new TagsController(
                mockTagsService.Object);

            IActionResult result = controller.AutoCompleteSearch("nature");

            Assert.IsType <JsonResult>(result);
            JsonResult jsonResult = (JsonResult)result;

            List <SearchTagDataModel> responseData = (List <SearchTagDataModel>)jsonResult.Value;

            Assert.Equal(2, responseData.Count);

            result = controller.AutoCompleteSearch("people");

            Assert.IsType <JsonResult>(result);
            jsonResult = (JsonResult)result;

            responseData = (List <SearchTagDataModel>)jsonResult.Value;
            Assert.Single(responseData);

            Assert.Equal("people", responseData[0].Name);
        }
Пример #2
0
        public void ValidateInputModel()
        {
            var mockTagsService = new Mock <ITagsService>();

            TagsController controller = new TagsController(
                mockTagsService.Object);

            IActionResult result = controller.AutoCompleteSearch(null);

            Assert.IsType <BadRequestResult>(result);

            result = controller.AutoCompleteSearch("te");
            Assert.IsType <BadRequestResult>(result);

            result = controller.AutoCompleteSearch("tes");
            Assert.IsNotType <BadRequestResult>(result);
        }