private static void AddPeople(List <Person> people) { var numberOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPeople; i++) { var personInfo = Console.ReadLine().Split(); if (personInfo.Length > 3) { var name = personInfo[0]; var age = personInfo[1]; var id = personInfo[2]; var birthDate = personInfo[3]; var citizen = new Citizen(id, name, age, birthDate); people.Add(citizen); } else { var name = personInfo[0]; var age = personInfo[1]; var group = personInfo[2]; var rebel = new Rebel(name, age, group); people.Add(rebel); } } }
public static void Main() { int numberOfPeople = int.Parse(Console.ReadLine()); ICollection <IBuyer> buyers = new HashSet <IBuyer>(); for (int i = 0; i < numberOfPeople; i++) { string[] lineInfo = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lineInfo.Length == 4) { DateTime date = DateTime.ParseExact(lineInfo[3], "dd/MM/yyyy", CultureInfo.InvariantCulture); IBuyer buyer = new Citizen(lineInfo[2], lineInfo[0], int.Parse(lineInfo[1]), date); buyers.Add(buyer); } else if (lineInfo.Length == 3) { IBuyer buyer = new Rebel(lineInfo[0], int.Parse(lineInfo[1]), lineInfo[2]); buyers.Add(buyer); } } string line; while ((line = Console.ReadLine()) != "End") { if (buyers.Any(b => b.Name == line)) { buyers.FirstOrDefault(b => b.Name == line).BuyFood(); } } Console.WriteLine(buyers.Sum(b => b.Food)); }
public void Run() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string input = Console.ReadLine(); string[] tokens = input.Split(); string name = tokens[0]; if (tokens.Length == 3) { //rebel int age = int.Parse(tokens[1]); string group = tokens[2]; if (!fake.Contains(name)) { IBuyer rebel = new Rebel(name, age, group, 0); fake.Add(name); buyers.Add(rebel); //rebel.BuyFood(); } } else if (tokens.Length == 4) { //citizen int age = int.Parse(tokens[1]); string id = tokens[2]; string birthdate = tokens[3]; if (!fake.Contains(name)) { IBuyer citizen = new Citizen(name, age, id, birthdate, 0); fake.Add(name); buyers.Add(citizen); //citizen.BuyFood(); } } } string command = Console.ReadLine(); while (command != "End") { var buyer = buyers.FirstOrDefault(b => b.Name == command); if (buyer != null) { buyer.BuyFood(); } command = Console.ReadLine(); } Console.WriteLine(buyers.Sum(b => b.Food)); }
public void Post_Rebel_Successfully() { //Arrange var name = "UnitTest"; var planet = "PlanetTest"; var rebelDto = new Rebel() { Name = name, Planet = planet }; var list = new RebelList() { Rebels = new List <Rebel>() { rebelDto } }; //Act var rebel = _con.Post(list); //ASSERT var actionResult = rebel.Result; var apiResult = (actionResult as OkObjectResult).Value as ApiResult; Assert.NotNull(apiResult); }
public async Task Crud_SpecialCharacters() { const string databaseName = "rebel0_$()+/-"; var rebels = await _client.GetOrCreateDatabaseAsync <Rebel>(databaseName); Rebel luke = await rebels.AddAsync(new Rebel { Name = "Luke", Age = 19 }); Assert.Equal("Luke", luke.Name); luke.Surname = "Skywalker"; luke = await rebels.AddOrUpdateAsync(luke); Assert.Equal("Skywalker", luke.Surname); luke = await rebels.FindAsync(luke.Id); Assert.Equal(19, luke.Age); await rebels.RemoveAsync(luke); luke = await rebels.FindAsync(luke.Id); Assert.Null(luke); await _client.DeleteDatabaseAsync(databaseName); }
public static void Main() { var enters = new Dictionary <string, IBuyer>(); var lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { var commandLine = Console.ReadLine().Split().ToList(); if (commandLine.Count == 3) { var rebel = new Rebel(commandLine[0], int.Parse(commandLine[1]), commandLine[2]); enters.Add(commandLine[0], rebel); } else if (commandLine.Count == 4) { var citizen = new Citizen(commandLine[0], int.Parse(commandLine[1]), commandLine[2], commandLine[3]); enters.Add(commandLine[0], citizen); } } var buyer = Console.ReadLine(); while (buyer != "End") { if (enters.ContainsKey(buyer)) { enters[buyer].BuyFood(); } buyer = Console.ReadLine(); } var totalAmountOfFood = enters.Values.Select(b => b.Food).Sum(); Console.WriteLine(totalAmountOfFood); }
private static void AddRebelsAndCitizens(int n, List <IBuyer> all) { for (int i = 0; i < n; i++) { var inputTokens = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries); if (inputTokens.Length == 4) { var name = inputTokens[0]; var age = int.Parse(inputTokens[1]); var id = inputTokens[2]; var birthDate = DateTime.ParseExact(inputTokens[3], "dd/MM/yyyy", CultureInfo.InvariantCulture); var citizen = new Citizen(name, age, id, birthDate); all.Add(citizen); } else if (inputTokens.Length == 3) { var name = inputTokens[0]; var age = int.Parse(inputTokens[1]); var group = inputTokens[2]; var rebel = new Rebel(name, age, group); all.Add(rebel); } } }
public void GetCitizen(string[] arr, List <Buyer> buyers) { string name; string id; string birthday; string age; Buyer buyer; switch (arr.Length) { case 3: name = arr[0]; age = arr[1]; string group = arr[2]; buyer = new Rebel(name, age, group); buyers.Add(buyer); break; case 4: name = arr[0]; age = arr[1]; id = arr[2]; birthday = arr[3]; buyer = new Person(name, age, id, birthday); buyers.Add(buyer); break; } }
public async Task <IActionResult> PutRebel(long id, Rebel rebel) { if (id != rebel.Id) { return(BadRequest()); } _context.Entry(rebel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RebelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void AddBuyers() { int numOfBuyers = int.Parse(Console.ReadLine()); for (int i = 0; i < numOfBuyers; i++) { var tokkens = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string name = tokkens[0]; int age = int.Parse(tokkens[1]); string id; string birthday; string group; switch (tokkens.Length) { case 4: id = tokkens[2]; birthday = tokkens[3]; Citizen citizen = new Citizen(name, age, id, birthday); this.buyers.Add(name, citizen); break; case 3: group = tokkens[2]; Rebel rebel = new Rebel(name, age, group); this.buyers.Add(name, rebel); break; } } }
private static List <IPeople> GetPeople() { var peopleList = new List <IPeople>(); var count = int.Parse(Console.ReadLine()); for (int i = 0; i < count; i++) { var firstInput = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries); if (firstInput.Length == 4) { var currCitizen = new Citizen(firstInput[0], int.Parse(firstInput[1]), firstInput[2], firstInput[3]); peopleList.Add(currCitizen); } else if (firstInput.Length == 3) { var currRebel = new Rebel(firstInput[0], int.Parse(firstInput[1]), firstInput[2]); peopleList.Add(currRebel); } } return(peopleList); }
public ActionResult UpdateRebel([FromBody] Rebel rebel) { var message = ""; _log.LogInformation("Init UpdateRebel"); try { if (!ModelState.IsValid) { throw new InvalidDataException("The rebel entered is not valid"); } var rebelUpdated = _rebelService.UpdateRebel(rebel); _log.LogInformation("Rebel updated successfully"); return(Ok(rebelUpdated)); } catch (InvalidDataException e) { message = "InvalidDataException: " + e.Message; _log.LogError(message); } catch (Exception e) { message = "Exception trying to UpdateRebel: " + e.Message; _log.LogError(message); } finally { _log.LogInformation("Finish UpdateRebel"); } return(BadRequest(message)); }
private static List <IBuyer> FillBuyerList(int count) { var buyerList = new List <IBuyer>(); for (int i = 0; i < count; i++) { var args = Console.ReadLine() .Split(); IBuyer buyer; if (args.Length == 3) { var name = args[0]; var age = int.Parse(args[1]); var group = args[2]; buyer = new Rebel(name, age, group); buyerList.Add(buyer); } else if (args.Length == 4) { var name = args[0]; var age = int.Parse(args[1]); var id = args[2]; var birth = DateTime.ParseExact(args[3], "dd/MM/yyyy", null); buyer = new Person(name, id, age, birth); buyerList.Add(buyer); } } return(buyerList); }
private static void AddMemebers(List <IBuyer> members, int countLines) { for (int i = 0; i < countLines; i++) { var memberTokens = Console.ReadLine() .Split(" "); if (memberTokens.Length == 4) { var name = memberTokens[0]; var age = memberTokens[1]; var id = memberTokens[2]; var birthdate = memberTokens[3]; var citizen = new Citizen(name, age, id, birthdate); members.Add(citizen); } else if (memberTokens.Length == 3) { var name = memberTokens[0]; var age = memberTokens[1]; var group = memberTokens[2]; var rebel = new Rebel(name, age, group); members.Add(rebel); } } }
public void Rebel_GetById_Ok() { //Arrange var id = 3; var name = "Rudeus"; var planet = "Earth"; var rebelDTO = new Rebel() { Id = id, Name = name, Planet = planet }; _service.Setup(a => a.GetRebelById(id)).Returns(rebelDTO); //Act var rebel = _controller.GetRebelById(id); //Assert var actionResult = rebel.Result; var apiResult = (actionResult as OkObjectResult).Value as Rebel; Assert.NotNull(apiResult); Assert.Equal(id, apiResult.Id); }
public static void Main() { var numOfPeople = int.Parse(Console.ReadLine()); var listOfBuyers = new List <IBuyer>(); for (int i = 0; i < numOfPeople; i++) { var buyerArgs = Console.ReadLine().Split(); IBuyer currentBuyer; if (buyerArgs.Length == 3) { currentBuyer = new Rebel(buyerArgs[0], int.Parse(buyerArgs[1]), buyerArgs[2]); } else { currentBuyer = new Citizen(buyerArgs[0], int.Parse(buyerArgs[1]), buyerArgs[2], buyerArgs[3]); } listOfBuyers.Add(currentBuyer); } string buyerName; while ((buyerName = Console.ReadLine()) != "End") { foreach (var buyer in listOfBuyers.Where(b => b.Name == buyerName)) { buyer.BuyFood(); } } var totalAmountOfFood = listOfBuyers.Sum(b => b.Food); Console.WriteLine(totalAmountOfFood); }
private void AddDate(int n) { for (int i = 0; i < n; i++) { var input = Console.ReadLine() .Split(' ') .ToArray(); string name = input[0]; int age = int.Parse(input[1]); if (input.Length == 3) { string group = input[2]; var rebel = new Rebel(name, age, group); rebels.Add(rebel); } else if (input.Length == 4) { string id = input[2]; string birthDate = input[3]; var citizen = new Citizen(name, age, id, birthDate); citizens.Add(citizen); } } }
public Find_Discriminator() { var client = new CouchClient("http://localhost"); _rebels = client.GetDatabase <Rebel>(_databaseName, nameof(Rebel)); _simpleRebels = client.GetDatabase <SimpleRebel>(_databaseName, nameof(SimpleRebel)); var mainRebel = new Rebel { Id = Guid.NewGuid().ToString(), Name = "Luke", Age = 19, Skills = new List <string> { "Force" } }; var rebelsList = new List <Rebel> { mainRebel }; _response = new { Docs = rebelsList }; }
static void Main(string[] args) { List <IBuyer> buyers = new List <IBuyer>(); int numberOfBuyers = int.Parse(Console.ReadLine()); for (int count = 0; count < numberOfBuyers; count++) { string[] buyersInput = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (buyersInput.Length == 3) { var rebel = new Rebel(buyersInput[0], int.Parse(buyersInput[1]), buyersInput[2]); buyers.Add(rebel); } else if (buyersInput.Length == 4) { var citizen = new Citizen(buyersInput[0], int.Parse(buyersInput[1]), buyersInput[2], buyersInput[3]); buyers.Add(citizen); } } string inputName; while ((inputName = Console.ReadLine()) != "End") { if (buyers.Any(n => n.Name == inputName)) { buyers.First(n => n.Name == inputName).BuyFood(); } } Console.WriteLine(buyers.Sum(x => x.Food)); }
public static void Main() { List <Citizen> citizens = new List <Citizen>(); List <Rebel> rebels = new List <Rebel>(); var numberOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPeople; i++) { var habitantTokens = Console.ReadLine().Split(); if (habitantTokens.Length == 3) { Rebel rebel = new Rebel(habitantTokens[0], int.Parse(habitantTokens[1]), habitantTokens[2]); rebels.Add(rebel); } if (habitantTokens.Length == 4) { Citizen citizen = new Citizen(habitantTokens[0], int.Parse(habitantTokens[1]), habitantTokens[2], habitantTokens[3]); citizens.Add(citizen); } } string buyer; List <string> names = new List <string>(); while ((buyer = Console.ReadLine()) != "End") { names.Add(buyer); } BuyFood(citizens, names); Console.WriteLine(); }
private void AddPeople() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] commandArgs = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries) .ToArray(); if (commandArgs.Length == 4) { string name = commandArgs[0]; int age = int.Parse(commandArgs[1]); string id = commandArgs[2]; string birthdate = commandArgs[3]; Citizen citizen = new Citizen(name, age, id, birthdate); this.people.Add(citizen); } else if (commandArgs.Length == 3) { string name = commandArgs[0]; int age = int.Parse(commandArgs[1]); string group = commandArgs[2]; Rebel rebel = new Rebel(name, age, group); this.people.Add(rebel); } } }
private static void AddBuyers(List <Customer> customers) { int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { string[] args = Console.ReadLine().Split(); string name = args[0]; int age = int.Parse(args[1]); if (args.Length == 3) { string group = args[2]; Rebel rebel = new Rebel(name, age, group); customers.Add(rebel); } else { string id = args[2]; string birthdate = args[3]; Citizen citizen = new Citizen(name, age, id, birthdate); customers.Add(citizen); } } }
static void Main(string[] args) { var input = ""; var n = int.Parse(Console.ReadLine()); var list = new List <IBuyer>(); for (int i = 0; i < n; i++) { input = Console.ReadLine(); var array = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length == 3 && !list.Any(c => c.Name == array[0])) { var rebel = new Rebel(array[0], int.Parse(array[1]), array[2]); list.Add(rebel); } if (array.Length > 3 && !list.Any(c => c.Name == array[0])) { var person = new Person(array[0], int.Parse(array[1]), array[2], array[3]); list.Add(person); } } while ((input = Console.ReadLine()) != "End") { if (list.Any(c => c.Name == input)) { list.Where(c => c.Name == input).ToList().ForEach(c => c.BuyFood()); } } Console.WriteLine(list.Sum(c => c.Food)); }
public ActionResult DeleteRebel([FromBody] Rebel rebel) { var message = ""; _log.LogInformation("Init DeleteRebel"); try { if (!ModelState.IsValid) { throw new InvalidDataException("Invalid modelState"); } _rebelService.DeleteRebel(rebel); _log.LogInformation("Rebel deleted successfully"); return(Ok("Rebel deleted successfully")); } catch (InvalidDataException e) { message = "InvalidDataException: " + e.Message; _log.LogError(message); } catch (Exception e) { message = "Exception trying to DeleteRebel: " + e.Message; _log.LogError(message); } finally { _log.LogInformation("Finish DeleteRebel"); } return(BadRequest(message)); }
public void Rebel_GetById_Successfully() { //Arrange var rebelId = 20; var name = "pepe"; var planeta = "tierra"; var rebelDto = new Rebel() { Id = rebelId, Name = name, Planet = planeta }; _mockRepo.Setup(x => x.GetRebelById(rebelId)).Returns(rebelDto); //Act var rebel = _con.GetRebelById(rebelId); //ASSERT var actionResult = rebel.Result; var apiResult = (actionResult as OkObjectResult).Value as Rebel; Assert.NotNull(apiResult); Assert.Equal(rebelId, apiResult.Id); }
public List <Rebel> GetAll() { try { string[] words; char[] delimiterChars = { ';', ',' }; var rebels = new List <Rebel>(); repository.SetRoute(route); List <string> list = repository.GetAll(); foreach (var line in list) { words = line.Split(delimiterChars); var rebel = new Rebel(words[0], words[1]); rebels.Add(rebel); } return(rebels); } catch (Exception e) { log.Fatal(e.Message); return(null); } }
private void GetAllPeople(int peopleCount) { for (int i = 0; i < peopleCount; i++) { var input = Console.ReadLine().Split(); var name = input[0]; var age = int.Parse(input[1]); if (input.Length == 4) { var id = input[2]; var birthdate = input[3]; IPerson citizen = new Citizen(name, age, id, birthdate); people.Add(citizen); } if (input.Length == 3) { var group = input[2]; IPerson rebel = new Rebel(name, age, group); people.Add(rebel); } } }
public bool Init(int nbSoldiers) { if (nbSoldiers < 0 || nbSoldiers > 10000) { Console.WriteLine("Merci de choisir un nombre de soldats compris entre 0 et 10 000"); return(false); } for (var i = 1; i <= nbSoldiers; i++) { var Rebel = new Rebel(i, _random.Next(1000, 2000), _random.Next(100, 500), _random.Next(1, 100), Role.Rebel); var Stormtrooper = new Stormtrooper(i, _random.Next(1000, 2000), _random.Next(100, 500), _random.Next(1, 100), Role.Stormtrooper); _rebels.Add(Rebel); _stormtroopers.Add(Stormtrooper); } DetermineHero(_rebels); DetermineHero(_stormtroopers); return(true); }
public async Task Changes() { using (var client = new CouchClient("http://localhost:5984")) { IEnumerable <string> dbs = await client.GetDatabasesNamesAsync().ConfigureAwait(false); CouchDatabase <Rebel> rebels = client.GetDatabase <Rebel>(); if (dbs.Contains(rebels.Database)) { await client.DeleteDatabaseAsync <Rebel>().ConfigureAwait(false); } rebels = await client.CreateDatabaseAsync <Rebel>().ConfigureAwait(false); Rebel luke = await rebels.CreateAsync(new Rebel { Name = "Luke", Age = 19 }).ConfigureAwait(false); Assert.Equal("Luke", luke.Name); var options = new ChangesFeedOptions { IncludeDocs = true }; var filter = ChangesFeedFilter.Selector <Rebel>(r => r.Name == "Luke" && r.Age == 19); var changesResult = await rebels.GetChangesAsync(options, filter); Assert.NotEmpty(changesResult.Results); Assert.Equal(changesResult.Results[0].Id, luke.Id); await client.DeleteDatabaseAsync <Rebel>().ConfigureAwait(false); } }
private static void GetPeople(int numberOfPeople) { for (int i = 0; i < numberOfPeople; i++) { var person = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); var name = person[0]; var age = int.Parse(person[1]); if (person.Length == 3) { var group = person[2]; IBuyer rebel = new Rebel(name, age, group); people.Add(rebel); } else if (person.Length == 4) { var id = person[2]; var birthdate = person[3]; IBuyer citizen = new Citizen(name, age, id, birthdate); people.Add(citizen); } } }
public ITextSource GetSource(Rebel.Foundation.Localization.TextManager textManager, Assembly referenceAssembly, string targetNamespace) { var source = new SimpleTextSource(); source.Texts.Add(new LocalizedText { Namespace = targetNamespace, Key = "FactoryTest", Pattern = "I'm from a factory", Language = "en-US", Source = new TextSourceInfo { TextSource = source, ReferenceAssembly = referenceAssembly } }); return source; }
public ITextSource GetSource(Rebel.Foundation.Localization.TextManager textManager, Assembly referenceAssembly, string targetNamespace) { _targetNamespace = targetNamespace; _referenceAssembly = referenceAssembly; return _source; }