public ActionResult CompendiumEdit(string name) { CompendiumEntryModel model = new CompendiumEntryModel(); CompendiumEntry entry = new CompendiumEntry(); if (!String.IsNullOrEmpty(name)) { Persona persona = repository.GetPersonaByPersonaName(repository.ConvertToStringFromBase64(name)); if (persona.HasCompendiumEntry) { entry = repository.GetCompendiumEntry(persona.Name); model.InheritedSkills = persona.InheritedSkills; } else { entry.PersonaName = persona.Name; entry.ActualLevel = persona.ActualLevel; } } else { model.PersonaNames = repository.GetPersonaNames(false); } model.Entry = entry; return View(model); }
public void GetCompendiumEntryByPersonaName_EntryDoesNotExist() { //Arrange CompendiumEntry entry = new CompendiumEntry { ActualLevel = 1, InheritedSkills = "Endure, Poisma", PersonaName = "Slime" }; StreamWriter writer = new StreamWriter("App_Data\\Compendium.csv", false); compendiumModel.UpdateCompendium(entry, writer); var expected = entry; //Act var result = compendiumModel.GetCompendiumEntryByPersonaName("Angel"); //Assert }
public void GetCompendiumEntryByPersonaName() { //Arrange CompendiumEntry entry = new CompendiumEntry { ActualLevel = 1, InheritedSkills = "Endure, Poisma", PersonaName = "Slime" }; StreamWriter writer = new StreamWriter("App_Data\\Compendium.csv", false); compendiumModel.UpdateCompendium(entry, writer); var expected = entry; //Act var result = compendiumModel.GetCompendiumEntryByPersonaName("Slime"); //Assert Assert.IsNotNull(result); Assert.AreEqual(expected, result); Assert.IsInstanceOfType(result, typeof(CompendiumEntry)); }
public void UpdateCompendium() { //Arrange CompendiumEntry entry = new CompendiumEntry{ ActualLevel = 1, InheritedSkills="Endure, Poisma", PersonaName = "Slime" }; StreamWriter writer = new StreamWriter("App_Data\\Compendium.csv", false); var expected = new List<CompendiumEntry>(); expected.Add(entry); //Act compendiumModel.UpdateCompendium(entry, writer); var result = compendiumModel.GetCompendium(); //Assert Assert.IsNotNull(result); CollectionAssert.AllItemsAreNotNull(result); CollectionAssert.AllItemsAreInstancesOfType(result, typeof(CompendiumEntry)); CollectionAssert.AreEqual(expected, result); }
protected List<CompendiumEntry> BuildCompendium(StreamReader reader) { List<CompendiumEntry> list = new List<CompendiumEntry>(); using (TextReader textReader = reader) { var csv = new CsvReader(textReader); while (csv.Read()) { CompendiumEntry entry = new CompendiumEntry(); entry.ActualLevel = Convert.ToInt32(csv.GetField<string>("ActualLevel")); entry.PersonaName = csv.GetField<string>("PersonaName"); entry.InheritedSkills = csv.GetField<string>("InheritedSkills"); list.Add(entry); } } return list; }
public void UpdateCompendium(CompendiumEntry personaToUpdate, StreamWriter writer) { var persona = compendium.FirstOrDefault(x => x.PersonaName == personaToUpdate.PersonaName); if(persona != null) { persona.ActualLevel = personaToUpdate.ActualLevel; persona.InheritedSkills = personaToUpdate.InheritedSkills; } else { compendium.Add(personaToUpdate); } using (TextWriter textWriter = writer) { var csv = new CsvWriter(writer); csv.WriteRecords(compendium); } }
protected List<Persona> BuildPersonaList(StreamReader reader) { List<Persona> list = new List<Persona>(); CompendiumEntry entry = new CompendiumEntry(); using (TextReader textReader = reader) { var csv = new CsvReader(textReader); while (csv.Read()) { Persona persona = new Persona(); persona.HPIncrease = Convert.ToInt32(csv.GetField<string>("HP")); persona.SPIncrease = Convert.ToInt32(csv.GetField<string>("SP")); persona.Arcana = (Arcana)Enum.Parse(typeof(Arcana), csv.GetField<string>("Arcana")); persona.ExtractedSkill = skillModel.GetSkillBySkillName(csv.GetField<string>("Card")); persona.InitialLevel = Convert.ToInt32(csv.GetField<string>("Lv")); persona.IsDownloadedContent = (csv.GetField<string>("DLC") == "X") ? true : false; persona.Name = csv.GetField<string>("Persona"); persona.LearnedSkills = skillModel.GetLearnedSkillsFromSkillList(csv.GetField<string>("Skills")); persona.InheritanceType = (csv.GetField<string>("Type") == "") ? PersonaInheritanceType.Any : (PersonaInheritanceType)Enum.Parse(typeof(PersonaInheritanceType), csv.GetField<string>("Type")); persona.InheritableSkillTypes = inheritanceModel.GetSkillInheritanceByPersonaInheritanceType(persona.InheritanceType); try { entry = compendiumModel.GetCompendiumEntryByPersonaName(persona.Name); } catch(KeyNotFoundException) { entry = null; } persona.ActualLevel = entry != null ? entry.ActualLevel : persona.InitialLevel; persona.InheritedSkills = entry != null ? skillModel.GetSkillsFromSkillList(entry.InheritedSkills) : new List<Skill>(); persona.HasCompendiumEntry = entry != null ? true : false; list.Add(persona); } } return list; }