public void PushesNotificationOnTournamentEndByStreamStopping() { var user = UserMapData.First(x => x.TwitchId.Equals("00")); var handlerMock = new Mock <PushNotificationHandler>(); System.Tournament.StartTournament(); TournamentModule.PushNotification += handlerMock.Object; System.Tournament.CurrentTournament.Entries.Add(new TournamentEntry(user.TwitchId, 100)); System.Tournament.EndTournament(false); handlerMock.Verify(x => x(null, It.IsAny <CommandResult>()), Times.Once); var result = handlerMock.Invocations[0].Arguments[1] as CommandResult; Assert.IsTrue(result.Messages.Any(x => x.Contains("offline"))); Assert.IsTrue(result.Messages.Any(x => x.Contains(user.Username, StringComparison.OrdinalIgnoreCase))); }
public async Task <IActionResult> Index() { var user = await _userManager.GetUserAsync(User); // Authenticated User if (user == null) { ViewBag.isNearMe = "false"; ViewBag.isAuthenticated = "false"; return(View()); } await _hubContext.Clients.All.SendAsync("Notify", $"Home page loaded at: {DateTime.Now}"); var users = _userManager.Users.ToList(); // All Users var userAddress = _db.UserAddresses.FirstOrDefault(uad => uad.UserId == user.Id); AddressComponent userCounty = null; Location userLocation = null; List <UserMapData> allUserMapData = new List <UserMapData>(); ViewBag.googleApiKey = _applicationSettings.GoogleApiKey; if (userAddress != null) { string userAddressQuery = ""; userAddressQuery = GetAddressQuery(userAddress); if (userAddressQuery != "") { userLocation = GetCoords(userAddressQuery, ViewBag.googleApiKey); userCounty = GetCounty(userAddressQuery, ViewBag.googleApiKey); List <Location> positions = new List <Location>(); Double distance = 0; foreach (var member in users) { // Don't load personal pins if (member.Id == user.Id) { continue; } string memberAddressQuery = ""; var memberAddress = _db.UserAddresses.FirstOrDefault(uad => uad.UserId == member.Id); var pins = _db.UserPins.Where(uid => uid.UserId == member.Id).ToList(); if (memberAddress != null && (pins != null && pins.Count > 0)) { memberAddressQuery = GetAddressQuery(memberAddress); if (memberAddressQuery != "") { Location memberLocation = GetCoords(memberAddressQuery, ViewBag.googleApiKey); distance = HaversineDistance(userLocation, memberLocation); positions.Add(memberLocation); if (positions.Count > 1) { foreach (var position in positions) { var latIsEqual = Math.Abs(position.lat - memberLocation.lat) < Double.Epsilon; var lngIsEqual = Math.Abs(position.lng - memberLocation.lng) < Double.Epsilon; if (latIsEqual && lngIsEqual) { Location locOffset = GetOffset(memberLocation.lat, memberLocation.lng); memberLocation = new Location { lat = locOffset.lat, lng = locOffset.lng }; } } } if (distance < 50) { Location location = new Location { lat = memberLocation.lat, lng = memberLocation.lng }; // Need to ecnrypt UserId UserMapData userMapData = new UserMapData { UserId = member.Id, UserName = member.UserName, Location = location, LocationColor = GetLocationColor(pins) }; allUserMapData.Add(userMapData); } } } } } } if (allUserMapData.Count == 0) { ViewBag.isNearMe = "false"; ViewBag.noPins = "true"; return(View()); } ViewBag.userCounty = userCounty.long_name; ViewBag.userLocation = userLocation; ViewBag.isNearMe = "true"; return(View(allUserMapData)); }