public MatchServiceTest()
 {
     services = new ServicesBuilder();
     _mocker  = new AutoMocker();
     services.Build(_mocker);
     _pavlovServerService  = _mocker.CreateInstance <PavlovServerService>();
     _sshServerSerivce     = _mocker.CreateInstance <SshServerSerivce>();
     _teamService          = _mocker.CreateInstance <TeamService>();
     _matchService         = _mocker.CreateInstance <MatchService>();
     _steamIdentityService = _mocker.CreateInstance <SteamIdentityService>();
     _matchSelectedSteamIdentitiesService     = _mocker.CreateInstance <MatchSelectedSteamIdentitiesService>();
     _matchSelectedTeamSteamIdentitiesService =
         _mocker.CreateInstance <MatchSelectedTeamSteamIdentitiesService>();
     _userManager = services.GetUserManager();
 }
 public MatchMakingController(UserService userService,
                              MatchService matchService,
                              PavlovServerService pavlovServerService, TeamService teamService,
                              MatchSelectedSteamIdentitiesService matchSelectedSteamIdentities,
                              SteamIdentityService steamIdentityService,
                              MapsService mapsService,
                              PublicViewListsService publicViewListsService,
                              TeamSelectedSteamIdentityService teamSelectedSteamIdentityService,
                              MatchSelectedTeamSteamIdentitiesService matchSelectedTeamSteamIdentitiesService)
 {
     _userservice          = userService;
     _matchService         = matchService;
     _pavlovServerService  = pavlovServerService;
     _teamService          = teamService;
     _steamIdentityService = steamIdentityService;
     _matchSelectedSteamIdentitiesService     = matchSelectedSteamIdentities;
     _matchSelectedTeamSteamIdentitiesService = matchSelectedTeamSteamIdentitiesService;
     _teamSelectedSteamIdentityService        = teamSelectedSteamIdentityService;
     _mapsService            = mapsService;
     _publicViewListsService = publicViewListsService;
 }
        public static Match CreateMatch(MatchService matchService, PavlovServer pavlovServer, bool teamMatch,
                                        TeamService teamService, SteamIdentityService steamIdentityService, UserManager <LiteDbUser> userManager,
                                        MatchSelectedSteamIdentitiesService matchSelectedSteamIdentitiesService,
                                        MatchSelectedTeamSteamIdentitiesService matchSelectedTeamSteamIdentitiesService)
        {
            var user = ServerSelectedModServiceTests.InsertUserAndSteamIdentity(steamIdentityService, userManager,
                                                                                "test");
            var user2 = ServerSelectedModServiceTests.InsertUserAndSteamIdentity(steamIdentityService, userManager,
                                                                                 "test2", "2");
            var steamIdentity1 = steamIdentityService.FindOne(user.Id).GetAwaiter().GetResult();
            var steamIdentity2 = steamIdentityService.FindOne(user2.Id).GetAwaiter().GetResult();
            var team1          = TeamSelectedSteamIdentityServiceTest.CreateTeam(teamService);
            var team2          = TeamSelectedSteamIdentityServiceTest.CreateTeam(teamService, "test2");

            if (teamMatch)
            {
                matchService.Upsert(new Match
                {
                    Name         = "Test",
                    MapId        = "null",
                    GameMode     = "TDM",
                    ForceStart   = false,
                    ForceSop     = false,
                    TimeLimit    = 40,
                    PlayerSlots  = 10,
                    Team0        = team1,
                    Team1        = team2,
                    PavlovServer = pavlovServer,
                    Status       = Status.Preparing
                }).GetAwaiter().GetResult();
            }
            else
            {
                matchService.Upsert(new Match
                {
                    Name         = "Test",
                    MapId        = "null",
                    GameMode     = "GUN",
                    ForceStart   = false,
                    ForceSop     = false,
                    TimeLimit    = 40,
                    PlayerSlots  = 10,
                    Team0        = team1,
                    PavlovServer = pavlovServer,
                    Status       = Status.Preparing
                }).GetAwaiter().GetResult();
            }


            var match = matchService.FindAll().GetAwaiter().GetResult().FirstOrDefault();

            if (teamMatch)
            {
                match.MatchTeam0SelectedSteamIdentities = new List <MatchTeamSelectedSteamIdentity>
                {
                    new()
                    {
                        SteamIdentityId = steamIdentity1.Id,
                        SteamIdentity   = steamIdentity1,
                        matchId         = match.Id,
                        TeamId          = 0
                    }
                };
                match.MatchTeam1SelectedSteamIdentities = new List <MatchTeamSelectedSteamIdentity>
                {
                    new()
                    {
                        SteamIdentityId = steamIdentity2.Id,
                        SteamIdentity   = steamIdentity2,
                        matchId         = match.Id,
                        TeamId          = 1
                    }
                };
                matchSelectedTeamSteamIdentitiesService.Upsert(match.MatchTeam0SelectedSteamIdentities, match.Id, 0)
                .GetAwaiter().GetResult();
                matchSelectedTeamSteamIdentitiesService.Upsert(match.MatchTeam1SelectedSteamIdentities, match.Id, 1)
                .GetAwaiter().GetResult();
            }
            else
            {
                match.MatchSelectedSteamIdentities = new List <MatchSelectedSteamIdentity>
                {
                    new()
                    {
                        SteamIdentityId = steamIdentity1.Id,
                        SteamIdentity   = steamIdentity1,
                        matchId         = match.Id
                    },
                    new()
                    {
                        SteamIdentityId = steamIdentity2.Id,
                        SteamIdentity   = steamIdentity2,
                        matchId         = match.Id
                    }
                };

                matchSelectedSteamIdentitiesService.Upsert(match.MatchSelectedSteamIdentities, match.Id).GetAwaiter()
                .GetResult();
            }

            matchService.Upsert(match);
            return(match);
        }