예제 #1
0
        public async Task AllTags_should_return_all_tags_fill_count_property()
        {
            // given
            List <string> tags = _fixture.CreateMany <string>().ToList();

            var duplicateTags = new List <string>();

            duplicateTags.Add("duplicate-tag");
            duplicateTags.Add("duplicate-tag");
            duplicateTags.Add("duplicate-tag");
            tags.AddRange(duplicateTags);

            int expectedTagCount = tags.Count - (duplicateTags.Count - 1);

            _pageRepositoryMock
            .AllTagsAsync()
            .Returns(tags);

            // when
            IEnumerable <TagResponse> tagViewModels = await _tagsController.AllTags();

            // then
            await _pageRepositoryMock
            .Received(1)
            .AllTagsAsync();

            tagViewModels.Count().ShouldBe(expectedTagCount);
            tagViewModels.First(x => x.Name == "duplicate-tag").Count.ShouldBe(3);
        }
예제 #2
0
        public async Task AllTags_should_return_all_tags_and_fill_count_property()
        {
            // given
            List <string> tags = _fixture.CreateMany <string>().ToList();

            var duplicateTags = new List <string>();

            duplicateTags.Add("duplicate-tag");
            duplicateTags.Add("duplicate-tag");
            duplicateTags.Add("duplicate-tag");
            tags.AddRange(duplicateTags);

            int expectedTagCount = tags.Count - (duplicateTags.Count - 1);

            _pageRepositoryMock
            .AllTagsAsync()
            .Returns(tags);

            // when
            ActionResult <IEnumerable <TagResponse> > actionResult = await _tagsController.AllTags();

            // then
            actionResult.ShouldBeOkObjectResult();
            IEnumerable <TagResponse> response = actionResult.GetOkObjectResultValue();

            response.Count().ShouldBe(expectedTagCount);
            response.First(x => x.Name == "duplicate-tag").Count.ShouldBe(3);
        }
예제 #3
0
        public async Task <ActionResult <IEnumerable <TagResponse> > > AllTags()
        {
            IEnumerable <string> allTags = await _pageRepository.AllTagsAsync();

            var responses = new List <TagResponse>();

            foreach (string tag in allTags)
            {
                var existingModel = responses.FirstOrDefault(x => x.Name == tag);
                if (existingModel != null)
                {
                    existingModel.Count += 1;
                }
                else
                {
                    responses.Add(new TagResponse()
                    {
                        Name = tag, Count = 1
                    });
                }
            }

            return(Ok(responses));
        }