コード例 #1
0
        public void DeleteSaborServiceTest()
        {
            //Arrange
            Sabor sabor = null;
            //Fake do repositório
            var repositoryFake = new Mock<ISaborRepository>();
            repositoryFake.Setup(r => r.Delete(1)).Returns(sabor);

            ISaborService service = new SaborService(repositoryFake.Object);

            //Action
            var saborFake = service.Delete(1);

            //Asserts
            repositoryFake.Verify(r => r.Delete(1));
            Assert.IsNull(saborFake);
        }
コード例 #2
0
        public void RetrieveSaborServiceTest()
        {
            //Arrange
            Sabor sabor = ObjectMother.GetSabor();
            //Fake do repositório
            var repositoryFake = new Mock<ISaborRepository>();
            repositoryFake.Setup(r => r.Get(1)).Returns(sabor);

            ISaborService service = new SaborService(repositoryFake.Object);

            //Action
            var saborFake = service.Retrieve(1);

            //Assert
            repositoryFake.Verify(r => r.Get(1));
            Assert.IsNotNull(saborFake);
        }
コード例 #3
0
        public void CreateSaborServiceValidationAndPersistenceTest()
        {
            //Arrange
            Sabor sabor = ObjectMother.GetSabor();
            //Fake do repositório
            var repositoryFake = new Mock<ISaborRepository>();
            repositoryFake.Setup(r => r.Save(sabor)).Returns(sabor);
            //Fake do dominio
            var saborFake = new Mock<Sabor>();
            saborFake.As<IObjectValidation>().Setup(b => b.Validate());

            ISaborService service = new SaborService(repositoryFake.Object);

            //Action
            service.Create(saborFake.Object);

            //Assert
            saborFake.As<IObjectValidation>().Verify(b => b.Validate());
            repositoryFake.Verify(r => r.Save(saborFake.Object));
        }