Exemple #1
0
        public void start()
        {
            tasks.workDone += EmailService.SendEmail;
            tasks.workDone += PushNotification.SendPushNotification;
            tasks.workDone += TextMessageService.SendText;
            do
            {
                Console.WriteLine("Welcome Hero! What would you like to do?");
                Console.WriteLine("[0] Create a Hero?");
                Console.WriteLine("[1] Get all Heros?");
                Console.WriteLine("[2] Go to work?");
                Console.WriteLine("[3] Go back to the main menu?");
                userInput = Console.ReadLine();
                switch (userInput)
                {
                case "0":
                    //call create a hero, get hero details
                    SuperHero newSuperHero = GetHeroDetails();
                    //call the business logic and the repo
                    try{
                        heroService.AddHero(newSuperHero);
                    } catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        continue;
                    }
                    break;

                case "1":
                    //call get all heros
                    foreach (var hero in heroService.GetAllHeroes())
                    {
                        Console.WriteLine($"Hero: \n\tHero Alias: {hero.Alias} \n\tHero Real Name: {hero.RealName} \n\tHero Hideout: {hero.HideOut}");
                        foreach (var power in hero.SuperPowers)
                        {
                            Console.WriteLine($"\tSuper Powers:\n\t\tName: {power.Name}\n\t\tDescription: {power.Description}");
                        }
                    }
                    break;

                case "2":
                    //call the event delegate for hero work, call get hero by name
                    tasks.DoWork();
                    tasks.ManageLife();
                    Console.WriteLine("Press <enter>");
                    break;

                case "3":
                    Console.WriteLine("Going back to main");
                    break;

                default:
                    //invalid input message;
                    service.InvalidInputMessage();
                    break;
                }
            } while (!userInput.Equals("3"));
        }
        public IActionResult Post([FromBody] Hero hero)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(_heroService.AddHero(hero)));
        }
        public void start()
        {
            tasks.workDone += EmailService.SendEmail;
            tasks.workDone += PushNotification.SendPushNotification;
            tasks.workDone += TextMessageService.SendText;
            do
            {
                Console.WriteLine("Welcome Hero! What would you like to do?");
                Console.WriteLine("[0] Create a Hero?");
                Console.WriteLine("[1] Get all Heros?");
                Console.WriteLine("[2] Go to work?");
                Console.WriteLine("[3] Go back to the main menu?");
                userInput = Console.ReadLine();
                switch (userInput)
                {
                case "0":
                    //call create a hero, get hero details
                    SuperHero newSuperHero = GetHeroDetails();
                    //call the business logic and the repo
                    heroService.AddHero(newSuperHero);
                    break;

                case "1":
                    //call get all heros
                    heroService.GetAllHeroes();
                    break;

                case "2":
                    //call the event delegate for hero work, call get hero by name
                    tasks.DoWork();
                    tasks.ManageLife();
                    Console.WriteLine("Press <enter>");
                    break;

                case "3":
                    //call the main menu
                    MainMenu main = new MainMenu();
                    main.start();
                    break;

                default:
                    //invalid input message;
                    service.InvalidInputMessage();
                    break;
                }
            } while (!userInput.Equals("3"));
        }
Exemple #4
0
        public void AddHeroTest()
        {
            //Arrange
            var powers = new List <Power>();

            heroRepositoryMock.Setup(x => x.Insert(It.IsAny <Hero>()))
            .Verifiable("should insert into repository!!!");
            unitOfWorkMock.Setup(x => x.Save())
            .Verifiable("should save after insert");
            powerRepositoryMock.Setup(x => x.Get(It.IsAny <Expression <Func <Power, bool> > >()))
            .Returns(powers.AsQueryable())
            .Verifiable("should get powers in order to insert");

            var heroDto = new HeroDTO();

            //Act
            var addedHero = heroService.AddHero(heroDto);

            //Assert
            Assert.IsNotNull(addedHero);
            unitOfWorkMock.Verify();
            heroRepositoryMock.Verify();
            powerRepositoryMock.Verify();
        }