Beispiel #1
0
        public async Task SearchForPlayerAndOppoRace()
        {
            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent();
            var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent();
            var matchFinishedEvent3 = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent1.match.players[0].race = Race.UD;
            matchFinishedEvent1.match.players[1].race = Race.HU;

            matchFinishedEvent2.match.players[0].race = Race.UD;
            matchFinishedEvent2.match.players[1].race = Race.NE;

            matchFinishedEvent3.match.players[0].race = Race.OC;
            matchFinishedEvent3.match.players[1].race = Race.HU;

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent1));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent2));

            var matches = await matchRepository.LoadFor("peter#123", null, GateWay.Europe, GameMode.GM_1v1, Race.UD, Race.HU, 100, 0, 0);

            var count = await matchRepository.CountFor("peter#123", null, GateWay.Europe, GameMode.GM_1v1, Race.UD, Race.HU, 0);

            Assert.AreEqual(1, count);
            Assert.AreEqual(Matchup.Create(matchFinishedEvent1).ToString(), matches.Single().ToString());
        }
Beispiel #2
0
        public async Task LoadDetails_RandomRaceNotSetForNonRandomSelection()
        {
            var matchFinishedEvent = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent.match.id = "nmhcCLaRc7";
            matchFinishedEvent.Id       = ObjectId.GenerateNewId();

            // Set race to non-random.
            matchFinishedEvent.match.players[0].race    = Race.HU;
            matchFinishedEvent.match.players[0].rndRace = null;
            matchFinishedEvent.result.players[0].raceId = (int)RaceId.HU;
            matchFinishedEvent.match.players.Find(p => p.battleTag == matchFinishedEvent.result.players[0].battleTag).race = Race.HU;

            await InsertMatchEvent(matchFinishedEvent);

            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent));

            var result = await matchRepository.LoadDetails(matchFinishedEvent.Id);

            Assert.AreEqual("nmhcCLaRc7", result.Match.MatchId);
            Assert.AreEqual(Race.HU, result.Match.Teams[0].Players[0].Race);
            Assert.AreEqual(null, result.Match.Teams[0].Players[0].RndRace);
        }
Beispiel #3
0
 public SkillBasedAssigner(MatchRepository matchRepository, SteamworksApi steamworksApi, ILogger <SkillBasedAssigner> logger)
 {
     myMatchRepository = matchRepository;
     mySteamworksApi   = steamworksApi;
     myLogger          = logger;
     myRandom          = new Random();
 }
Beispiel #4
0
        public async Task LoadDetails_RandomRaceSetToRandomWhenNullResult()
        {
            var matchFinishedEvent = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent.match.id = "nmhcCLaRc7";
            matchFinishedEvent.Id       = ObjectId.GenerateNewId();
            matchFinishedEvent.result   = null;

            var player = matchFinishedEvent.match.players[0];

            // Set race to random.
            matchFinishedEvent.match.players[0].race = Race.RnD;

            await InsertMatchEvent(matchFinishedEvent);

            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent));

            var result = await matchRepository.LoadDetails(matchFinishedEvent.Id);

            Assert.AreEqual("nmhcCLaRc7", result.Match.MatchId);
            Assert.AreEqual(Race.RnD, result.Match.Teams[0].Players.Find(p => p.BattleTag == player.battleTag).Race);
            Assert.AreEqual(Race.RnD, result.Match.Teams[0].Players.Find(p => p.BattleTag == player.battleTag).RndRace);
        }
        public async Task GetUnclaimedAsync_WhenUserHasAnUnclaimedMatch_ReturnsUnclaimedMatch()
        {
            var matchId   = Guid.NewGuid();
            var userId    = Guid.NewGuid();
            var stubMatch = new ApplicationCore.Models.Match.Match
            {
                Id       = matchId,
                HomeTeam = new TeamDetails()
                {
                    UserId            = userId,
                    HasClaimedRewards = false
                },
                AwayTeam = new TeamDetails()
                {
                    UserId = Guid.NewGuid()
                },
                KickOff = DateTime.Now.AddMinutes(-100)
            };
            var stubMatchList = new List <ApplicationCore.Models.Match.Match>()
            {
                stubMatch
            };

            var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList);

            // Act
            var repository = new MatchRepository(dbContextStub);
            var result     = await repository.GetUnclaimedAsync(userId);

            //Assert
            Assert.Equal(stubMatch, result.First());
        }
