public Engine(IReader reader, IWriter writer) { this.reader = reader; this.writer = writer; citizenFactory = new CitizenFactory(); rebelFactory = new RebelFactory(); buyers = new List <IBuyer>(); }
public void CreateInstance_ValidData_ReturnsValidRebel() { //Arrange var validName = "Pedro"; var validPlanet = "Marte"; //Act var rebel = RebelFactory.CreateInstance(validName, validPlanet); //Assert Assert.IsNotNull(rebel); Assert.IsNotNull(rebel.Name); Assert.IsNotNull(rebel.Planet); Assert.IsNotNull(rebel.DateTime); Assert.AreEqual(validName, rebel.Name); Assert.AreEqual(validPlanet, rebel.Planet); }
public void Run() { int numberInputs = int.Parse(Console.ReadLine()); for (int i = 0; i < numberInputs; i++) { string[] commandArgs = Console.ReadLine().Split(); if (commandArgs.Length == 4) { IBuyer citizen = CitizenFactory.CreateCitizen(commandArgs); population.Add(citizen); } else if (commandArgs.Length == 3) { IBuyer rebel = RebelFactory.CreateRebel(commandArgs); population.Add(rebel); } } while (true) { string input = Console.ReadLine(); if (input == "End") { break; } IBuyer buyer = population.FirstOrDefault(b => b.Name == input); if (buyer != null) { buyer.BuyFood(); } } Console.WriteLine(population.Sum(b => b.Food)); }
public List <Rebel> SplitData(StringCollection collection) { if (collection == null) { throw new ServiceException("Collection null"); } var rebelList = new List <Rebel>(); foreach (var linea in collection) { try { String[] data = linea.Split(','); rebelList.Add(RebelFactory.CreateInstance(data[0], data[1])); } catch (Exception ex) { throw new ServiceException("Error al recuperar los datos", ex); } } return(rebelList); }
public void CreateInstance_EmptyPlanet_ThrowsModelException() { Assert.ThrowsException <ModelException>(() => RebelFactory.CreateInstance("Pedro", "")); }
public void CreateInstance_EmptyName_ThrowsModelException() { Assert.ThrowsException <ModelException>(() => RebelFactory.CreateInstance("", "Marte")); }