Esempio n. 1
0
        public void AddPostTags_ListOfTags_Test()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var tagsService = new TagsService(mock.Object);

            tagsService.AddPostTags(new List <string>()
            {
                "banan"
            }, 2);

            mock.Verify(m => m.SaveChanges(), Times.Once);
            init.mockSetPostTags.Verify(m => m.Remove(It.IsAny <PostTags>()), Times.Exactly(3));
            init.mockSetPostTags.Verify(m => m.Add(It.IsAny <PostTags>()), Times.Once);
        }
Esempio n. 2
0
        public void AddPostTags_CountingTest_Test()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var tagName               = "banan";
            var tagName2              = "krajobraz";
            var expectedTagsCountInt  = mock.Object.Tags.First(x => x.TagName == tagName).Count;
            var expectedTagsCountInt2 = mock.Object.Tags.First(x => x.TagName == tagName2).Count;
            var tagsService           = new TagsService(mock.Object);

            tagsService.AddPostTags(new List <string>()
            {
                tagName
            }, 2);

            mock.Verify(m => m.SaveChanges(), Times.Once);
            init.mockSetPostTags.Verify(m => m.Remove(It.IsAny <PostTags>()), Times.Exactly(3));
            init.mockSetPostTags.Verify(m => m.Add(It.IsAny <PostTags>()), Times.Once);
            Assert.AreEqual(expectedTagsCountInt, mock.Object.Tags.First(x => x.TagName == tagName).Count);
            Assert.AreEqual(expectedTagsCountInt2 - 1, mock.Object.Tags.First(x => x.TagName == tagName2).Count);
        }