Ejemplo n.º 1
0
            public void Remove_Given_Stats_by_id_fails()
            {
                //Arrange
                var expectedResult = new Stats()
                {
                    StatsId = 1, Time = 20
                };

                StatsRepository
                .Setup(g => g.Remove(expectedResult.StatsId)).Throws(new Exception());

                UnitofWorkMock
                .Setup(u => u.Stats)
                .Returns(StatsRepository.Object);

                //Act
                var result = _uut.Delete(expectedResult.StatsId);

                //Assert
                StatsRepository.Verify();

                var response = Assert.IsType <BadRequestObjectResult>(result);

                Assert.Equal(400, response.StatusCode);
            }
Ejemplo n.º 2
0
        public ActionResult UpdateFunction(DatabaseStatModel model)
        {
            var   repo  = new StatsRepository(new StatsSQLContext());
            Stats s     = repo.GetById(model.SelectedId);
            Stats prevS = new Stats(s.Level, s.Experience, s.Health, s.Spirit, s.HealthRegen, s.SpiritRegen, s.Strength, s.Dexterity, s.Intelligence);

            prevS.Id = s.Id;
            if (model.Level != 0)
            {
                s.Level = model.Level;
            }
            if (model.Health != 0)
            {
                s.Health = model.Health;
            }
            if (model.Spirit != 0)
            {
                s.Spirit = model.Spirit;
            }
            if (model.Strength != 0)
            {
                s.Strength = model.Strength;
            }
            if (model.Dexterity != 0)
            {
                s.Dexterity = model.Dexterity;
            }
            if (model.Intelligence != 0)
            {
                s.Intelligence = model.Intelligence;
            }
            repo.Update(s);
            return(Content($"Succesfully updated </br>{prevS.ToReadableString()} </br>to </br>{s.ToReadableString()}"));
        }
        public void RefreshGenomeStatsCache_UpdatesCache_WhenInvokedAndCacheAlreadyExists()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var testGenomes = new List <Genome>()
            {
                new Genome(new[] { "ACGT", "TGCA" }, false),
                new Genome(new[] { "AAAA", "BBBB" }, true),
            };

            readContext.Genomes.AddRange(testGenomes);
            readContext.SaveChanges();
            var testStats = new StatsModel()
            {
                Id          = 1,
                HumanCount  = 1,
                MutantCount = 0,
                Ratio       = 0,
                Changed     = DateTime.UtcNow.AddDays(-1)
            };

            commandContext.StatsModels.Add(testStats);
            commandContext.SaveChanges();
            var statsRepository = new StatsRepository(readContext, commandContext);

            statsRepository.RefreshGenomeStatsCache();
            var result = commandContext.StatsModels.Find(1);

            Assert.Equal(1, result.HumanCount);
            Assert.Equal(1, result.MutantCount);
            Assert.Equal(0.5, result.Ratio);
        }
Ejemplo n.º 4
0
        public override DougResponse Activate(User user, ICombatable target, string channel)
        {
            if (!CanActivateSkill(user, out var response))
            {
                return(response);
            }

            var userToBeHealed = user;

            if (target != null && target is User targetUser)
            {
                userToBeHealed = targetUser;
            }

            var healAmount = 30; // TODO : add scaling

            userToBeHealed.Health += healAmount;
            StatsRepository.UpdateHealth(userToBeHealed.Id, userToBeHealed.Health);

            var message = string.Format(DougMessages.UserHealed, _userService.Mention(user), _userService.Mention(userToBeHealed), healAmount);

            _slack.BroadcastMessage(message, channel);

            return(new DougResponse());
        }