Beispiel #6
0
 public IHttpActionResult Bet([FromBody]dynamic value)
 {
     var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault());
     var mId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("matchId").FirstOrDefault());
     var homeScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("homeScore").FirstOrDefault());
     var awayScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("awayScore").FirstOrDefault());
     var mRepo = new MatchRepository();
     if (!mRepo.ContainsId(mId))
         return NotFound();
     var uRepo = new UserRepository();
     if (!uRepo.ContainsId(uId))
         return NotFound();
     var brepo = new BetRepository();
     if (brepo.ContainsBet(mId, uId))
     {
         var b = brepo.GetByMatchAndUserIds(mId, uId);
         b.HomeTeamScore = homeScore;
         b.AwayTeamScore = awayScore;
         brepo.SaveOrUpdate(b);
     }
     else
     {
         var b = new Bet();
         b.AwayTeamScore = awayScore;
         b.HomeTeamScore = homeScore;
         b.Match = mRepo.GetById(mId);
         b.User = uRepo.GetById(uId);
         brepo.SaveOrUpdate(b);
     }
     return Ok();
 }
        public async Task Cache_ByPlayerId_OneTeamEmpty()
        {
            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            var storedEvent = TestDtoHelper.Create1v1StartedEvent();

            await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(storedEvent));

            await Task.Delay(100);

            var result = await matchRepository.TryLoadOnGoingMatchForPlayer(storedEvent.match.players[0].battleTag);

            Assert.IsNotNull(result);
            Assert.AreEqual(storedEvent.match.id, result.MatchId);

            var notCachedEvent = TestDtoHelper.Create1v1StartedEvent();
            await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(notCachedEvent));

            await Task.Delay(100);

            var result2 = await matchRepository.TryLoadOnGoingMatchForPlayer(storedEvent.match.players[0].battleTag);

            Assert.IsNotNull(result2);
            Assert.AreEqual(storedEvent.match.id, result.MatchId);
            Assert.AreEqual(notCachedEvent.match.id, result2.MatchId);
        }
Beispiel #8
0
 public AdminController(BettingContext context)
 {
     _matchRepository  = new MatchRepository(context);
     _teamRepository   = new TeamRepository(context);
     _sportRepository  = new SportRepository(context);
     _ticketRepository = new TicketRepository(context);
 }
Beispiel #9
0
 public MatchModel ReturnMatch(int matchId)
 {
     using (var repository = new MatchRepository())
     {
         return(repository.FindMatch(matchId)?.ToModel());
     }
 }
        public async Task CountFor()
        {
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine($"https://www.test.w3champions.com:{i}/login");
            }

            var matchRepository = new MatchRepository(MongoClient);

            var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent();
            var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent();
            var matchFinishedEvent3 = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent1.match.season = 1;
            matchFinishedEvent1.match.players[0].battleTag = "peter#123";
            matchFinishedEvent1.match.players[1].battleTag = "wolf#456";

            matchFinishedEvent2.match.season = 1;
            matchFinishedEvent2.match.players[0].battleTag = "wolf#456";
            matchFinishedEvent2.match.players[1].battleTag = "peter#123";

            matchFinishedEvent3.match.season = 1;
            matchFinishedEvent3.match.players[0].battleTag = "notFound";
            matchFinishedEvent3.match.players[1].battleTag = "notFound2";

            var matchup = Matchup.Create(matchFinishedEvent1);
            await matchRepository.Insert(matchup);

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent2));

            var count = await matchRepository.CountFor(matchup.Teams[0].Players[0].BattleTag);

            Assert.AreEqual(2, count);
        }
