public void GetAllMobs_GetsAllMobs()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedLootTable1 = CreateLootTable();
            var insertedLootTable2 = CreateLootTable();

            context.LootTables.Add(insertedLootTable1);
            context.LootTables.Add(insertedLootTable2);
            context.SaveChanges();
            var insertedMob1 = CreateMob(insertedLootTable1.Id);
            var insertedMob2 = CreateMob(insertedLootTable2.Id);

            context.Mobs.Add(insertedMob1);
            context.SaveChanges();
            context.Mobs.Add(insertedMob2);
            context.SaveChanges();
            var repo = new MobRepository(context);

            // act
            List <Business.Model.Mob> mob = repo.GetAllMobs().ToList();

            // assert
            Assert.Equal(insertedMob1.Id, mob[0].Id);
            Assert.Equal(insertedMob1.Name, mob[0].Name);
            Assert.Equal(insertedMob1.LootTableId, mob[0].LootTableId);
            Assert.Equal(insertedMob1.Health, mob[0].Health);
            Assert.Equal(insertedMob1.Exp, mob[0].Exp);
            Assert.Equal(insertedMob1.Attack, mob[0].Attack);
            Assert.Equal(insertedMob1.Defense, mob[0].Defense);
            Assert.Equal(insertedMob1.Speed, mob[0].Speed);
            Assert.Equal(insertedMob2.Id, mob[1].Id);
        }
        public void GetAllWeapons_GetsAllWeapons()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedWeapon1 = CreateWeapon("AK-47");
            var insertedWeapon2 = CreateWeapon("Katana");

            context.Weapons.Add(insertedWeapon1);
            context.Weapons.Add(insertedWeapon2);
            context.SaveChanges();
            var repo = new ItemRepository(context);

            // act
            List <Business.Model.Weapon> weapon = repo.GetAllWeapons().ToList();

            // assert
            Assert.Equal(insertedWeapon1.Id, weapon[0].Id);
            Assert.Equal(insertedWeapon1.Name, weapon[0].Name);
            Assert.Equal(insertedWeapon1.Description, weapon[0].Description);
            Assert.Equal(insertedWeapon1.Damage, weapon[0].Damage);
            Assert.Equal(insertedWeapon1.AttackSpeed, weapon[0].AttackSpeed);
            Assert.Equal(insertedWeapon1.LevelRequirement, weapon[0].LevelRequirement);
            Assert.Equal(insertedWeapon1.Rarity, weapon[0].Rarity);
            Assert.Equal(insertedWeapon2.Id, weapon[1].Id);
            Assert.Equal(insertedWeapon2.Name, weapon[1].Name);
        }
        public void GetAllConsumables_GetsAllConsumables()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedConsumable1 = CreateConsumable("Health Potion");
            var insertedConsumable2 = CreateConsumable("Mana Potion");

            context.Consumables.Add(insertedConsumable1);
            context.Consumables.Add(insertedConsumable2);
            context.SaveChanges();
            var repo = new ItemRepository(context);

            // act
            List <Business.Model.Consumable> consumable = repo.GetAllConsumables().ToList();

            // assert
            Assert.Equal(insertedConsumable1.Id, consumable[0].Id);
            Assert.Equal(insertedConsumable1.ItemName, consumable[0].ItemName);
            Assert.Equal(insertedConsumable1.Description, consumable[0].Description);
            Assert.Equal(insertedConsumable1.Duration, consumable[0].Duration);
            Assert.Equal(insertedConsumable1.Strength, consumable[0].Strength);
            Assert.Equal(insertedConsumable1.Type, consumable[0].Type);
            Assert.Equal(insertedConsumable2.Id, consumable[1].Id);
            Assert.Equal(insertedConsumable2.ItemName, consumable[1].ItemName);
        }