Ejemplo n.º 5
0
            public async void Should_Return_Badrequest_when_wrong_input_is_given()
            {
                //Arrange
                var expectedResult = new List <Stats>()
                {
                    new Stats {
                        StatsId = 1, Time = 10
                    },
                    new Stats {
                        StatsId = 2, Time = 10
                    }
                };

                StatsRepository
                .Setup(x => x.GetAll())
                .ReturnsAsync((List <Stats>)null).Verifiable();

                UnitofWorkMock
                .Setup(m => m.Stats)
                .Returns(StatsRepository.Object);

                //Act
                var result = await _uut.GetAll();

                //Assert
                StatsRepository.Verify();

                var ErrorResult = Assert.IsType <NotFoundResult>(result);

                Assert.Equal(404, ErrorResult.StatusCode);
            }
Ejemplo n.º 6
0
 public StatsService(DiscordSocketClient client, PrefixCommandHandler commandHandler, StatsRepository repository, ILogger <StatsService> logger)
 {
     this._client         = client;
     this._commandHandler = commandHandler;
     this._repository     = repository;
     this._logger         = logger;
 }
Ejemplo n.º 7
0
        protected override bool CanActivateSkill(User user, ICombatable target, string channel, out DougResponse response)
        {
            var totalCooldown = Cooldown * (1 - user.CooldownReduction());

            if (target is User targetUser)
            {
                var usersInChannel = _slack.GetUsersInChannel(channel).Result;
                if (usersInChannel.All(usr => usr != targetUser.Id))
                {
                    response = new DougResponse(DougMessages.UserNotInChannel);
                    return(false);
                }
            }

            if (user.IsSkillOnCooldown())
            {
                response = new DougResponse(string.Format(DougMessages.CommandOnCooldown, user.CalculateStealCooldownRemaining()));
                return(false);
            }

            if (!user.HasEnoughEnergyForCost(EnergyCost))
            {
                response = new DougResponse(DougMessages.NotEnoughEnergy);
                return(false);
            }

            user.Energy -= EnergyCost;
            StatsRepository.FireSkill(user.Id, TimeSpan.FromSeconds(totalCooldown), user.Energy);
            response = new DougResponse();
            return(true);
        }
Ejemplo n.º 8
0
        public async Task GetsStats()
        {
            using (var context = new ApplicationDbContext(_options))
            {
                context.Stats.AddRange(
                    new Stats {
                    Id = 1
                },
                    new Stats {
                    Id = 2
                },
                    new Stats {
                    Id = 3
                });

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var statsRepository = new StatsRepository(context);

                var stats = await statsRepository.GetAll(0, 2);

                Assert.Equal(2, stats.Count);
                Assert.NotNull(stats.SingleOrDefault(x => x.Id == 1));
                Assert.NotNull(stats.SingleOrDefault(x => x.Id == 2));
            }
        }
Ejemplo n.º 9
0
        public void StatsSelect()
        {
            StatsRepository repo = new StatsRepository(new StatsSQLContext());
            Stats           s    = repo.GetById(1);

            Assert.IsNotNull(s, "Stats wasn't correctly retrieved");
        }
Ejemplo n.º 10
0
        public async Task GetsStatsById()
        {
            using (var context = new ApplicationDbContext(_options))
            {
                context.Stats.AddRange(
                    new Stats {
                    Id = 1
                },
                    new Stats {
                    Id = 2
                });

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var statsRepository = new StatsRepository(context);

                var stats = await statsRepository.GetById(1);

                var stats2 = await statsRepository.GetById(2);

                Assert.NotNull(stats);
                Assert.NotNull(stats2);
                Assert.Equal(1, stats.Id);
                Assert.Equal(2, stats2.Id);
            }
        }
Ejemplo n.º 11
0
        public void MultiStatsSelect()
        {
            StatsRepository repo = new StatsRepository(new StatsSQLContext());
            List <Stats>    s    = repo.GetAll();

            Assert.IsNotNull(s, "Multiple stats weren't correctly retrieved");
        }
