public void CantAddSameHero() { //Arrange Hero hero = new Hero(1, "Slaughter", 10, 15, "Warrior", 1); var mock = new Mock<IService<Hero>>(); mock.Setup(m => m.GetAllObjects()).Returns(new List<Hero>() { hero }); var manager = new HeroManager(new MenuActionService(), mock.Object); //Act var returnHeroWithSameName = manager.AddNewHero("Slaughter", 1); var returnHeroWithSameName2 = manager.AddNewHero("Slaughter", 2); //Assert returnHeroWithSameName.Should().Be(0); returnHeroWithSameName2.Should().Be(0); }
public void CantAddHeroWithIncorrectParameters() { //Arrange var mock = new Mock<IService<Hero>>(); mock.Setup(m => m.GetAllObjects()).Returns(new List<Hero>()); var manager = new HeroManager(new MenuActionService(), mock.Object); //Act var returnedWrongTypeId = manager.AddNewHero("Slaughter", 3); var returnedTooSmallName = manager.AddNewHero("sw", 2); var returnedNameWithSpaces = manager.AddNewHero(" ", 1); //Assert returnedWrongTypeId.Should().Be(0); returnedTooSmallName.Should().Be(0); returnedNameWithSpaces.Should().Be(0); }
public void CanAddHero() { //Arrange var mock = new Mock<IService<Hero>>(); mock.Setup(m => m.GetAllObjects()).Returns(new List<Hero>()); var manager = new HeroManager(new MenuActionService(), mock.Object); //Act var returnedWarriorId = manager.AddNewHero("Slaughter", 1); //Assert returnedWarriorId.Should().NotBe(0); returnedWarriorId.Should().Be(1); }
public void CheckHeroId() { //Arrange Hero hero = new Hero(1, "Slaughter", 10, 15, "Warrior", 1); Hero hero2 = new Hero(2, "Hero", 10, 15, "Paladin", 1); var mock = new Mock<IService<Hero>>(); mock.Setup(m => m.GetAllObjects()).Returns(new List<Hero>() { hero }); mock.Setup(m => m.GetLastId()).Returns(hero.Id); var manager = new HeroManager(new MenuActionService(), mock.Object); //Act var returnedId = manager.AddNewHero(hero2.Name, hero2.TypeId); //Assert returnedId.Should().NotBe(null); returnedId.Should().NotBe(hero.Id); returnedId.Should().Be(hero2.Id); }
static void Main(string[] args) { MenuActionService menuActionService = new MenuActionService(); HeroService heroService = new HeroService(); HeroManager heroManager = new HeroManager(menuActionService, heroService); EnemyService enemyService = new EnemyService(); StoryManager storyManager; int tryHard = 0; bool choseLvlOne = false; bool choseLvlTwo = false; bool choseLvlThree = false; int lastDiffLvl = 0; List <Hero> heroes = null; Console.WriteLine("Welcome to RPG Game app!"); while (true) { int exit = 0; Console.WriteLine("Please let me know what you want to do:"); var mainMenu = menuActionService.GetMenuActionsByMenuName("Main"); for (int i = 0; i < mainMenu.Count; i++) { Console.WriteLine($"{mainMenu[i].Id}. {mainMenu[i].Name}"); } var operation = Console.ReadKey(); switch (operation.KeyChar) { case '1': var newId = heroManager.AddNewHero(); break; case '2': heroManager.RemoveHero(); break; case '3': heroManager.HeroDetails(); break; case '4': var toShow = heroManager.ShowHeroes(); Console.WriteLine(toShow.ToStringTable(new[] { "Id", "Name", "Health", "Max Health", "Attack", "Heal Level", "Experience", "Level", "Required Experience", "Profession", "Typ Id" }, a => a.Id, a => a.Name, a => a.Health, a => a.MaxHealth, a => a.Attack, a => a.HealLvl, a => a.Exp, a => a.Level, a => a.RequiredExp, a => a.Profession, a => a.TypeId)); break; case '5': heroes = heroManager.GetAllHeroes(); if (heroes.Count > 0) { Console.WriteLine(); Console.WriteLine(heroes.ToStringTable(new[] { "Id", "Name", "Health", "Max Health", "Attack", "Heal Level", "Experience", "Level", "Required Experience", "Profession", "Typ Id" }, a => a.Id, a => a.Name, a => a.Health, a => a.MaxHealth, a => a.Attack, a => a.HealLvl, a => a.Exp, a => a.Level, a => a.RequiredExp, a => a.Profession, a => a.TypeId)); int chosenHero = -1; Hero hero = null; while (hero == null) { chosenHero = heroManager.SelectCharacter(); if (chosenHero == -1) { break; } hero = heroManager.GetHeroById(chosenHero); } if (chosenHero != -1) { Console.WriteLine($"You chose Hero {hero.Name}, level:{hero.Level}, profession:{hero.Profession}"); storyManager = new StoryManager(menuActionService, hero, enemyService); storyManager.SetLastDiffLvl(lastDiffLvl); storyManager.Start(); if (storyManager.DiffLvl == lastDiffLvl) { tryHard++; enemyService.UpgradeEnemiesByDiffLvl(tryHard, storyManager.DiffLvl); } else { tryHard = 0; } lastDiffLvl = storyManager.DiffLvl; hero.Reset(); switch (storyManager.DiffLvl) { case 1: choseLvlOne = true; break; case 2: choseLvlTwo = true; break; case 3: choseLvlThree = true; break; } if (choseLvlOne && choseLvlTwo && choseLvlThree) { enemyService.UpgradeEnemies(1); choseLvlOne = false; choseLvlTwo = false; choseLvlThree = false; } } } else { Console.WriteLine("\nThere is no heroes to choose"); } break; case '6': exit = 1; if (heroes != null) { bool IsFileCreated = CreateXmlFileWithAllHeroes(heroes); if (IsFileCreated) { Console.WriteLine("\nSaved all Heroes in file listOfAllHeroes.xml"); } } Console.WriteLine("Press Enter to continue"); Console.ReadLine(); break; default: Console.WriteLine("Action you entered does not exist"); break; } if (exit == 1) { break; } } }