public async void TestForCreateVendor() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LeagueControllerCreateVendor") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); VendorController vendorController = new VendorController(logic); var vendorDto = new CreateVendorDto { VendorInfo = "chicken tenders", VendorName = "bojangles" }; var createVendor = await vendorController.CreateVendor(vendorDto); Assert.IsAssignableFrom <Vendor>((createVendor as OkObjectResult).Value); var createVendor2 = await vendorController.CreateVendor(vendorDto); Assert.IsAssignableFrom <string>((createVendor2 as ConflictObjectResult).Value); } }
public async void TestForCreateTeam() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3TeamControllerCreateTeam") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); TeamController teamController = new TeamController(logic); var team = new Team { TeamID = Guid.NewGuid(), CarpoolID = Guid.NewGuid(), LeagueID = Guid.NewGuid(), StatLineID = Guid.NewGuid(), Name = "Broncos", Wins = 2, Losses = 1 }; //var createTeam = await teamController.CreateTeam(team.Name); //Assert.IsAssignableFrom<Team>((createTeam as OkObjectResult).Value); //var createTeam2 = await teamController.CreateTeam(team.Name); //Assert.IsAssignableFrom<string>((createTeam2 as ConflictObjectResult).Value); } }
public async void TestForGetLeagueById() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LeagueControllerGetLeagueById") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); LeagueController leagueController = new LeagueController(logic); var league = new League { LeagueID = Guid.NewGuid(), LeagueName = "louge", SportID = 51 }; var getLeague = await leagueController.GetLeagueById(league.LeagueID); Assert.IsAssignableFrom <string>((getLeague as NotFoundObjectResult).Value); r.Leagues.Add(league); await r.CommitSave(); var getLeague2 = await leagueController.GetLeagueById(league.LeagueID); Assert.IsAssignableFrom <League>((getLeague2 as OkObjectResult).Value); } }
public async void TestForDeleteLeague() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicDeleteLeague") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var league = new League { LeagueID = Guid.NewGuid(), SportID = 29, LeagueName = "football" }; r.Leagues.Add(league); await r.CommitSave(); var getLeague = await logic.GetLeagueById(league.LeagueID); Assert.NotNull(getLeague); await logic.DeleteLeague(league); var getLeague2 = await logic.GetLeagueById(league.LeagueID); Assert.Null(getLeague2); } }
public DataDragonController( IWebHostEnvironment env, LeagueContext context) { this.env = env; this.context = context; }
public async void TestForAddLeague() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicAddLeague") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var sport = new Sport { SportID = 35, SportName = "basketball" }; r.Sports.Add(sport); await r.CommitSave(); var leagueDto = new CreateLeagueDto { LeagueName = "sports", SportName = sport.SportName }; var newLeague = await logic.AddLeague(leagueDto); Assert.Contains <League>(newLeague, context.Leagues); } }
public async void TestForGetTeamByName() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicGetTeamByName") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var team = new Team { TeamID = Guid.NewGuid(), CarpoolID = Guid.NewGuid(), LeagueID = Guid.NewGuid(), StatLineID = Guid.NewGuid(), Name = "Broncos", Wins = 2, Losses = 1 }; r.Teams.Add(team); await r.CommitSave(); var listOfTeams = await logic.GetTeamByName(team.Name); Assert.True(listOfTeams.Wins.Equals(2)); } }
public async void TestForGetVendors() { //for coverage var dbContext = new LeagueContext(); var logicClass = new Logic(); var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicGetVendors") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var vendor = new Vendor { VendorID = Guid.NewGuid(), VendorInfo = "hotdog", VendorName = "weinerhut" }; r.Vendors.Add(vendor); await r.CommitSave(); var listOfVendors = await logic.GetVendors(); var convertedList = (List <Vendor>)listOfVendors; Assert.NotNull(listOfVendors); Assert.Equal("hotdog", convertedList[0].VendorInfo); Assert.Equal("weinerhut", convertedList[0].VendorName); } }
public async void TestForVendorExists() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicVendorExists") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var vendor = new Vendor { VendorID = Guid.NewGuid(), VendorInfo = "hotdog", VendorName = "weinerhut" }; var vendorExists = await logic.VendorExists(vendor.VendorName); Assert.False(vendorExists); r.Vendors.Add(vendor); await r.CommitSave(); var vendorExists2 = await logic.VendorExists(vendor.VendorName); Assert.True(vendorExists2); } }
public async void TestForDeleteVendor() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicDeleteVendor") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var vendor = new Vendor { VendorID = Guid.NewGuid(), VendorInfo = "hotdog", VendorName = "weinerhut" }; r.Vendors.Add(vendor); await r.CommitSave(); var getVendor = await logic.GetVendorById(vendor.VendorID); Assert.Equal("hotdog", getVendor.VendorInfo); Assert.Equal("weinerhut", getVendor.VendorName); bool deleteVendor = await logic.DeleteVendor(vendor); Assert.True(deleteVendor); } }
public LeagueController(LeagueContext context, SportContext sportContext, TeamContext teamContext, MatchContext matchContext) { _context = context; _sportContext = sportContext; _teamContext = teamContext; _matchContext = matchContext; }
public static TEntity Query <TEntity>(Func <LeagueContext, TEntity> query) { using (var context = new LeagueContext(options)) { return(query(context)); } }
public async void TestForSportExists() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicSportExists") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var sport = new Sport { SportID = 35, SportName = "basketball" }; var sportExists = await logic.SportExists(sport.SportName); Assert.False(sportExists); r.Sports.Add(sport); await r.CommitSave(); var sportExists2 = await logic.SportExists(sport.SportName); Assert.True(sportExists2); } }
public async void TestForGetVendorById() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3VendorControllerGetVendorById") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); VendorController vendorController = new VendorController(logic); var vendor = new Vendor { VendorID = Guid.NewGuid(), VendorInfo = "chicken tenders", VendorName = "bojangles" }; var getVendor = await vendorController.GetVendorById(vendor.VendorID); Assert.IsAssignableFrom <string>((getVendor as NotFoundObjectResult).Value); r.Vendors.Add(vendor); await r.CommitSave(); var getVendor2 = await vendorController.GetVendorById(vendor.VendorID); Assert.IsAssignableFrom <Vendor>((getVendor2 as OkObjectResult).Value); } }
public async void TestForGetVendorByName() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3GetVendorByName") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); var vendor = new Vendor { VendorID = Guid.NewGuid(), VendorInfo = "hotdog", VendorName = "weinerhut" }; r.Vendors.Add(vendor); await r.CommitSave(); var getTeam = await r.GetVendorByName(vendor.VendorName); Assert.True(getTeam.VendorInfo.Equals("hotdog")); } }
public async void TestForLeagueExistsByName() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3LogicLeagueExistsName") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); var league = new League { LeagueID = Guid.NewGuid(), SportID = 35, LeagueName = "sports" }; var leagueExists = await logic.LeagueExists(league.LeagueName); Assert.False(leagueExists); r.Leagues.Add(league); await r.CommitSave(); var leagueExists2 = await logic.LeagueExists(league.LeagueName); Assert.True(leagueExists2); } }
public async Task Load(SeasonModel season) { this.season = season; if (season == null) { return; } try { IsLoading = true; var seasonStatisticSets = await LeagueContext.GetModelsAsync <SeasonStatisticSetModel>(season.SeasonStatisticSets.Select(x => x.ModelId)); var leagueStatisticSets = await LeagueContext.GetModelsAsync <LeagueStatisticSetModel>(); var loadedStatisticSets = seasonStatisticSets.Cast <StatisticSetModel>().Concat(leagueStatisticSets); statisticiSets.UpdateSource(loadedStatisticSets); } catch (Exception e) { GlobalSettings.LogError(e); } finally { IsLoading = false; } }
public async void TestForGetTeamsByLeague() { var options = new DbContextOptionsBuilder <LeagueContext>() .UseInMemoryDatabase(databaseName: "p3GetTeamsByLeague") .Options; using (var context = new LeagueContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); var team = new Team { TeamID = Guid.NewGuid(), CarpoolID = Guid.NewGuid(), LeagueID = Guid.NewGuid(), StatLineID = Guid.NewGuid(), Name = "Broncos", Wins = 2, Losses = 1 }; r.Teams.Add(team); await r.CommitSave(); var getTeam = await r.GetTeamsByLeague(team.LeagueID); var convertedList = (List <Team>)getTeam; Assert.True(convertedList[0].Wins.Equals(2)); } }
private async Task <(string clanTag, League league, string race)> GetClanTagAndLeagueAndRaceAsync( Profile profile, OAuthCreatingTicketContext context, LeagueContext leagueContext ) { var request = new HttpRequestMessage( HttpMethod.Get, "https://eu.api.blizzard.com/sc2/profile/" + profile.RegionId + "/" + profile.RealmId + "/" + profile.Id + "?access_token=" + context.AccessToken ); var response = await GetResponseAsync(request, context); var pr = JObject.Parse(response); string clanTag = (string)pr["summary"]["clanTag"]; League league = leagueContext.Leagues.FirstOrDefault(l => l.Name == (string)pr["career"]["current1v1LeagueName"]); if (league == null) { league = leagueContext.Leagues.First(l => l.Name == (string)pr["career"]["best1v1Finish"]["leagueName"]); } int terranParameter = int.Parse((string)pr["career"]["terranWins"]); int zergParameter = int.Parse((string)pr["career"]["zergWins"]); int protossParameter = int.Parse((string)pr["career"]["protossWins"]); if (terranParameter == 0 & zergParameter == 0 && protossParameter == 0) { terranParameter = int.Parse((string)pr["swarmLevels"][RaceConstants.TERRAN]["level"]); zergParameter = int.Parse((string)pr["swarmLevels"][RaceConstants.ZERG]["level"]); protossParameter = int.Parse((string)pr["swarmLevels"][RaceConstants.PROTOSS]["level"]); } string race; if (terranParameter > zergParameter && terranParameter > protossParameter) { race = RaceConstants.TERRAN; } else if (zergParameter > terranParameter && zergParameter > protossParameter) { race = RaceConstants.ZERG; } else if (protossParameter > terranParameter && protossParameter > zergParameter) { race = RaceConstants.PROTOSS; } else { race = RaceConstants.RANDOM; } return(clanTag, league, race); }
public LeagueService(IServiceScopeFactory scopeFactory, IAlarmClock alarmClock) { _serviceScope = scopeFactory.CreateScope(); _alarmClock = alarmClock; _dateTimeService = _serviceScope.ServiceProvider.GetRequiredService <IDateTimeService>(); _seasonService = _serviceScope.ServiceProvider.GetRequiredService <ISeasonService>(); _leagueContext = _serviceScope.ServiceProvider.GetRequiredService <LeagueContext>(); }
public UnitOfWork(LeagueContext dbContext) { _dbContext = dbContext; Competitions = new EntityRepository <Competition>(dbContext); Teams = new TeamRepository(dbContext); Players = new PlayerRepository(dbContext); TeamByCompetition = new EntityRepository <TeamByCompetition>(dbContext); }
private static void SeedMatchesResults(LeagueContext leagueContext, IEnumerable <Match> matches) { Randomizer randomizer = new Randomizer(); foreach (Match match in matches) { SeedMatchResult(leagueContext, randomizer, match); } }
private static void SeedRegistration(LeagueContext leagueContext, ISeasonService seasonService) { IEnumerable <int> userIds = leagueContext.Users.Select(u => u.Id); foreach (int userId in userIds) { seasonService.Register(userId); } }
public PlayoffsRoundService( LeagueContext leagueContext, IGroupsService groupsService, IMatchService matchService ) { _leagueContext = leagueContext; _groupsService = groupsService; _matchService = matchService; }
public HomeController( LeagueContext leagueContext, ISeasonService seasonService, IMatchesStatisticsService matchesStatisticsService ) { _leagueContext = leagueContext; _seasonService = seasonService; _matchesStatisticsService = matchesStatisticsService; }
private async Task CreateOAuthTicket(OAuthCreatingTicketContext context) { var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken); var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted); response.EnsureSuccessStatusCode(); context.HttpContext.Response.Cookies.Append("token", context.AccessToken); var user = JObject.Parse(await response.Content.ReadAsStringAsync()); context.RunClaimActions(user); LeagueContext leagueContext = context.HttpContext.RequestServices.GetService <LeagueContext>(); int id = int.Parse((string)user["id"]); User dbUser = leagueContext.Users.Find(id); Role role = null; if (dbUser == null) { role = leagueContext.Roles.First(r => r.Name == RoleConstants.User); dbUser = new User() { Id = id, BattleTag = context.Identity.Name, Role = role }; leagueContext.Users.Add(dbUser); leagueContext.SaveChanges(); } if (dbUser.ProfileId == null) { Profile profile = await GetFullProfileAsync(dbUser, context, leagueContext); if (profile != null) { leagueContext.Profiles.Add(profile); dbUser.ProfileId = profile.Id; leagueContext.Attach(dbUser); leagueContext.Entry(dbUser).Property(u => u.ProfileId).IsModified = true; leagueContext.SaveChanges(); SetHasProfileClaimAsTrue(context); } } else { SetHasProfileClaimAsTrue(context); } role = role ?? leagueContext.Roles.Find(dbUser.RoleId); context.Identity.AddClaim(new Claim(ClaimsIdentity.DefaultRoleClaimType, role.Name)); }
public GroupServiceTests() { var optionsBuilder = new DbContextOptionsBuilder <LeagueContext>(); optionsBuilder.UseInMemoryDatabase("StarCraft2League"); LeagueContext dbContext = new LeagueContext(optionsBuilder.Options); Mock <IGroupRoundService> groupRoundServiceMock = new Mock <IGroupRoundService>(); Mock <IMatchService> matchServiceMock = new Mock <IMatchService>(); _groupService = new GroupsService(dbContext, groupRoundServiceMock.Object, matchServiceMock.Object); }
public static void Update(params Entity[] entities) { using (var context = new LeagueContext(options)) { foreach (var entity in entities) { context.Update(entity); } context.SaveChanges(); } }
public void CallGetMethod_NoParams_DoesNotReturnNull() { var options = InMemorySQLite.CreateOptions <LeagueContext>(); using (var context = new LeagueContext(options)) { context.Database.EnsureCreated(); var controller = new SummonersController(context); var result = controller.Get(); Assert.NotNull(result); } }
public void CallGetMethod_ParamIsInvalidSummonerName_ThrowsArgumentNullException( string summonerName) { var options = InMemorySQLite.CreateOptions <LeagueContext>(); using (var context = new LeagueContext(options)) { context.Database.EnsureCreated(); var controller = new SummonersController(context); Assert.Throws <ArgumentException>(() => controller.GetDetails(summonerName)); } }