public void Deve_Carregar_Lista_De_Regras_Para_Contratos_Retornados() { //Arrange Mock <IContratoDeRemuneracao> contrato1 = ContratoMock(1, 2, 3); IEnumerable <IContratoDeRemuneracao> contratos = new List <IContratoDeRemuneracao>() { contrato1.Object }; Mock <IRepositorioDeContratoDeRemuneracao> contratoRepositorio = new Mock <IRepositorioDeContratoDeRemuneracao>(); contratoRepositorio.Setup(cont => cont.ListarVigentesEm(It.IsAny <Competencia[]>())).ReturnsAsync(contratos); Mock <IRegraDeRemuneracao> regra1 = new Mock <IRegraDeRemuneracao>(); Mock <IRegraDeRemuneracao> regra2 = new Mock <IRegraDeRemuneracao>(); Mock <IRegraDeRemuneracao> regra3 = new Mock <IRegraDeRemuneracao>(); Mock <IRepositorioDeRegras> regraRepositorio = new Mock <IRepositorioDeRegras>(); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 1 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra1.Object }); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 2 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra2.Object }); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 3 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra3.Object }); DescobridorDeContratos descobridor = null;// new DescobridorDeContratos(contratoRepositorio.Object, regraRepositorio.Object); //Act var task = descobridor.DescobrirContratosDeRemuneracaoAsync(new Competencia[] { new Mock <Competencia>().Object }); task.Wait(); var result = task.Result; //Assert IContratoDeRemuneracao contrato = result.ToArray()[0]; Assert.AreEqual(regra1.Object, contrato.Regras.ToArray()[0]); Assert.AreEqual(regra2.Object, contrato.Regras.ToArray()[1]); Assert.AreEqual(regra3.Object, contrato.Regras.ToArray()[2]); }
public void Deve_Retornar_Lista_De_Contratos_Referente_As_Competencias_Informadas() { //Arrange Mock <IContratoDeRemuneracao> contrato1 = ContratoMock(1); Mock <IContratoDeRemuneracao> contrato2 = ContratoMock(2); Mock <IContratoDeRemuneracao> contrato3 = ContratoMock(3, 4); IEnumerable <IContratoDeRemuneracao> contratos = new List <IContratoDeRemuneracao>() { contrato1.Object, contrato2.Object, contrato3.Object }; Mock <IRepositorioDeContratoDeRemuneracao> contratoRepositorio = new Mock <IRepositorioDeContratoDeRemuneracao>(); contratoRepositorio.Setup(cont => cont.ListarVigentesEm(It.IsAny <Competencia[]>())).ReturnsAsync(contratos); Mock <IRegraDeRemuneracao> regra1 = new Mock <IRegraDeRemuneracao>(); Mock <IRegraDeRemuneracao> regra2 = new Mock <IRegraDeRemuneracao>(); Mock <IRegraDeRemuneracao> regra3 = new Mock <IRegraDeRemuneracao>(); Mock <IRegraDeRemuneracao> regra4 = new Mock <IRegraDeRemuneracao>(); Mock <IRepositorioDeRegras> regraRepositorio = new Mock <IRepositorioDeRegras>(); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 1 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra1.Object }); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 2 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra2.Object }); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 3 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra3.Object }); //regraRepositorio.Setup(reg => reg.ObterAsync(new int[] { 4 })).ReturnsAsync(new IRegraDeRemuneracao[] { regra4.Object }); DescobridorDeContratos descobridor = null;//new DescobridorDeContratos(contratoRepositorio.Object, regraRepositorio.Object); //Act var task = descobridor.DescobrirContratosDeRemuneracaoAsync(new Competencia[] { new Mock <Competencia>().Object }); task.Wait(); var result = task.Result; //Assert Assert.Contains(contrato1.Object, result.ToArray()); Assert.Contains(contrato2.Object, result.ToArray()); Assert.Contains(contrato3.Object, result.ToArray()); }