Exemplo n.º 1
0
        public void PlayerAppService_BuyHero_WithoutMoney_False()
        {
            //Arrange
            var player = new PlayerViewModel()
            {
                PlayerName  = "test",
                PlayerMoney = 23
            };

            var hero = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 24
            };

            //Act
            var repoPlayer = MockRepository.GenerateStub <IPlayerRepository>();

            repoPlayer.Stub(s => s.GetById(player.PlayerId)).Return(Mapper.Map <PlayerViewModel, Player>(player));

            var repoHero = MockRepository.GenerateStub <IHeroRepository>();

            repoHero.Stub(s => s.GetById(hero.HeroId)).Return(Mapper.Map <HeroViewModel, Hero>(hero));

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            var heroService   = new HeroService(repoHero, repoType);
            var playerService = new PlayerService(repoPlayer, heroService);
            var AppService    = new PlayerAppService(playerService, heroService);

            player.ValidationResult.Add(AppService.BuyHero(player.PlayerId, hero.HeroId));

            Assert.IsFalse(player.ValidationResult.IsValid);
            Assert.IsTrue(player.ValidationResult.Erros.Any(e => e.Message == "You don't have money to buy this hero. Please chose another"));
        }
Exemplo n.º 2
0
        public void PlayerAppService_BuyHero_True()
        {
            //Arrange
            var player = new PlayerViewModel()
            {
                PlayerName  = "test",
                PlayerMoney = 300
            };

            var hero = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 24
            };

            //Act
            var repoPlayer = MockRepository.GenerateStub <IPlayerRepository>();

            repoPlayer.Stub(s => s.GetById(player.PlayerId)).Return(Mapper.Map <PlayerViewModel, Player>(player));

            var repoHero = MockRepository.GenerateStub <IHeroRepository>();

            repoHero.Stub(s => s.GetById(hero.HeroId)).Return(Mapper.Map <HeroViewModel, Hero>(hero));

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            var heroService   = new HeroService(repoHero, repoType);
            var playerService = new PlayerService(repoPlayer, heroService);
            var AppService    = new PlayerAppService(playerService, heroService);

            player.ValidationResult.Add(AppService.BuyHero(player.PlayerId, hero.HeroId));

            Assert.IsTrue(player.ValidationResult.IsValid);
        }
Exemplo n.º 3
0
        public void PlayerAppService_BuyHero_Inconsistent_False()
        {
            //Arrange
            var player = new PlayerViewModel()
            {
                PlayerName  = "test",
                PlayerMoney = 300
            };

            var hero = new HeroViewModel()
            {
                HeroName  = "test",
                HeroPrice = 24
            };

            //Act
            var repoPlayer = MockRepository.GenerateStub <IPlayerRepository>();

            repoPlayer.Stub(s => s.GetById(player.PlayerId)).Return(null);

            var repoHero = MockRepository.GenerateStub <IHeroRepository>();

            repoHero.Stub(s => s.GetById(hero.HeroId)).Return(null);

            var repoType = MockRepository.GenerateStub <IHeroTypeRepository>();

            var heroService   = new HeroService(repoHero, repoType);
            var playerService = new PlayerService(repoPlayer, heroService);
            var AppService    = new PlayerAppService(playerService, heroService);

            player.ValidationResult.Add(AppService.BuyHero(player.PlayerId, hero.HeroId));

            Assert.IsFalse(player.ValidationResult.IsValid);
            Assert.IsTrue(player.ValidationResult.Erros.Any(e => e.Message == "Invalid Player"));
            Assert.IsTrue(player.ValidationResult.Erros.Any(e => e.Message == "Invalid Hero"));
        }