Ejemplo n.º 12
0
        public async Task Correct_Stats_Returned()
        {
            using (var contextFactory = new SqliteInMemoryDbContextFactory <ApplicationDbContext>(options => new ApplicationDbContext(options)))
            {
                using (var context = await contextFactory.CreateContextAsync())
                {
                    SeedTestData.Seed(context);
                    await context.SaveChangesAsync();
                }

                using (var context = await contextFactory.CreateContextAsync())
                {
                    var repo    = new StatsRepository(context);
                    var results = await repo.GetRoomSummaryAsync();

                    //Ensure the SQL returns correct stats for each room type
                    foreach (var roomType in context.RoomTypes)
                    {
                        Assert.Equal(await context.Jobs.CountAsync(j => j.RoomTypeId == roomType.Id && j.StatusNum == JobStatus.NotStarted), results.First(r => r.Name == roomType.Name && r.Status == JobStatus.NotStarted.Description()).Count);
                        Assert.Equal(await context.Jobs.CountAsync(j => j.RoomTypeId == roomType.Id && j.StatusNum == JobStatus.Delayed), results.First(r => r.Name == roomType.Name && r.Status == JobStatus.Delayed.Description()).Count);
                        Assert.Equal(await context.Jobs.CountAsync(j => j.RoomTypeId == roomType.Id && j.StatusNum == JobStatus.InProgress), results.First(r => r.Name == roomType.Name && r.Status == JobStatus.InProgress.Description()).Count);
                        Assert.Equal(await context.Jobs.CountAsync(j => j.RoomTypeId == roomType.Id && j.StatusNum == JobStatus.Complete), results.First(r => r.Name == roomType.Name && r.Status == JobStatus.Complete.Description()).Count);
                        Assert.Equal(await context.Jobs.CountAsync(j => j.RoomTypeId == roomType.Id), results.First(r => r.Name == roomType.Name).Total);
                    }
                }
            }
        }
Ejemplo n.º 13
0
            public async void Should_Return_Badrequest_when_wrong_input_is_given()
            {
                //Arrange
                var expectedResult = new Stats()
                {
                    StatsId = 1, Time = 20
                };

                StatsRepository
                .Setup(x => x.Get(expectedResult.StatsId))
                .ReturnsAsync((Stats)null).Verifiable();

                UnitofWorkMock
                .Setup(m => m.Stats)
                .Returns(StatsRepository.Object);

                //Act
                var result = await _uut.Get(expectedResult.StatsId);

                //Assert
                StatsRepository.Verify();

                var ErrorResult = Assert.IsType <BadRequestObjectResult>(result);

                Assert.Equal(400, ErrorResult.StatusCode);
            }
Ejemplo n.º 14
0
        public ActionResult DeleteFunction(DatabaseStatModel model)
        {
            var repo = new StatsRepository(new StatsSQLContext());

            repo.Delete(model.SelectedId);
            return(Content($"Succesfully removed stat with {model.SelectedId} id"));
        }
Ejemplo n.º 15
0
        public ActionResult InsertFunction(DatabaseStatModel model)
        {
            var   repo = new StatsRepository(new StatsSQLContext());
            Stats s    = new Stats(model.Level, 0, model.Health, model.Spirit, 0, 0, model.Strength, model.Dexterity, model.Intelligence);

            repo.Insert(s);
            return(Content($"Succesfully inserted: {s.ToReadableString()}"));
        }
Ejemplo n.º 16
0
        public UnitOfWork(DataContext context)
        {
            _context = context;

            LeaderBoard = new LeaderBoardRepository(_context);
            Game        = new GameRepository(_context);
            Queue       = new QueueRepository(_context);
            Stats       = new StatsRepository(_context);
            Player      = new PlayerRepository(_context);
        }
Ejemplo n.º 17
0
        public IEnumerable <SelectListItem> GetStats()
        {
            var repo  = new StatsRepository(new StatsSQLContext());
            var roles = repo.GetAll().Select(x => new SelectListItem {
                Value = x.Id.ToString(),
                Text  = x.ToReadableString()
            });

            return(new SelectList(roles, "Value", "Text"));
        }
