コード例 #1
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));
        }
コード例 #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 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));
        }