public void TestExecuteWithNomeNullSholdNotInvokeAllMethods() { //Arrange _model.canal = _str; _model.nome = null; _model.valor = _str; _model.obs = _str; _mocker.GetMock <IContatoRepository>(); _mocker.GetMock <IContatoFactory>(); _mocker.GetMock <ICreateContatoRule>() .Setup(x => x.IsValid(It.IsAny <CreateContatoModel>(), It.IsAny <ICommand>())) .Returns(true); _command = _command = new CreateContatoCommand( _mocker.Resolve <IContatoRepository>(), _mocker.Resolve <IContatoFactory>(), new List <ICreateContatoRule> { _mocker.Resolve <ICreateContatoRule>() } ); //Act _command.Execute(_model).Wait(); //Assert _mocker.Verify <IContatoFactory>(x => x.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never(), "Não foi possivel completar a execução"); _mocker.Verify <IContatoRepository>(x => x.Add(It.IsAny <Contato>()), Times.Never(), "Não foi possivel completar a execução"); }
public void TestExecuteWithAllValuesAndRulesOkSholdInvokeAllMethods() { //Arrange _model.canal = _str; _model.nome = _str; _model.valor = _str; _model.obs = _str; _mocker.GetMock <ICreateContatoRule>() .Setup(x => x.IsValid(It.IsAny <CreateContatoModel>(), It.IsAny <CreateContatoCommand>())) .Returns(true); _mocker.GetMock <IContatoFactory>() .Setup(x => x.Create(_str, _str, _str, _str)).Returns(_entity); _mocker.GetMock <IContatoRepository>(); _command = _command = new CreateContatoCommand( _mocker.Resolve <IContatoRepository>(), _mocker.Resolve <IContatoFactory>(), new List <ICreateContatoRule> { _mocker.Resolve <ICreateContatoRule>() } ); //Act _command.Execute(_model).Wait(); //Assert _mocker.Verify <IContatoFactory>(x => x.Create(_str, _str, _str, _str), Times.Once(), ""); _mocker.Verify <IContatoRepository>(x => x.Add(It.IsAny <Contato>()), Times.Once(), ""); }