Ejemplo n.º 18
0
        private static async Task ExportClasses()
        {
            // WCL Api Library
            var wclApi = new WCL_Api();
            var repo   = new StatsRepository();

            // Get Classes and Upload to DB
            var classes    = wclApi.GetClassicClassesAsync().Result;
            var newClasses = classes.Select(s => s.ToClassicClass()).ToList();

            repo.Classes.Add(newClasses);
        }
Ejemplo n.º 19
0
        private static async Task ExportZones()
        {
            // WCL Api Library
            var wclApi = new WCL_Api();
            var repo   = new StatsRepository();

            // Get Zones and Upload to DB
            var zones    = wclApi.GetZonesAsync().Result;
            var newZones = zones.Select(s => s.ToZone()).ToList();

            repo.Zones.Add(newZones);
        }
Ejemplo n.º 20
0
        private void SaveAll()
        {
            var UserRepo  = new UsersRepository();
            var StatsRepo = new StatsRepository();

            Player1.LogIn = false;
            Player2.LogIn = false;

            UserRepo.Save(Player1);
            UserRepo.Save(Player2);

            StatsRepo.Save(Player1.Stats);
            StatsRepo.Save(Player2.Stats);
        }
Ejemplo n.º 21
0
        public void UpdateStats()
        {
            StatsRepository repo = new StatsRepository(new StatsSQLContext());
            Stats           s    = repo.GetById(2);

            s.Spirit += 10;
            int spirit = s.Spirit;

            repo.Update(s);
            s = repo.GetById(2);
            Assert.AreEqual(s.Spirit, spirit, "Stats weren't updated.");
            s.Spirit -= 10;
            repo.Update(s);
        }
 public PokemonServicesImpl(
     PokemonRepository pokemonRepository,
     StatsRepository statsRepository,
     AbilitiesRepository abilitiesRepository,
     StorageProvider storageProvider,
     IMapper mapper
     )
 {
     this.pokemonRepository   = pokemonRepository;
     this.statsRepository     = statsRepository;
     this.abilitiesRepository = abilitiesRepository;
     this.storageProvider     = storageProvider;
     this.mapper = mapper;
 }
Ejemplo n.º 23
0
        public async Task CreatesStats()
        {
            using (var context = new ApplicationDbContext(_options))
            {
                var statsRepository = new StatsRepository(context);

                await statsRepository.Create(new Stats { Id = 1 });
            }

            using (var context = new ApplicationDbContext(_options))
            {
                Assert.Equal(1, context.Stats.Count());
                Assert.Equal(1, context.Stats.Single().Id);
            }
        }
Ejemplo n.º 24
0
        public void GetStats_ReturnsCorrectStatsModel_WhenInvokedWithNoData()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var statsRepository = new StatsRepository(readContext, commandContext);

            var result = statsRepository.GetGenomeStats();

            Assert.Equal(0, result.HumanCount);
            Assert.Equal(0, result.MutantCount);
            Assert.Equal(0, result.Ratio);
        }
Ejemplo n.º 25
0
        public async Task ExecJSONQueryTest()
        {
            Stats     stats     = null;
            StatsView statsView = null;

            Assert.NotNull(dbc = new DBContext(settings.Database.ConnectionString, logger));
            StatsRepository statsRepos = new StatsRepository(settings, logger, dbc);

            stats = await statsRepos.GetStats();

            statsView = JsonConvert.DeserializeObject <StatsView>(stats.Result);
            Assert.NotNull(statsView);
            Assert.True(statsView.TotalContacts > 0);
            dbc.Close();
        }
Ejemplo n.º 26
0
            public async void Should_Return_OkObjectResult_with_list_of_Stats()
            {
                //Arrange
                var expectedResult = new List <Stats>()
                {
                    new Stats {
                        StatsId = 1, Time = 10
                    },
                    new Stats {
                        StatsId = 2, Time = 10
                    }
                };

                var finalResult = new List <StatsResponse>()
                {
                    new StatsResponse()
                    {
                        StatsId = 1, Time = 10
                    },
                    new StatsResponse()
                    {
                        StatsId = 2, Time = 10
                    }
                };

                StatsRepository
                .Setup(r => r.GetAll())
                .ReturnsAsync(expectedResult).Verifiable();

                UnitofWorkMock
                .Setup(x => x.Stats)
                .Returns(StatsRepository.Object);

                MapperMock
                .Setup(m => m.Map <List <StatsResponse> >(expectedResult))
                .Returns(finalResult).Verifiable();

                //Act
                var result = await _uut.GetAll();

                //Assert
                StatsRepository.Verify();
                MapperMock.Verify();

                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(finalResult, okResult.Value);
            }