Ejemplo n.º 4
0
        public void GetKillStats_GetsExistingKillStats()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Player    insertedPlayer    = CreatePlayer(null);
            LootTable insertedLootTable = CreateLootTable();

            context.Players.Add(insertedPlayer);
            context.LootTables.Add(insertedLootTable);
            context.SaveChanges();
            Mob insertedMob = CreateMob(insertedLootTable.Id);

            context.Mobs.Add(insertedMob);
            context.SaveChanges();
            KillStat insertedKillStat = CreateKillStat(insertedPlayer.Id, insertedMob.Id, 10);

            context.KillStats.Add(insertedKillStat);
            context.SaveChanges();
            var repo = new PlayerRepository(context);

            //act
            List <Business.Model.KillStat> killStats = repo.GetKillStats(insertedPlayer.Id).ToList();

            //assert
            Assert.Equal(insertedKillStat.Id, killStats[0].Id);
            Assert.Equal(insertedKillStat.PlayerId, killStats[0].PlayerId);
            Assert.Equal(insertedKillStat.MobId, killStats[0].MobId);
            Assert.Equal(insertedKillStat.Quantity, killStats[0].Quantity);
        }
        public void GetLoot_GetsRandomPossibleLoot()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedLootTable = CreateLootTable();

            context.LootTables.Add(insertedLootTable);
            var insertedWeapon1 = CreateWeapon("AK-47");
            var insertedWeapon2 = CreateWeapon("Katana");

            context.Weapons.Add(insertedWeapon1);
            context.Weapons.Add(insertedWeapon2);
            context.SaveChanges();
            var insertedMob = CreateMob(insertedLootTable.Id);

            context.Mobs.Add(insertedMob);
            var insertedLootLine1 = CreateLootLine(insertedLootTable.Id, insertedWeapon1.Id);
            var insertedLootLine2 = CreateLootLine(insertedLootTable.Id, insertedWeapon2.Id);

            context.SaveChanges();
            context.Lootlines.Add(insertedLootLine1);
            context.Lootlines.Add(insertedLootLine2);
            context.SaveChanges();
            var repo = new MobRepository(context);

            // act
            Business.Model.Weapon weapon = repo.GetLoot(insertedMob.Id - 1);

            // assert
            Assert.IsType <Business.Model.Weapon>(weapon);
        }
Ejemplo n.º 6
0
        public void Save_SavesCreateKillStat()
        {
            //arrange
            using var contextFactory = new Project2ContextFactory();
            using Project2Context arrangeActContext = contextFactory.CreateContext();
            Player    insertedPlayer    = CreatePlayer(null);
            LootTable insertedLootTable = CreateLootTable();

            arrangeActContext.Players.Add(insertedPlayer);
            arrangeActContext.LootTables.Add(insertedLootTable);
            arrangeActContext.SaveChanges();
            Mob insertedMob = CreateMob(insertedLootTable.Id);

            arrangeActContext.Mobs.Add(insertedMob);
            arrangeActContext.SaveChanges();
            var repo = new PlayerRepository(arrangeActContext);

            repo.UpdateKillStat(insertedPlayer.Id, insertedMob.Id);

            //act
            repo.Save();

            //assert
            using var assertContext = contextFactory.CreateContext();
            KillStat killStat = assertContext.KillStats.Single(k => k.PlayerId == insertedPlayer.Id && k.MobId == insertedMob.Id);

            Assert.InRange(killStat.Id, 1, 10000);
            Assert.Equal(insertedPlayer.Id, killStat.PlayerId);
            Assert.Equal(insertedMob.Id, killStat.MobId);
            Assert.Equal(1, killStat.Quantity);
        }