Beispiel #11
0
        public HttpResponseMessage GetByTournamentID(int id)
        {
            try
            {
                List <MatchModelGet> list = new List <MatchModelGet>();

                MatchRepository rep = new MatchRepository();
                foreach (Match m in rep.GetByTournamentID(id))
                {
                    MatchModelGet model = new MatchModelGet();
                    model.Match_ID      = m.Match_ID;
                    model.Tournament_ID = m.Tournament_ID;
                    model.Team1         = m.Team1;
                    model.Team2         = m.Team2;
                    model.Score1        = m.Score1;
                    model.Score2        = m.Score2;
                    model.TeamVictory   = m.TeamVictory;

                    list.Add(model);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, list));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
        static void Main(string[] args)
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
            IDictionary props = new Hashtable();

            props["port"] = 55555;
            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);

            ClientRepository clientRepository = new ClientRepository();
            MatchRepository  matchRepository  = new MatchRepository();
            SellerRepository sellerRepository = new SellerRepository();
            TicketRepository ticketRepository = new TicketRepository();
            var server = new ServiceImpl(clientRepository, matchRepository, sellerRepository, ticketRepository);

            //var server = new ChatServerImpl();
            RemotingServices.Marshal(server, "Chat");
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServerImpl), "Chat",
            //    WellKnownObjectMode.Singleton);

            // the server will keep running until keypress.
            Console.WriteLine("Server started ...");
            Console.WriteLine("Press <enter> to exit...");
            Console.ReadLine();
        }
Beispiel #13
0
        public async Task <ISingleModelResponse <MatchDto> > GetMatchAsync(int id)
        {
            Logger?.LogInformation($"{nameof(GetMatchAsync)} has been invoked");

            var response = new SingleModelResponse <MatchDto>();

            try
            {
                var item = await MatchRepository.GetItems()
                           .Include(m => m.Team1)
                           .Include(m => m.Team2)
                           .Include(m => m.League)
                           .Include(m => m.Scores).ThenInclude(s => s.Player)
                           .FirstOrDefaultAsync(m => m.Id == id);

                if (ShouldIncludeAuditData())
                {
                    response.Model = Mapper.Map <MatchAuditDto>(item);
                }
                else
                {
                    response.Model = Mapper.Map <MatchDto>(item);
                }
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
        public UnitOfWorkWebApi(ApplicationContext context) : base(context)
        {
            /*************Authorization************/
            Claims                 = new ClaimRepository(context);
            ClientApplications     = new ClientApplicationRepository(context);
            ClientApplicationUtils = new ClientApplicationUtilRepository(context);
            RoleClaims             = new RoleClaimRepository(context);
            RoleEntityClaims       = new RoleEntityClaimRepository(context);
            Roles            = new RoleRepository(context);
            UserClaims       = new UserClaimRepository(context);
            UserEntityClaims = new UserEntityClaimRepository(context);
            Users            = new UserRepository(context);
            UserRoles        = new UserRoleRepository(context);
            UserUtils        = new UserUtilRepository(context);
            Applications     = new ApplicationRepository(context);
            ApplicationUsers = new ApplicationUserRepository(context);
            /*************Authorization************/

            /*************Instances************/
            Matches = new MatchRepository(context);
            Teams   = new TeamRepository(context);
            Players = new PlayerRepository(context);
            Stats   = new StatRepository(context);
            /*********End of Instances*********/
        }
Beispiel #15
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context = context;
     Users    = new UserRepository(context);
     Emotions = new EmotionRepository(context);
     Match    = new MatchRepository(context);
 }
Beispiel #16
0
        private static void DownloadAndParseAndStoreScores(string sport, string directoryRepo)
        {
            var dir    = System.IO.Directory.CreateDirectory("../../../Data/" + sport);
            var sqlite = new UtilityDAL.Sqlite.KeyValueLite(dir.FullName);

            foreach (var(date, directory) in from directory in Directory.EnumerateDirectories(directoryRepo)
                     let name = Path.GetFileName(directory)
                                where Common.FileNameHelper.TryGetDateFromDirectoryName(name, out _)
                                where sqlite.FindDate(directory) == null
                                let date = Common.FileNameHelper.GetDateTimeFromDirectory(name)
                                           select
                                               (date, directory))
            {
                var info = MatchRepository.SelectInformation(directory);

                //var ids = Smarkets.DAL.Sqlite.MatchRepository.Select(date).Select(a => a.EventId.ToString()).ToArray();
                var newResults = Download2(100, date, info.Select(a => a.id.ToString()).ToArray());

                Console.WriteLine($"results downloaded {newResults.Count()}");
                foreach (var(ifo, newResult) in from ifo in info
                         join newResult in newResults
                         on ifo.id.ToString() equals newResult.id
                         select(ifo, newResult))
                {
                    int transferred = MatchRepository.TransferToDB(newResult.Item2, ifo.name);
                    Console.WriteLine($"results added {transferred}");
                    Console.Write(ifo.name);
                    Console.Write(ifo.id);
                }

                sqlite.Insert(new KeyValuePair <string, long>(directory, date.Ticks));
            }
            Console.WriteLine("Finished");
            Console.ReadLine();
        }
Beispiel #17
0
        public void AllMatches()
        {
            var repo = new MatchRepository();
            var x    = repo.GetAll();

            Assert.IsTrue(x.Count != 0);
        }
Beispiel #18
0
        public void ContainsMatch()
        {
            var repo = new MatchRepository();
            var x    = repo.GetById(1);

            Assert.IsTrue(repo.ContainsMatch(x));
        }
Beispiel #19
0
        public MyBetsController() : base(Module.MyBets)
        {
            var matchRepo = new MatchRepository();

            ViewBag.RoundExpired = matchRepo.CurrentRoundIsExpired();
            ViewBag.Expired      = matchRepo.GlobalBetsExpired();
        }
        public async Task GetAllSync_WithOneMatchPlayed_ReturnsOneMatch()
        {
            // Arrange
            var matchId   = Guid.NewGuid();
            var userId    = Guid.NewGuid();
            var stubMatch = new ApplicationCore.Models.Match.Match
            {
                Id       = matchId,
                HomeTeam = new TeamDetails()
                {
                    UserId = userId,
                },
                AwayTeam = new TeamDetails()
                {
                    UserId = Guid.NewGuid()
                }
            };
            var stubMatchList = new List <ApplicationCore.Models.Match.Match>()
            {
                stubMatch
            };

            var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList);

            // Act
            var repository = new MatchRepository(dbContextStub);
            var result     = await repository.GetAllAsync(0, 1, userId);

            //Assert
            Assert.Equal(stubMatch, result.First());
        }
