Example #1
0
        public async Task GettingEnemyByName_ValidInput_ReturnsEntity(string name, int health, int attack, int defense,
                                                                      int speed, int goldOnKill)
        {
            await using var dbContext = new AppDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var entity = await dbContext.AddAsync(new Enemy()
            {
                Name       = name,
                Health     = health,
                Attack     = attack,
                Defense    = defense,
                Speed      = speed,
                GoldOnKill = goldOnKill
            });

            await dbContext.SaveChangesAsync();

            var repository = new EnemyRepository(dbContext);

            var result = await repository.GetEnemyByName(entity.Entity.Id);

            Assert.NotNull(result);
            Assert.Equal(name, result.Name);
            Assert.Equal(health, result.Health);
            Assert.Equal(attack, result.Attack);
            Assert.Equal(defense, result.Defense);
            Assert.Equal(speed, result.Speed);
            Assert.Equal(goldOnKill, result.GoldOnKill);
        }
Example #2
0
        public async Task GettingEnemyByName_InvalidInput_ReturnsNull(string name, int health, int attack, int defense,
                                                                      int speed, int goldOnKill)
        {
            await using var dbContext = new AppDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var entity = await dbContext.AddAsync(new Enemy()
            {
                Name       = name,
                Health     = health,
                Attack     = attack,
                Defense    = defense,
                Speed      = speed,
                GoldOnKill = goldOnKill
            });

            await dbContext.SaveChangesAsync();

            var repository = new EnemyRepository(dbContext);

            var result = await repository.GetEnemyByName(int.MaxValue);

            Assert.Null(result);
        }