Ejemplo n.º 7
0
        public void UpdateKillStat_CreatesNewKillStat()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Player    insertedPlayer    = CreatePlayer(null);
            LootTable insertedLootTable = CreateLootTable();

            context.Players.Add(insertedPlayer);
            context.LootTables.Add(insertedLootTable);
            context.SaveChanges();
            Mob insertedMob = CreateMob(insertedLootTable.Id);

            context.Mobs.Add(insertedMob);
            context.SaveChanges();
            var repo = new PlayerRepository(context);

            //act
            repo.UpdateKillStat(insertedPlayer.Id, insertedMob.Id);

            //assert
            KillStat killStat = context.KillStats.Local.Single(k => k.PlayerId == insertedPlayer.Id && k.MobId == insertedMob.Id);

            Assert.Equal(insertedPlayer.Id, killStat.PlayerId);
            Assert.Equal(insertedMob.Id, killStat.MobId);
            Assert.Equal(1, killStat.Quantity);
        }
Ejemplo n.º 8
0
        public void GetCharacterStats_GetsExistingCharacterStats()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Character insertedCharacter = CreateCharacter();

            context.Characters.Add(insertedCharacter);
            context.SaveChanges();
            Player insertedPlayer = CreatePlayer(insertedCharacter.Id);

            context.Players.Add(insertedPlayer);
            context.SaveChanges();
            var repo = new PlayerRepository(context);

            //act
            Business.Model.Character character = repo.GetCharacterStats(insertedPlayer.Id);

            //assert
            Assert.Equal(insertedCharacter.Id, character.Id);
            Assert.Equal(insertedCharacter.CharacterName, character.CharacterName);
            Assert.Equal(insertedCharacter.Exp, character.Exp);
            Assert.Equal(insertedCharacter.Health, character.Health);
            Assert.Equal(insertedCharacter.Attack, character.Attack);
            Assert.Equal(insertedCharacter.Mana, character.Mana);
        }
Ejemplo n.º 9
0
        public void CreatePlayer_Creates1PlayerAndCharacter()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Player insertedPlayer = CreatePlayer(1);

            Business.Model.Player insertedPlayerB = new Business.Model.Player
            {
                CharacterId = insertedPlayer.CharacterId,
                Username    = insertedPlayer.Username,
                Password    = insertedPlayer.Password
            };
            var repo = new PlayerRepository(context);

            //act
            Business.Model.Player placeholder = repo.CreatePlayer(insertedPlayerB, "Hamza");

            //assert
            Player    player    = context.Players.Local.Single(p => p.Username == insertedPlayerB.Username);
            Character character = context.Characters.Local.Single(c => c.CharacterName == "Hamza");

            Assert.Equal(1, player.Id);
            Assert.Equal(insertedPlayerB.CharacterId, player.CharacterId);
            Assert.Equal(insertedPlayerB.Username, player.Username);
            Assert.Equal(insertedPlayerB.Password, player.Password);
            Assert.Equal(1, character.Id);
            Assert.Equal("Hamza", character.CharacterName);
            Assert.Equal(1, character.Exp);
            Assert.Equal(10, character.Health);
            Assert.Equal(1, character.Attack);
            Assert.Equal(1, character.Defense);
            Assert.Equal(10, character.Mana);
        }