Beispiel #21
0
        public void pointCalculation()
        {
            //Arange
            MatchRepository matchRepository = new MatchRepository(null);

            List <Forecast> forecast1 = DataStorage.forecasts1;
            PointsAnalysis  rules1    = new PointsAnalysis()
            {
                Full = 60, GoalDif = 30, JustWinner = 20
            };
            double expSum1 = 24;

            List <Forecast> forecast2 = DataStorage.forecasts2;
            PointsAnalysis  rules2    = new PointsAnalysis()
            {
                Full = 80, GoalDif = 20, JustWinner = 10
            };
            double expSum2 = 20;

            //Act
            double sum1 = matchRepository.calculateUserPoints(forecast1, DataStorage.fixtures, rules1);
            double sum2 = matchRepository.calculateUserPoints(forecast2, DataStorage.fixtures, rules2);

            //Assert
            Assert.AreEqual(expSum1, sum1);
            Assert.AreEqual(expSum2, sum2);
        }
        public async Task GetAllSync_WithMatchNotInvolvingUser_ReturnsEmptyList()
        {
            // Arrange
            var stubMatch = new ApplicationCore.Models.Match.Match
            {
                Id       = Guid.NewGuid(),
                HomeTeam = new TeamDetails()
                {
                    UserId = Guid.NewGuid()
                },
                AwayTeam = new TeamDetails()
                {
                    UserId = Guid.NewGuid()
                }
            };
            var stubMatchList = new List <ApplicationCore.Models.Match.Match>()
            {
                stubMatch
            };

            var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList);

            // Act
            var repository = new MatchRepository(dbContextStub);
            var result     = await repository.GetAllAsync(0, 1, Guid.NewGuid());

            //Assert
            Assert.False(result.Any());
        }
        public async Task SearchForPlayerAndOpponent_2v2And1V1()
        {
            var matchRepository = new MatchRepository(MongoClient);

            var matchFinishedEvent1 = TestDtoHelper.CreateFake2v2AtEvent();
            var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent1.match.season = 1;
            matchFinishedEvent1.match.players[0].battleTag = "peter#123";
            matchFinishedEvent1.match.players[0].team      = 0;
            matchFinishedEvent1.match.players[1].battleTag = "LostTeam1#456";
            matchFinishedEvent1.match.players[1].team      = 0;

            matchFinishedEvent1.match.players[2].battleTag = "wolf#456";
            matchFinishedEvent1.match.players[2].team      = 1;
            matchFinishedEvent1.match.players[3].battleTag = "LostTeam2#456";
            matchFinishedEvent1.match.players[3].team      = 1;

            matchFinishedEvent2.match.season = 1;
            matchFinishedEvent2.match.players[0].battleTag = "peter#123";
            matchFinishedEvent2.match.players[1].battleTag = "wolf#456";

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent1));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent2));

            var matches = await matchRepository.LoadFor("peter#123", "wolf#456");

            var count = await matchRepository.CountFor("peter#123", "wolf#456");

            Assert.AreEqual(2, count);
            Assert.AreEqual("peter#123", matches[0].Teams[0].Players[0].BattleTag);
            Assert.AreEqual("peter#123", matches[1].Teams[0].Players[0].BattleTag);
        }
