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

            IFuncionarioService service = new FuncionarioService(repositoryFake.Object);

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

            //Assert
            repositoryFake.Verify(r => r.Delete(1));
            Assert.IsNull(funcionarioFake);
        }
コード例 #2
0
        public void RetrieveFuncionarioServiceTest()
        {
            //Arrange
            Funcionario funcionario = ObjectMother.GetFuncionario();
            //Fake do repositório
            var repositoryFake = new Mock<IFuncionarioRepository>();
            repositoryFake.Setup(r => r.Get(1)).Returns(funcionario);

            IFuncionarioService service = new FuncionarioService(repositoryFake.Object);

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

            //Assert
            repositoryFake.Verify(r => r.Get(1));
            Assert.IsNotNull(funcionarioFake);
        }
コード例 #3
0
        public void CreateFuncionarioServiceValidationAndPersistenceTest()
        {
            //Arrange
            Funcionario funcionario = ObjectMother.GetFuncionario();
            //Fake do repositório
            var repositoryFake = new Mock<IFuncionarioRepository>();
            repositoryFake.Setup(r => r.Save(funcionario)).Returns(funcionario);
            //Fake do dominio
            var funcionarioFake = new Mock<Funcionario>();
            funcionarioFake.As<IObjectValidation>().Setup(b => b.Validate());

            IFuncionarioService service = new FuncionarioService(repositoryFake.Object);

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

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