예제 #1
0
        public void Delete_By_Topic_With_One_Topics_Per_Tag()
        {
            var tagRepository   = Substitute.For <ITopicTagRepository>();
            var topicRepository = Substitute.For <ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);

            var topicTag = new TopicTag
            {
                Tag    = "tag-one",
                Topics = new List <Topic> {
                    new Topic {
                        Name = "HulkRules"
                    }
                }
            };
            var topic = new Topic
            {
                Tags = new List <TopicTag>
                {
                    topicTag
                }
            };

            topicTagService.DeleteByTopic(topic);

            Assert.IsTrue(topicTag.Topics.Count() <= 1);
            tagRepository.Received().Delete(Arg.Is(topicTag));
        }
예제 #2
0
        public void Add_Test_With_No_Existing_Tags()
        {
            const string testtag         = "testtag";
            const string testtagtwo      = "testtagtwo";
            const string andthree        = "andthree";
            var          tagRepository   = Substitute.For <ITopicTagRepository>();
            var          topicRepository = Substitute.For <ITopicRepository>();
            var          topicTagService = new TopicTagService(tagRepository, topicRepository);

            tagRepository.GetTagName(testtag).Returns(x => new TopicTag {
                Tag = testtag
            });
            tagRepository.GetTagName(testtagtwo).Returns(x => new TopicTag {
                Tag = testtagtwo
            });
            tagRepository.GetTagName(andthree).Returns(x => new TopicTag {
                Tag = andthree
            });

            var topic = new Topic();

            topicTagService.Add(string.Concat(testtag, " , ", testtagtwo, " , ", andthree), topic);

            Assert.IsTrue(topic.Tags.Count() == 3);
            tagRepository.DidNotReceive().Add(Arg.Is <TopicTag>(x => x.Tag == testtag));
            tagRepository.DidNotReceive().Add(Arg.Is <TopicTag>(x => x.Tag == testtagtwo));
            tagRepository.DidNotReceive().Add(Arg.Is <TopicTag>(x => x.Tag == andthree));
        }
예제 #3
0
        public void Delete_By_Topic_With_Multiple_Topics_Per_Tag()
        {
            var tagRepository   = Substitute.For <ITopicTagRepository>();
            var topicRepository = Substitute.For <ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);

            var topicTag = new TopicTag
            {
                Tag    = "tag-one",
                Topics = new List <Topic> {
                    new Topic {
                        Name = "Tony"
                    }, new Topic {
                        Name = "Stark"
                    }
                }
            };
            var topic = new Topic
            {
                Tags = new List <TopicTag>
                {
                    topicTag
                }
            };

            topicTagService.DeleteByTopic(topic);

            Assert.IsFalse(topicTag.Topics.Count() <= 1);
            tagRepository.DidNotReceive().Delete(Arg.Is(topicTag));
        }
예제 #4
0
        public void DeleteTags_With_EmptyTags()
        {
            var tagRepository   = Substitute.For <ITopicTagRepository>();
            var topicRepository = Substitute.For <ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);

            var topicTags = new List <TopicTag>();

            topicTagService.DeleteTags(topicTags);

            Assert.IsTrue(!topicTags.Any());
            tagRepository.DidNotReceiveWithAnyArgs().Delete(Arg.Is <TopicTag>(x => x.Tag == null));
        }
예제 #5
0
        //[ExpectedException]
        public void UpdateTagNames_With_Empty_Tags()
        {
            var          tagRepository   = Substitute.For <ITopicTagRepository>();
            var          topicRepository = Substitute.For <ITopicRepository>();
            var          topicTagService = new TopicTagService(tagRepository, topicRepository);
            const string oldName         = "";
            const string newName         = "";

            tagRepository.GetTagName(oldName).Returns(x => null);

            topicTagService.UpdateTagNames(newName, oldName);

            tagRepository.DidNotReceiveWithAnyArgs().Update(Arg.Is <TopicTag>(x => x.Tag == null));
        }
예제 #6
0
        public void UpdateTagNames_With_Non_Existing_Tag()
        {
            var tagRepository   = Substitute.For <ITopicTagRepository>();
            var topicRepository = Substitute.For <ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);
            var oldName         = "bilbo";
            var newName         = "baggins";

            tagRepository.GetTagName(oldName).Returns(x => null);

            topicTagService.UpdateTagNames(newName, oldName);

            tagRepository.DidNotReceiveWithAnyArgs().Update(Arg.Is <TopicTag>(x => x.Tag == null));
        }
예제 #7
0
        public void Add_Test_With_Null_Tags()
        {
            var tagRepository   = Substitute.For <ITopicTagRepository>();
            var topicRepository = Substitute.For <ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);

            var topic = new Topic {
                Tags = new List <TopicTag>()
            };
            var topicTag = new TopicTag();

            topicTagService.Add(string.Empty, topic);

            Assert.IsTrue(!topic.Tags.Any());
            tagRepository.DidNotReceive().Update(Arg.Is(topicTag));
        }
예제 #8
0
        public void Add_Test()
        {
            const string tag             = "testtag";
            var          tagRepository   = Substitute.For <ITopicTagRepository>();
            var          topicRepository = Substitute.For <ITopicRepository>();
            var          topicTagService = new TopicTagService(tagRepository, topicRepository);

            tagRepository.GetTagName(tag).Returns(x => null);

            var topic = new Topic();

            topicTagService.Add(tag, topic);

            Assert.IsTrue(topic.Tags.Count() == 1);
            Assert.IsTrue(topic.Tags[0].Tag == tag);
            tagRepository.Received().Add(Arg.Is <TopicTag>(x => x.Tag == tag));
        }