public void TestPrepararPlato()
        {
            var mockBasculaService = new Mock <IBasculaService>();
            var mockCocinaService  = new Mock <ICocinaService>();

            //       mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny<Alimento>())).Returns(1.5F);
            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimento>())).Returns((Alimento p) => p.Peso);
            // mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny<Alimento>())).Returns(5F);
            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimento>())).Returns((Alimento p) => p.Peso);

            mockCocinaService.Setup(cocina => cocina.Calentar(It.IsAny <Alimento>(), It.IsAny <Alimento>()))
            .Callback(
                (Alimento p1, Alimento p2)
                =>
            {
                p1.Calentado = true;
                p2.Calentado = true;
            }
                );

            IBasculaService basculaService = mockBasculaService.Object;
            ICocinaService  cocinaService  = mockCocinaService.Object;

            TurboMixService sut       = new TurboMixService(basculaService, cocinaService);
            Alimento        alimento1 = new Alimento();

            alimento1.Peso      = 1.5f;
            alimento1.Calentado = true;
            Alimento alimento2 = new Alimento();

            alimento2.Peso      = 5f;
            alimento2.Calentado = true;

            Alimento alimentoCocinado1 = new Alimento();

            alimentoCocinado1.Peso      = 1.5f;
            alimentoCocinado1.Calentado = true;
            Alimento alimentoCocinado2 = new Alimento();

            alimentoCocinado2.Peso      = 5f;
            alimentoCocinado2.Calentado = true;

            Plato resultado = sut.PesarYCalentar(alimento1, alimento2);

            mockBasculaService.Verify(bascula => bascula.Pesar(It.IsAny <Alimento>()), Times.AtLeast(2));
            mockCocinaService.Verify(cocina => cocina.Calentar(It.IsAny <Alimento>(), It.IsAny <Alimento>()), Times.AtLeastOnce);

            Plato mPlato = new Plato(alimento1, alimento2);

            Assert.AreNotEqual(mPlato, resultado);
        }
Beispiel #2
0
        public void init()
        {
            IBascula basculaService = new BasculaService();
            ICocina  cocinaService  = new CocinaService();

            sut              = new TurboMixService(basculaService, cocinaService);
            alimento1        = new Alimentos();
            alimento1.Nombre = "patata";
            alimento1.peso   = 25;

            alimento2        = new Alimentos();
            alimento2.Nombre = "zanahoria";
            alimento2.peso   = 35;
        }
        public void TestPrepararPlato()
        {
            var mockBasculaService = new Mock <IBascula>();
            var mockCocinaService  = new Mock <ICocina>();

            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimentos>()))
            .Returns((Alimentos p) => p.peso);
            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimentos>()))
            .Returns((Alimentos p) => p.peso);


            mockCocinaService.Setup(cocina => cocina.Calentar(It.IsAny <Alimentos>(), It.IsAny <Alimentos>()))
            .Callback(
                (Alimentos p1, Alimentos p2)
                => {
                p1.Calentado = true;
                p2.Calentado = true;
            }
                );

            IBascula basculaService = mockBasculaService.Object;
            ICocina  cocinaService  = mockCocinaService.Object;

            TurboMixService sut       = new TurboMixService(basculaService, cocinaService);
            Alimentos       alimento1 = new Alimentos();

            alimento1.Nombre = "patata";
            alimento1.peso   = 25;

            Alimentos alimento2 = new Alimentos();

            alimento2.Nombre = "zanahoria";
            alimento2.peso   = 35;


            Receta miReceta  = new Receta(alimento1, alimento2, 25, 35);
            Platos resultado = sut.PrepararPlato(miReceta, alimento1, alimento2);

            mockBasculaService.Verify(bascula => bascula.Pesar(It.IsAny <Alimentos>()), Times.AtLeast(2));
            mockCocinaService.Verify(cocina => cocina.Calentar(It.IsAny <Alimentos>(), It.IsAny <Alimentos>()),
                                     Times.Once);

            Platos mPlato = new Platos(alimento1, alimento2);

            Assert.AreEqual(mPlato, resultado);
        }
        public void init()
        {
            IBasculaService basculaService = new BasculaService();
            ICocinaService  cocinaService  = new CocinaService();

            sut                 = new TurboMixService(basculaService, cocinaService);
            alimento1           = new Alimento();
            alimento1.Peso      = 1.5f;
            alimento1.Calentado = true;
            alimento2           = new Alimento();
            alimento2.Peso      = 5f;
            alimento2.Calentado = true;

            alimentoCocinado1           = new Alimento();
            alimentoCocinado1.Peso      = 1.5f;
            alimentoCocinado1.Calentado = true;
            alimentoCocinado2           = new Alimento();
            alimentoCocinado2.Peso      = 5f;
            alimentoCocinado2.Calentado = true;
        }
        public void TestHacerComidaSinReceta()
        {
            var mockBasculaService = new Mock <IBasculaService>();
            var mockCocinaService  = new Mock <ICocinaService>();

            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimento>()))
            .Returns((Alimento p) => p.peso);
            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimento>()))
            .Returns((Alimento p) => p.peso);

            mockCocinaService.Setup(cocina => cocina.Calentar(It.IsAny <Alimento>(), It.IsAny <Alimento>()))
            .Callback(
                (Alimento p1, Alimento p2) => { p1.calentado = true; p2.calentado = true; });

            IBasculaService basculaService = mockBasculaService.Object;
            ICocinaService  cocinaService  = mockCocinaService.Object;

            Alimento a = new Alimento();

            a.peso   = 25F;
            a.nombre = "Pollo";
            Alimento b = new Alimento();

            b.peso   = 10.2F;
            b.nombre = "Curry";
            TurboMixService sut = new TurboMixService(basculaService, cocinaService, null);

            Plato resultado = sut.HacerComida(a, b);

            mockBasculaService.Verify(bascula => bascula.Pesar(It.IsAny <Alimento>()), Times.AtLeast(2));
            mockCocinaService.Verify(cocina => cocina.Calentar(It.IsAny <Alimento>(), It.IsAny <Alimento>()), Times.Once);

            Plato mplato = new Plato(a, b);

            Assert.AreEqual(mplato, resultado);
        }