Ejemplo n.º 27
0
        public async Task UpdatesStats()
        {
            var statsPf  = 2;
            var statsPf2 = 4;

            var mockStats = new List <Stats>
            {
                new Stats {
                    Id = 1, Pf = statsPf
                },
                new Stats {
                    Id = 2
                },
                new Stats {
                    Id = 3
                }
            };

            using (var context = new ApplicationDbContext(_options))
            {
                context.Stats.AddRange(mockStats);

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var statsRepository = new StatsRepository(context);
                var existingStats   = mockStats[0];
                var updatedStats    = mockStats[0];
                updatedStats.Pf = statsPf2;
                await statsRepository.Update(existingStats, updatedStats);
            }

            using (var context = new ApplicationDbContext(_options))
            {
                Assert.NotNull(context.Stats.SingleOrDefault(x => x.Id == 1));
                Assert.Equal(statsPf2, context.Stats.Single(x => x.Id == 1).Pf);
            }
        }
Ejemplo n.º 28
0
        public void GetStats_ReturnsCorrectStatsModel_WhenInvokedWithOnlyOneMutantRow()
        {
            var rOptions = TestDbContextOptionsFactory.GetTestReadDbOptions();
            var cOptions = TestDbContextOptionsFactory.GetTestCommandDbOptions();

            using var readContext    = new ReadGenomeContext(rOptions);
            using var commandContext = new CommandGenomeContext(cOptions);
            var testGenomes = new List <Genome>()
            {
                new Genome(new[] { "ACGT", "TGCA" }, true),
            };

            readContext.Genomes.AddRange(testGenomes);
            readContext.SaveChanges();
            var statsRepository = new StatsRepository(readContext, commandContext);

            var result = statsRepository.GetGenomeStats();

            Assert.Equal(0, result.HumanCount);
            Assert.Equal(1, result.MutantCount);
            Assert.Equal(1, result.Ratio);
        }
Ejemplo n.º 29
0
        public async Task DeletesStats()
        {
            var mockStats = new List <Stats>
            {
                new Stats {
                    Id = 1
                },
                new Stats {
                    Id = 2
                },
                new Stats {
                    Id = 3
                }
            };

            using (var context = new ApplicationDbContext(_options))
            {
                context.Stats.AddRange(mockStats);

                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext(_options))
            {
                var statsRepository = new StatsRepository(context);

                var stats = mockStats[0];
                await statsRepository.Delete(stats);
            }

            using (var context = new ApplicationDbContext(_options))
            {
                Assert.Equal(2, context.Stats.Count());
                Assert.Null(context.Stats.SingleOrDefault(x => x.Id == 1));
            }
        }
Ejemplo n.º 30
0
        public override async Task <DougResponse> Activate(User user, ICombatable target, string channel)
        {
            if (!CanActivateSkill(user, target, channel, out var response))
            {
                return(response);
            }

            var userToBeHealed = user;

            if (target != null && target is User targetUser)
            {
                userToBeHealed = targetUser;
            }

            var healAmount = user.Level * 5 + 2 * user.TotalIntelligence();

            userToBeHealed.Health += healAmount;
            StatsRepository.UpdateHealth(userToBeHealed.Id, userToBeHealed.Health);

            var message = string.Format(DougMessages.UserHealed, _userService.Mention(user), _userService.Mention(userToBeHealed), healAmount);
            await _slack.BroadcastMessage(message, channel);

            return(new DougResponse());
        }