public void TestPrepararPlato() { IUnityContainer container = new UnityContainer(); container.RegisterType <IBasculaService, BasculaService>(); container.RegisterType <ICocinaService, CocinaService>(); container.RegisterType <ITurbomixService, TurbomixService>(); IBasculaService basculaService = container.Resolve <IBasculaService>(); ICocinaService cocinaService = container.Resolve <ICocinaService>(); ITurbomixService sut = container.Resolve <ITurbomixService>(); Alimento mAlimento1 = new Alimento(); mAlimento1.Nombre = "Curry"; mAlimento1.Peso = 1.5F; Alimento mAlimento2 = new Alimento(); mAlimento2.Nombre = "Queso"; mAlimento1.Peso = 5F; Plato resultado = sut.PrepararPlato(mAlimento1, mAlimento2); Plato mPlato = new Plato(mAlimento1, mAlimento2); Assert.AreEqual(mPlato, resultado); }
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); }
public void TestPrepararPlato() { 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; TurbomixService sut = new TurbomixService(basculaService, cocinaService, null); Alimento mAlimento1 = new Alimento(); mAlimento1.Nombre = "Curry"; mAlimento1.Peso = 1.5F; Alimento mAlimento2 = new Alimento(); mAlimento2.Nombre = "Queso"; mAlimento1.Peso = 5F; Plato resultado = sut.PrepararPlato(mAlimento1, mAlimento2); //Verificaciones 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(mAlimento1, mAlimento2); Assert.AreEqual(mPlato, resultado); }
public void Init() { //IBasculaService basculaService = new BasculaService(); //ICocinaService cocinaService = new CocinaService(); //IRecetaRepository Recetario = new RecetaRepository(); IUnityContainer container = new UnityContainer(); container.RegisterType <ITurbomixService, TurbomixService>(); container.RegisterType <IRecetaService, RecetaService>(); container.RegisterType <IRecetaRepository, RecetaRepository>(); container.RegisterType <IBasculaService, BasculaService>(); container.RegisterType <ICocinaService, CocinaService>(); ITurbomixService sut = container.Resolve <ITurbomixService>(); IRecetaService recetaService = container.Resolve <IRecetaService>(); IRecetaRepository repo = container.Resolve <IRecetaRepository>(); IBasculaService basculaService = container.Resolve <IBasculaService>(); ICocinaService cocinaService = container.Resolve <ICocinaService>(); //sut = new TurbomixService(basculaService, cocinaService, null); mAlimento1 = new Alimento(); mAlimento1.Nombre = "Curry"; mAlimento1.Peso = 1.5F; mAlimento2 = new Alimento(); mAlimento2.Nombre = "Queso"; mAlimento2.Peso = 5F; mAlimentoReceta1 = new Alimento(); mAlimentoReceta1.Nombre = "Curry"; mAlimentoReceta1.Peso = 1.4F; mAlimentoReceta1.Calentado = true; mAlimentoReceta2 = new Alimento(); mAlimentoReceta2.Nombre = "Queso"; mAlimentoReceta2.Peso = 3F; mAlimentoReceta2.Calentado = true; receta = new Receta(mAlimentoReceta1, mAlimentoReceta2); }
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); }
public TurbomixService(IBasculaService _Bascula, ICocinaService _Cocina, IRecetaRepository _Recetario) { this.Bascula = _Bascula; this.Cocina = _Cocina; this.Recetario = _Recetario; }
//public IRecetaRepository Repository { get; set; } //public TurboMixService(IBasculaService _Bascula, ICocinaService _Cocina, IComprobarReceta _SePuedeCocinar, IRecetaRepository _Repository) //{ // this.Bascula = _Bascula; // this.Cocina = _Cocina; // this.SePuedeCocinar = _SePuedeCocinar; // this.Repository = _Repository; //} public TurboMixService(IBasculaService _Bascula, ICocinaService _Cocina, IComprobarReceta _SePuedeCocinar) { this.Bascula = _Bascula; this.Cocina = _Cocina; this.SePuedeCocinar = _SePuedeCocinar; }
public TurbomixService(IBasculaService _Bascula, ICocinaService _Cocina) { this.basculaService = _Bascula; this.cocinaService = _Cocina; }
public TurboMixService(IBasculaService _Bascula, ICocinaService _Cocina, IRecetaRepository _RecetaRepository) { this.basculaService = _Bascula; this.cocinaService = _Cocina; this.recetaRepository = _RecetaRepository; }