Beispiel #24
0
        public HttpResponseMessage EditMatch(MatchModelEdit model)
        {
            try
            {
                Match m = new Match();
                m.Match_ID      = model.Match_ID;
                m.Tournament_ID = model.Tournament_ID;
                m.Team1         = model.Team1;
                m.Team2         = model.Team2;
                m.Score1        = model.Score1;
                m.Score2        = model.Score2;

                if (model.Score1 > model.Score2)
                {
                    m.TeamVictory = model.Team1;
                }
                else
                {
                    m.TeamVictory = model.Team2;
                }

                MatchRepository rep = new MatchRepository();
                rep.Update(m);

                return(Request.CreateResponse(HttpStatusCode.OK, ""));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
        public async Task SearchForPlayerAndOpponent_FilterByGateway()
        {
            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent();
            var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent1.match.gateway = GateWay.America;
            matchFinishedEvent2.match.gateway = GateWay.Europe;

            matchFinishedEvent1.match.season = 1;
            matchFinishedEvent1.match.players[0].battleTag = "peter#123";
            matchFinishedEvent1.match.players[1].battleTag = "wolf#456";

            matchFinishedEvent2.match.season = 1;
            matchFinishedEvent2.match.players[0].battleTag = "peter#123";
            matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456";

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent1));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent2));

            var matches = await matchRepository.LoadFor("peter#123", null, GateWay.America);

            var count = await matchRepository.CountFor("peter#123", null, GateWay.America);

            Assert.AreEqual(1, count);
            Assert.AreEqual("peter#123", matches.Single().Teams.First().Players.Single().BattleTag);
        }
        public async Task SearchForPlayerAndOpponent_FilterBySeason(int season, string playerTwo)
        {
            var matchRepository = new MatchRepository(MongoClient);

            var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent();
            var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent1.match.season = 0;
            matchFinishedEvent1.match.players[0].battleTag = "peter#123";
            matchFinishedEvent1.match.players[1].battleTag = "wolf#456";

            matchFinishedEvent2.match.season = 1;
            matchFinishedEvent2.match.players[0].battleTag = "peter#123";
            matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456";

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent1));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent2));

            var matches = await matchRepository.LoadFor("peter#123", null, season : season);

            var count = await matchRepository.CountFor("peter#123", null, season : season);

            Assert.AreEqual(1, count);
            Assert.AreEqual("peter#123", matches.Single().Teams.First().Players.Single().BattleTag);
            Assert.AreEqual(playerTwo, matches.Single().Teams.Last().Players.Single().BattleTag);
        }
        public async Task SearchForPlayerAndOpponent_2v2_SameTeam()
        {
            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            var matchFinishedEvent1 = TestDtoHelper.CreateFake2v2AtEvent();
            var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent();

            matchFinishedEvent1.match.season = 1;
            matchFinishedEvent1.match.players[0].battleTag = "peter#123";
            matchFinishedEvent1.match.players[1].battleTag = "wolf#456";
            matchFinishedEvent1.match.players[2].battleTag = "LostTeam1#456";
            matchFinishedEvent1.match.players[3].battleTag = "LostTeam2#456";

            matchFinishedEvent2.match.season = 1;
            matchFinishedEvent2.match.players[0].battleTag = "peter#123";
            matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456";

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent1));

            await matchRepository.Insert(Matchup.Create(matchFinishedEvent2));

            var matches = await matchRepository.LoadFor("peter#123@10", "wolf#456");

            var count = await matchRepository.CountFor("peter#123@10", "wolf#456");

            Assert.AreEqual(0, count);
        }