Ejemplo n.º 10
0
        public void UpdateCharacterStats_UpdatesCharacterStats()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Character characterBeforeUpdate = CreateCharacter();
            Character insertedCharacter     = new Character
            {
                Id            = characterBeforeUpdate.Id,
                CharacterName = characterBeforeUpdate.CharacterName,
                Exp           = characterBeforeUpdate.Exp,
                Health        = characterBeforeUpdate.Health,
                Attack        = characterBeforeUpdate.Attack,
                Defense       = characterBeforeUpdate.Defense,
                Mana          = characterBeforeUpdate.Mana
            };

            context.Characters.Add(insertedCharacter);
            context.SaveChanges();
            characterBeforeUpdate.Id = insertedCharacter.Id;
            var characterUpdated = new Business.Model.Character
            {
                Id            = insertedCharacter.Id,
                CharacterName = insertedCharacter.CharacterName,
                Exp           = 15,
                Health        = 12,
                Attack        = 8,
                Defense       = 6,
                Mana          = 18
            };
            var repo = new PlayerRepository(context);

            //act
            repo.UpdateCharacterStats(characterUpdated);

            //assert
            Character character = context.Characters.Local.Single(c => c.Id == characterUpdated.Id);

            Assert.Equal(characterUpdated.Id, character.Id);
            Assert.Equal(characterUpdated.CharacterName, character.CharacterName);
            Assert.Equal(characterUpdated.Exp, character.Exp);
            Assert.Equal(characterUpdated.Health, character.Health);
            Assert.Equal(characterUpdated.Attack, character.Attack);
            Assert.Equal(characterUpdated.Mana, character.Mana);
            Assert.Equal(characterBeforeUpdate.Id, character.Id);
            Assert.Equal(characterBeforeUpdate.CharacterName, character.CharacterName);
            Assert.NotEqual(characterBeforeUpdate.Exp, character.Exp);
            Assert.NotEqual(characterBeforeUpdate.Health, character.Health);
            Assert.NotEqual(characterBeforeUpdate.Attack, character.Attack);
            Assert.NotEqual(characterBeforeUpdate.Mana, character.Mana);
        }
        public void GetConsumable_Gets1ConsumableById()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedConsumable = CreateConsumable("Health Potion");

            context.Consumables.Add(insertedConsumable);
            context.SaveChanges();
            var repo = new ItemRepository(context);

            // act
            Business.Model.Consumable consumable = repo.GetConsumable(insertedConsumable.Id);

            // assert
            Assert.Equal(insertedConsumable.Id, consumable.Id);
            Assert.Equal(insertedConsumable.ItemName, consumable.ItemName);
            Assert.Equal(insertedConsumable.Description, consumable.Description);
            Assert.Equal(insertedConsumable.Duration, consumable.Duration);
            Assert.Equal(insertedConsumable.Strength, consumable.Strength);
            Assert.Equal(insertedConsumable.Type, consumable.Type);
        }
Ejemplo n.º 12
0
        public async Task UpdateCharacterExpAsync_UpdatesCharacterExp()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Character characterBeforeUpdate = CreateCharacter();
            Character insertedCharacter     = new Character
            {
                Id            = characterBeforeUpdate.Id,
                CharacterName = characterBeforeUpdate.CharacterName,
                Exp           = characterBeforeUpdate.Exp,
                Health        = characterBeforeUpdate.Health,
                Attack        = characterBeforeUpdate.Attack,
                Defense       = characterBeforeUpdate.Defense,
                Mana          = characterBeforeUpdate.Mana
            };

            context.Characters.Add(insertedCharacter);
            context.SaveChanges();
            characterBeforeUpdate.Id = insertedCharacter.Id;
            var repo = new PlayerRepository(context);

            //act
            await repo.UpdateCharacterExpAsync(insertedCharacter.Id, 20);

            //assert
            Character character = context.Characters.Local.Single(c => c.Id == insertedCharacter.Id);

            Assert.Equal(insertedCharacter.Id, character.Id);
            Assert.Equal(insertedCharacter.CharacterName, character.CharacterName);
            Assert.Equal(characterBeforeUpdate.Exp + 20, character.Exp);
            Assert.Equal(insertedCharacter.Health, character.Health);
            Assert.Equal(insertedCharacter.Attack, character.Attack);
            Assert.Equal(insertedCharacter.Mana, character.Mana);
            Assert.Equal(characterBeforeUpdate.Id, character.Id);
            Assert.Equal(characterBeforeUpdate.CharacterName, character.CharacterName);
            Assert.NotEqual(characterBeforeUpdate.Exp, character.Exp);
        }
        public void GetWeapon_Gets1ExistingWeaponById()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedWeapon = CreateWeapon("AK-47");

            context.Weapons.Add(insertedWeapon);
            context.SaveChanges();
            var repo = new ItemRepository(context);

            // act
            Business.Model.Weapon weapon = repo.GetWeapon(insertedWeapon.Id);

            // assert
            Assert.Equal(insertedWeapon.Id, weapon.Id);
            Assert.Equal(insertedWeapon.Name, weapon.Name);
            Assert.Equal(insertedWeapon.Description, weapon.Description);
            Assert.Equal(insertedWeapon.Damage, weapon.Damage);
            Assert.Equal(insertedWeapon.AttackSpeed, weapon.AttackSpeed);
            Assert.Equal(insertedWeapon.LevelRequirement, weapon.LevelRequirement);
            Assert.Equal(insertedWeapon.Rarity, weapon.Rarity);
        }
