public void Service_Conta_AdicionarConta_DevePassar() { //Arrange var conta = ContaObjectMother.GetContaValida(); var contaCmd = ContaObjectMother.GetContaValidaParaRegistrar(); _repositoryFake.Setup(x => x.Add(It.IsAny <Conta>())) .Returns(conta); _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns(conta.Cliente); //Action var novoContaId = _service.Add(contaCmd); //Verify _repositoryFake.Verify(x => x.Add(It.IsAny <Conta>()), Times.Once); novoContaId.Should().Be(conta.Id); }
public void Service_Conta_AdicionarConta_Com_IdCliente_Inesistente_DeveJogarExcessao_NotFoundException() { //Arrange var conta = ContaObjectMother.GetContaValida(); var contaCmd = ContaObjectMother.GetContaValidaParaRegistrar(); contaCmd.ClienteId = 20; // _repositoryFake.Setup(pr => pr.Add(conta)); _repositoryClienteFake.Setup(cl => cl.GetById(contaCmd.ClienteId)).Returns((Cliente)null); //Action Action act = () => _service.Add(contaCmd); //Assert act.Should().Throw <NotFoundException>(); //_repositoryFake.Verify(x => x.Add(conta), Times.Never); _repositoryClienteFake.Verify(pr => pr.GetById(contaCmd.ClienteId), Times.Once); }