コード例 #1
0
        public void Test_Find_FindsCharacterInDatabase()
        {
            Character testCharacter = new Character("Artorias", 0,1, 1,1,1);
              testCharacter.Save();

              Character foundCharacter = Character.Find(testCharacter.GetId());

              Assert.Equal(testCharacter, foundCharacter);
        }
コード例 #2
0
        public void Test_Save_SavesToDatabase()
        {
            Character testCharacter = new Character("Artorias", 0, 1, 1,1,1);

              testCharacter.Save();
              List<Character> result = Character.GetAll();
              List<Character> testList = new List<Character>{testCharacter};

              Assert.Equal(testList, result);
        }
コード例 #3
0
        public void Test_Update_UpdatesCharacterWithNewValues()
        {
            Character testCharacter = new Character("Artorias", 0,1, 1,1,1);
              testCharacter.Save();

              testCharacter.SetName("Guts");
              testCharacter.Update();

              Character resultCharacter = Character.Find(testCharacter.GetId());
              Character test = new Character("Guts", 0,1, 1,1,1, testCharacter.GetId());

              Assert.Equal(test, resultCharacter);
        }
コード例 #4
0
        public void Test_Delete_DeletesCharacterFromDatabase()
        {
            Character testCharacter1 = new Character("Artorias", 0,1, 1,1,1);
              testCharacter1.Save();
              Character testCharacter2 = new Character("Guts", 0,1, 1,1,1);
              testCharacter2.Save();

              Character.Delete(testCharacter1.GetId());

              List<Character> testList = new List<Character>{testCharacter2};
              List<Character> resultList = Character.GetAll();

              Assert.Equal(testList, resultList);
        }
コード例 #5
0
 public HomeModule()
 {
     Get["/"]= _ =>{
     return View["index.cshtml"];
       };
       Get["/character/new"]= _ =>{
     Dictionary<string, object> model = new Dictionary<string, object>();
     model.Add("class", Class.GetAll());
     model.Add("item", Item.GetAll());
     model.Add("itemTypes", ItemType.GetAll());
     return View["main.cshtml", model];
       };
       Post["/character/create"]= _ =>{
     Character newCharacter = new Character(Request.Form["name"],Request.Form["klass"],Request.Form["bodyType"],Request.Form["weapon"],Request.Form["armor"],Request.Form["special"]);
     newCharacter.Save();
     Dictionary<string, object> model = new Dictionary<string, object>();
     Class characterClassName = Class.Find(newCharacter.GetClassId());
     Item characterBodyType = Item.Find(newCharacter.GetBodyTypeId());
     Item characterWeapon = Item.Find(newCharacter.GetWeaponId());
     Item characterArmor = Item.Find(newCharacter.GetArmorId());
     Item characterSpecial = Item.Find(newCharacter.GetSpecialId());
     model.Add("className", characterClassName);
     model.Add("bodyType", characterBodyType);
     model.Add("weapon", characterWeapon);
     model.Add("armor", characterArmor);
     model.Add("special", characterSpecial);
     model.Add("newCharacter", newCharacter);
     return View["new_character.cshtml", model];
       };
       Get["/character/load"] =_=> {
     List<Character> AllCharacters = Character.GetAll();
     return View["load_character.cshtml", AllCharacters];
       };
       Get["/character/update/{id}"] =parameters=> {
     Dictionary<string, object> model = new Dictionary<string, object>();
     model.Add("klass", Class.GetAll());
     model.Add("item", Item.GetAll());
     model.Add("itemTypes", ItemType.GetAll());
     Character currentCharacter = Character.Find(parameters.id);
     model.Add("current", currentCharacter);
     return View["update_character.cshtml", model];
       };
       Post["/character/confirm-update/{id}"] =parameters=> {
     Character currentCharacter = Character.Find(parameters.id);
     currentCharacter.SetBodyType(Request.Form["bodyType"]);
     currentCharacter.SetClass(Request.Form["klass"]);
     currentCharacter.SetName(Request.Form["name"]);
     currentCharacter.SetWeapon(Request.Form["weapon"]);
     currentCharacter.SetArmor(Request.Form["armor"]);
     currentCharacter.SetSpecial(Request.Form["special"]);
     currentCharacter.Update();
     List<Character> AllCharacters = Character.GetAll();
     return View["load_character.cshtml", AllCharacters];
       };
       Get["/character/delete/{id}"] =parameters=> {
     Character currentCharacter = Character.Find(parameters.id);
     Dictionary<string, object> model = new Dictionary<string, object>();
     Class characterClassName = Class.Find(currentCharacter.GetClassId());
     Item characterBodyType = Item.Find(currentCharacter.GetBodyTypeId());
     Item characterWeapon = Item.Find(currentCharacter.GetWeaponId());
     Item characterArmor = Item.Find(currentCharacter.GetArmorId());
     Item characterSpecial = Item.Find(currentCharacter.GetSpecialId());
     model.Add("current", currentCharacter);
     model.Add("className", characterClassName);
     model.Add("bodyType", characterBodyType);
     model.Add("weapon", characterWeapon);
     model.Add("armor", characterArmor);
     model.Add("special", characterSpecial);
     return View["delete_character.cshtml", model];
       };
       Get["/character/delete-confirm/{id}"] =parameters=> {
     Character.Delete(parameters.id);
     List<Character> AllCharacters = Character.GetAll();
     return View["load_character.cshtml", AllCharacters];
       };
 }