Beispiel #28
0
 public List <MatchModel> ReturnAllMatches()
 {
     using (var repository = new MatchRepository())
     {
         return(repository.GetAllMatches().Select(x => x.ToModel()).ToList());
     }
 }
        public async Task Cache_AllOngoingMatches()
        {
            var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient));

            var storedEvent = TestDtoHelper.CreateFakeStartedEvent();
            await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(storedEvent));

            await Task.Delay(100);

            var result = await matchRepository.LoadOnGoingMatches(
                storedEvent.match.gameMode,
                storedEvent.match.gateway);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(storedEvent.match.id, result[0].MatchId);

            var notCachedEvent = TestDtoHelper.CreateFakeStartedEvent();
            await matchRepository.InsertOnGoingMatch(OnGoingMatchup.Create(notCachedEvent));

            await Task.Delay(100);

            var result2 = await matchRepository.LoadOnGoingMatches(
                notCachedEvent.match.gameMode,
                notCachedEvent.match.gateway);

            Assert.AreEqual(2, result2.Count);
            Assert.AreEqual(storedEvent.match.id, result[0].MatchId);
        }
Beispiel #30
0
 public void DeleteMatch(int matchId)
 {
     using (var repository = new MatchRepository())
     {
         repository.RemoveMatch(matchId);
     }
 }
        public async Task GetInProgressAsync_WithMatchInProgressAsHomeTeam_ReturnsMatchId()
        {
            // Arrange
            var matchId   = Guid.NewGuid();
            var userId    = Guid.NewGuid();
            var stubMatch = new ApplicationCore.Models.Match.Match
            {
                Id       = matchId,
                HomeTeam = new TeamDetails()
                {
                    UserId = userId
                },
                AwayTeam = new TeamDetails()
                {
                    UserId = Guid.NewGuid()
                },
                KickOff = DateTime.Now.AddMinutes(-10)
            };
            var stubMatchList = new List <ApplicationCore.Models.Match.Match>()
            {
                stubMatch
            };

            var dbContextStub = new InMemoryDataContext <ApplicationCore.Models.Match.Match>(stubMatchList);

            // Act
            var repository = new MatchRepository(dbContextStub);
            var result     = await repository.GetInProgressAsync(userId);

            //Assert
            Assert.Equal(stubMatch.Id, result);
        }
Beispiel #32
0
        public void GetByDate()
        {
            var repo = new MatchRepository();
            DateTime start = new DateTime(1990,1,1);
            DateTime end = new DateTime(2020, 1, 1);

            var r = repo.GetFromTimeInterval(start,end);
            Assert.AreEqual(1, 1);
        }
        public void MatchLoadTest()
        {
            const int countryId = 66;
            const int seriesId = 1000;
            var country = TestEntities.CreateCountry(countryId, "EnglishName", "CountryName");

            List<Series> series = TestEntities.CreateSeries(seriesId, country);
            var sessionFactory = SessionFactory.CreateSessionFactory(true);
            using (var session = sessionFactory.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    session.SaveOrUpdate(country);
                    foreach (var league in series)
                    {
                        session.SaveOrUpdate(league);
                    }
                    session.Transaction.Commit();
                }
            }

            var match1 = TestEntities.CreateMatchFullData(1000, country, 1050, 1051,
                                                          new List<int> {10000, 10001, 10002}, 3000, 1);

            var match2 = TestEntities.CreateMatchFullData(1001, country, 1052, 1053,
                                                          new List<int> {10003, 10004, 10005}, 3001, 1);

            series.First(s => s.HtSeriesId == seriesId).AddMatch(match1);
            series.First(s => s.HtSeriesId == seriesId).AddMatch(match2);

            var matchList = new List<Match> {match1, match2};

            using (var session = sessionFactory.OpenSession())
            {
                foreach (var match in matchList)
                {
                    using (session.BeginTransaction())
                    {
                        session.SaveOrUpdate(match);
                        session.Transaction.Commit();
                        session.Clear();
                    }
                }
            }

            var matchRepository = new MatchRepository(SessionManager.CurrentSession);
            var matches = matchRepository.GetAllMatchesForSeries(seriesId).ToList();
            Assert.True(matches.Count == 2);
            var firstMatch = matches.First(m => m.HtMatchId == 1000);
            Assert.True(firstMatch.MatchHomeTeam.Team.TeamId == 1050);
            Assert.True(firstMatch.MatchAwayTeam.Team.TeamId == 1051);
            Assert.True(firstMatch.MatchEvents.Count == 3);
            Assert.True(firstMatch.MatchScorers.Count == 3);
            Assert.True(firstMatch.MatchBookings.Count == 3);
        }