Ejemplo n.º 14
0
        public void GetLeaderboard_GetsTop10Characters()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            List <Character> insertedCharacters = Create10Characters();

            foreach (var character in insertedCharacters)
            {
                context.Characters.Add(character);
            }
            context.SaveChanges();
            var repo = new PlayerRepository(context);

            //act
            List <Business.Model.Character> characters = repo.GetLeaderboard().ToList();

            //assert
            Assert.Equal(11, characters[0].Exp);
            Assert.Equal(10, characters[1].Exp);
            Assert.Equal(3, characters[8].Exp);
            Assert.Equal(2, characters[9].Exp);
        }
        public void GetMobSpawn_GetsAllMobSpawns()
        {
            // arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            var insertedLootTable1 = CreateLootTable();
            var insertedLootTable2 = CreateLootTable();

            context.LootTables.Add(insertedLootTable1);
            context.LootTables.Add(insertedLootTable2);
            context.SaveChanges();
            var insertedMob1 = CreateMob(insertedLootTable1.Id);
            var insertedMob2 = CreateMob(insertedLootTable2.Id);

            context.Mobs.Add(insertedMob1);
            context.Mobs.Add(insertedMob2);
            context.SaveChanges();
            var insertedMobSpawn1 = CreateMobSpawn(insertedMob1.Id);
            var insertedMobSpawn2 = CreateMobSpawn(insertedMob2.Id);

            context.MobSpawns.Add(insertedMobSpawn1);
            context.SaveChanges();
            context.MobSpawns.Add(insertedMobSpawn2);
            context.SaveChanges();
            var repo = new MobRepository(context);

            // act
            List <Business.Model.MobSpawn> mobSpawns = repo.GetMobSpawns().ToList();

            // assert
            Assert.Equal(insertedMobSpawn1.Id, mobSpawns[0].Id);
            Assert.Equal(insertedMobSpawn1.ModId, mobSpawns[0].ModId);
            Assert.Equal(insertedMobSpawn1.SpawnX, mobSpawns[0].SpawnX);
            Assert.Equal(insertedMobSpawn1.SpawnY, mobSpawns[0].SpawnY);
            Assert.Equal(insertedMobSpawn2.Id, mobSpawns[1].Id);
        }
Ejemplo n.º 16
0
        public void GetPlayer_GetsExistingPlayer()
        {
            //arrange
            using var contextFactory      = new Project2ContextFactory();
            using Project2Context context = contextFactory.CreateContext();
            Character insertedCharacter = CreateCharacter();

            context.Characters.Add(insertedCharacter);
            context.SaveChanges();
            Player insertedPlayer = CreatePlayer(insertedCharacter.Id);

            context.Players.Add(insertedPlayer);
            context.SaveChanges();
            var repo = new PlayerRepository(context);

            //act
            Business.Model.Player player = repo.GetPlayer(insertedPlayer.Username, insertedPlayer.Password);

            //assert
            Assert.Equal(insertedPlayer.Id, player.Id);
            Assert.Equal(insertedPlayer.CharacterId, player.CharacterId);
            Assert.Equal(insertedPlayer.Username, player.Username);
            Assert.Equal(insertedPlayer.Password, player.Password);
        }