Exemplo n.º 1
0
        public void should_create_check_wordmodel_IsValidForNew()
        {
            //arrange
            var model = new WordModel();

            //act
            var sut = new WordServiceBuilder().WithWordRepository(Mock.Of<IRepository<Word>>()).Build();

            var result = sut.Create(model);

            //assert
            Assert.IsNull(result);
        }
Exemplo n.º 2
0
        public void create_check_if_word_allready_exists()
        {
            //arrange
            var model = new WordModel
            {
                Key = "key",
                Tag = "tag"
            };

            var wordRepository = new Mock<IRepository<Word>>();
            wordRepository.Setup(x => x.Any(It.IsAny<Expression<Func<Word, bool>>>()))
                          .Returns(true);

            //act
            var sut = new WordServiceBuilder().WithWordRepository(wordRepository.Object)
                                              .Build();

            var result = sut.Create(model);

            //assert
            Assert.IsNull(result);
            wordRepository.Verify(x => x.Any(It.IsAny<Expression<Func<Word, bool>>>()), Times.Once);
          
        }
Exemplo n.º 3
0
        public void should_create_word()
        {
            //arrange
            var model = new WordModel
            {
                Key = "key",
                Tag = "tag1"
            };

            var wordRepository = new Mock<IRepository<Word>>();
            wordRepository.Setup(x => x.SaveChanges()).Returns(true);

            //act
            var sut = new WordServiceBuilder().WithWordRepository(wordRepository.Object).Build();

            var result = sut.Create(model);

            //assert
            Assert.IsNotNull(result);
            Assert.AreEqual(model.Key, result.Result);
            
            wordRepository.Verify(x => x.Create(It.IsAny<Word>()), Times.Once);
            wordRepository.Verify(x => x.SaveChanges(), Times.Once);
        }
Exemplo n.º 4
0
        public void should_create_check_for_savechanges_returns_true()
        {
            //arrange
            var model = new WordModel
            {
                Key = "key",
                Tag = "tag"
            };

            var wordRepository = new Mock<IRepository<Word>>();
            wordRepository.Setup(x => x.SaveChanges()).Returns(false);

            //act
            var sut = new WordServiceBuilder().WithWordRepository(wordRepository.Object).Build();

            var result = sut.Create(model);

            //assert
            Assert.IsNull(result);
        }