Beispiel #34
0
 public ActionResult Index()
 {
     MatchRepository _repository = new MatchRepository();
     UserRepository userRepository = new UserRepository();
     if(System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
     {
         IEnumerable<Match> tempFollowed =  _repository.GetMatchesOfFollowedTeams(userRepository.GetByName(System.Web.HttpContext.Current.User.Identity.Name).Id);
         ViewData["followedMatches"] = tempFollowed.OrderBy(o => o.Date).Reverse().ToList();
     }
     IEnumerable<Match> tempAll = cache.GetOrSet("home.allMatches", ()=>_repository.GetAll());
     ViewData["allMatches"] = tempAll.OrderBy(o => o.Date).Reverse().ToList();
     return View();
 }
        //TODO:: refactor ->TSQL
        private void CalculateLeague(DateTime date)
        {
            //Get day matches
            MatchRepository matchRepository = new MatchRepository();
            List<Match> matches = matchRepository.FindBy(m => m.MatchDate == date).ToList();
            Dictionary<int, TeamRoundStats> roundTeamStats = new Dictionary<int, TeamRoundStats>();

            //for each team count wins,loses etc
            foreach (Match match in matches)
            {
                if (!roundTeamStats.ContainsKey(match.Team1Id))
                    roundTeamStats.Add(match.Team1Id, new TeamRoundStats());

                if (!roundTeamStats.ContainsKey(match.Team2Id))
                    roundTeamStats.Add(match.Team2Id, new TeamRoundStats());

                if (match.Team1Score > match.Team2Score)
                {
                    roundTeamStats[match.Team1Id].Wins++;
                    roundTeamStats[match.Team2Id].Loses++;
                    roundTeamStats[match.Team1Id].Points += CalculateMatchPoints(match);
                }

                if (match.Team2Score > match.Team1Score)
                {
                    roundTeamStats[match.Team2Id].Wins++;
                    roundTeamStats[match.Team1Id].Loses++;
                    roundTeamStats[match.Team2Id].Points += CalculateMatchPoints(match);
                }
                roundTeamStats[match.Team1Id].GoalsPlus += match.Team1Score;
                roundTeamStats[match.Team1Id].GoalsMinus += match.Team2Score;

                roundTeamStats[match.Team2Id].GoalsPlus += match.Team2Score;
                roundTeamStats[match.Team2Id].GoalsMinus += match.Team1Score;
            }

            //save day stats to league table
            foreach (var row in roundTeamStats)
            {
                Leauge leauge = new Leauge();
                leauge.TeamId = row.Key;
                leauge.Points = row.Value.Points;
                leauge.Wins = row.Value.Wins;
                leauge.Loses = row.Value.Loses;
                leauge.GoalsPlus = row.Value.GoalsPlus;
                leauge.GoalsMinus = row.Value.GoalsMinus;
                leauge.MatchDate = date;
                leauge.InsertDate = DateTime.Now;
                _uow.LeaugeRepository.Add(leauge);
            }
        }
Beispiel #36
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //static void Main()
        //{
        //    ServiceBase[] ServicesToRun;
        //    ServicesToRun = new ServiceBase[] 
        //    { 
        //        new MatchParserService() 
        //    };
        //    ServiceBase.Run(ServicesToRun);
        //}
        static void Main(string[] args)
        {

            Dota2DbContext dbContext = new Dota2DbContext();
            IUnitOfWork unitOfWork = new UnitOfWork(dbContext);
            ITaskParserRepository taskRepository = new TaskParserRepository(dbContext);
            ISteamRepository onlineMatchRepository = new SteamRepository();
            IMatchRepository matchRepository = new MatchRepository(dbContext);
            ITasksParser taskParser = new TasksParser(taskRepository, onlineMatchRepository, matchRepository, unitOfWork);
#if DEBUG
            var service = new MatchParserService(taskParser);
            service.OnDebug();
            Thread.Sleep(Timeout.Infinite);

#else
            ServiceBase[] ServicesToRun; 
            ServicesToRun = new ServiceBase[]
            {
                new MatchParserService(taskParser),
            }; 
            ServiceBase.Run(ServicesToRun);
#endif
        }
Beispiel #37
0
 public void ContainsMatch()
 {
     var repo = new MatchRepository();
     var x = repo.GetById(1);
     Assert.IsTrue(repo.ContainsMatch(x));
 }
Beispiel #38
0
 public void AllMatches()
 {
     var repo = new MatchRepository();
     var x = repo.GetAll();
     Assert.IsTrue(x.Count != 0);
 }
        public void MatchUpdateTest()
        {
            const int countryId = 66;
            const int seriesId = 1000;
            var country = TestEntities.CreateCountry(countryId, "EnglishName", "CountryName");

            List<Series> series = TestEntities.CreateSeries(seriesId, country);
            var sessionFactory = SessionFactory.CreateSessionFactory(true);
            using (var session = sessionFactory.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    session.SaveOrUpdate(country);
                    foreach (var league in series)
                    {
                        session.SaveOrUpdate(league);
                    }
                    session.Transaction.Commit();
                }
            }
            var match1 = TestEntities.CreateMatchFullData(1000, country, 1050, 1051,
                                                          new List<int> {10000, 10001, 10002}, 3000, 1);

            var match2 = TestEntities.CreateMatchFullData(1001, country, 1052, 1053,
                                                          new List<int> {10003, 10004, 10005}, 3001, 1);

            series.First(s => s.HtSeriesId == seriesId).AddMatch(match1);
            series.First(s => s.HtSeriesId == seriesId).AddMatch(match2);

            var matchList = new List<Match> {match1, match2};

            using (var session = sessionFactory.OpenSession())
            {
                foreach (var match in matchList)
                {
                    using (session.BeginTransaction())
                    {
                        session.SaveOrUpdate(match);
                        session.Transaction.Commit();
                        session.Clear();
                    }
                }
            }

            var prodSession = SessionManager.CurrentSession;
            var matchRepository = new MatchRepository(prodSession);
            var matches = matchRepository.GetAllMatchesForSeries(seriesId);

            var firstMatch = matches.First(m => m.HtMatchId == 1000);
            var originalRound = firstMatch.MatchRound;

            firstMatch.MatchRound += 10;

            using (var transaction = prodSession.BeginTransaction())
            {
                matchRepository.SaveUpdate(firstMatch);
                transaction.Commit();
            }

            var updatedMatch = matchRepository.GetAllMatchesForSeries(seriesId).First(m => m.HtMatchId == 1000);
            Assert.True(updatedMatch.MatchRound != originalRound);
        }
        public void MatchSaveTest()
        {
            const int countryId = 66;
            var country = TestEntities.CreateCountry(countryId, "countryEnglishName", "CountryName");
            var series = TestEntities.CreateSeries(1000, country, "A Lyga");
            var sessionFactory = SessionFactory.CreateSessionFactory(true);
            using (var session = sessionFactory.OpenSession())
            {
                session.SaveOrUpdate(country);
                session.SaveOrUpdate(series);
                session.Flush();
            }

            var match1 = TestEntities.CreateMatchFullData(1000, country, 1050, 1051,
                                                          new List<int> {10000, 10001, 10002}, 3000, 1);

            var match2 = TestEntities.CreateMatchFullData(1001, country, 1052, 1053,
                                              new List<int> { 10003, 10004, 10005 }, 3001, 1);

            series.AddMatch(match1);
            series.AddMatch(match2);

            var matchList = new List<Match> { match1, match2 };

            var prodSession = SessionManager.CurrentSession;
            var matchRepository = new MatchRepository(prodSession);

            using (var transaction = prodSession.BeginTransaction())
            {
                matchList.ForEach(matchRepository.SaveUpdate);
                transaction.Commit();
            }
        }