public void OnMatchList(bool success, string extendedInfo, List <MatchInfoSnapshot> matchList) { status.text = ""; if (!success || matchList == null) { status.text = "Couldn't find any matches. Try again!"; return; } foreach (MatchInfoSnapshot match in matchList) { GameObject _matchListItemGO = Instantiate(matchListItemPrefab); _matchListItemGO.transform.SetParent(matchListParent); MatchListItem _matchListItem = _matchListItemGO.GetComponent <MatchListItem>(); if (_matchListItem != null) { _matchListItem.Setup(match, JoinMatch); } // as well as setting up a callback function that will join the game. //matchList.Add(_matchListItemGO); } if (matchList.Count == 0) { status.text = "No matches at the moment."; } }
public async Task ShouldReturnNumberOfConnections() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem { Url = Guid.NewGuid().ToString(), NumberOfConnections = 0 }; matchListItemService.AddMatchListItem(matchListItem); int numberOfConnectionsToAdd = new Random().Next(0, 10); for (int i = 0; i < numberOfConnectionsToAdd; i++) { matchListItemService.AddConnection(matchListItem.Url); } var handler = new GetNumberOfConnectionsByUrlQueryHandler(matchListItemService); //Act int numberOfConnections = await handler.Handle(new GetNumberOfConnectionsByUrlQuery { Url = matchListItem.Url }, CancellationToken.None); //Assert numberOfConnections.Should().Be(numberOfConnectionsToAdd); }
public async Task ShouldReturnMatchListItems() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem { Id = Guid.NewGuid().ToString(), Url = Guid.NewGuid().ToString(), Name = "Game", Password = "******", }; matchListItemService.AddMatchListItem(matchListItem); var handler = new GetAllMatchListItemsQueryHandler(matchListItemService); //Act List <MatchListItem> matchListItems = await handler.Handle(new GetAllMatchListItemsQuery(), CancellationToken.None); //Assert matchListItems.Should().NotBeNull(); matchListItems.Should().HaveCount(1); matchListItems.First().Should().Be(matchListItem); }
private static MatchListItemDto ToMatchDto(MatchListItem matchItem, MatchListEventType eventType) { return(new MatchListItemDto { Id = matchItem.MatchId, Name = $"{matchItem.HomeTeam.Name} - {matchItem.AwayTeam.Name}", Minute = matchItem.Minute, MatchPeriod = (int)matchItem.MatchPeriod, MatchListEventType = eventType, HomeTeam = new TeamDto { Id = matchItem.HomeTeam.Id, Name = matchItem.HomeTeam.Name, Players = new List <MatchPlayerDto>() }, AwayTeam = new TeamDto { Id = matchItem.AwayTeam.Id, Name = matchItem.AwayTeam.Name, Players = new List <MatchPlayerDto>() }, Goals = new ScoreDto { Home = matchItem.Goals.Home, Away = matchItem.Goals.Away } }); }
public async Task ShouldAddConnection() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); int startNumberOfConnections = new Random().Next(); MatchListItem matchListItem = new MatchListItem { Id = Guid.NewGuid().ToString(), Url = Guid.NewGuid().ToString(), Name = "Game", Password = "******", NumberOfConnections = startNumberOfConnections }; matchListItemService.AddMatchListItem(matchListItem); var handler = new AddConnectionCommandHandler(matchListItemService); //Act await handler.Handle(new AddConnectionCommand { Url = matchListItem.Url }, CancellationToken.None); //Assert int numberOfConnections = matchListItemService.GetMatchById(matchListItem.Id).NumberOfConnections; int expectedNumberOfConnections = startNumberOfConnections + 1; numberOfConnections.Should().Be(expectedNumberOfConnections); }
public void AddConnection(string url) { MatchListItem match = _matches.FirstOrDefault(x => x.Url == url); if (match is not null) { match.NumberOfConnections++; } }
public void RemoveConnection(string url) { MatchListItem match = _matches.FirstOrDefault(x => x.Url == url); if (match != null) { match.NumberOfConnections--; } }
public void RemoveMatchByUrl(string url) { MatchListItem match = _matches.FirstOrDefault(x => x.Url == url); if (match != null) { _matches.Remove(match); } }
public async Task CreateMatch(MatchListItem match) { List <MatchListItem> matchListItems = await _mediator.Send(new GetAllMatchListItemsQuery()); bool matchDoesNotExist = matchListItems.FirstOrDefault(x => x.Id == match.Id) == null; if (matchDoesNotExist) { _mediator.Send(new AddMatchListItemCommand { MatchListItem = match }); } }
public int GetNumberOfConnections(string url) { int o_numberOfConnections = 0; MatchListItem match = _matches.FirstOrDefault(x => x.Url == url); if (match != null) { o_numberOfConnections = match.NumberOfConnections; } return(o_numberOfConnections); }
public async Task TryJoinMatch(string id, string password) { MatchListItem match = await _mediator.Send(new GetMatchByIdQuery { Id = id }); bool isPasswordCorrect = match.Password == password; if (isPasswordCorrect) { await Clients.Caller.SendAsync("RecieveMatchUrl", match.Url); return; } await Clients.Caller.SendAsync("SendNotificationAboutIncorrectPassword"); }
public async Task SholdThrowError_IfMatchListItemIsInvalid() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem(); var handler = new AddMatchListItemCommandHandler(matchListItemService); //Assert Assert.ThrowsAsync <ValidationException>(async() => { await handler.Handle(new AddMatchListItemCommand { MatchListItem = matchListItem }, CancellationToken.None); }); }
public async Task ShouldAddMatchListItem() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem(); var handler = new AddMatchListItemCommandHandler(matchListItemService); //Act await handler.Handle(new AddMatchListItemCommand { MatchListItem = matchListItem }, CancellationToken.None); //Assert MatchListItem result = matchListItemService.GetMatchById(matchListItem.Id); result.Should().NotBeNull(); result.Should().Be(matchListItem); }
public async Task AddMatch(string matchId, TeamDto homeTeam, TeamDto awayTeam) { var matchStreamId = Guid.Parse(matchId); var streamProvider = GetStreamProvider("SMSProvider"); var matchStream = streamProvider.GetStream <MatchEventDto>(matchStreamId, "Matches"); var matchItem = _matches[matchId] = new MatchListItem(matchId, new Identifier { Id = homeTeam.Id, Name = homeTeam.Name }, new Identifier { Id = awayTeam.Id, Name = awayTeam.Name }); await _matchListStream.OnNextAsync(ToMatchDto(matchItem, MatchListEventType.MatchAdded)); var subscriptionHandle = await matchStream.SubscribeAsync(OnMatchEvent); _matchStreams[matchStreamId] = subscriptionHandle; }
public async Task ShouldRemoveMatchListItem() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem { Url = Guid.NewGuid().ToString() }; var handler = new RemoveMatchByUrlCommandHandler(matchListItemService); //Act await handler.Handle(new RemoveMatchByUrlCommand { Url = matchListItem.Url }, CancellationToken.None); //Assert MatchListItem result = matchListItemService.GetMatchById(matchListItem.Id); result.Should().BeNull(); }
public async Task ShouldReturnMatchListItemById() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem { Id = Guid.NewGuid().ToString() }; matchListItemService.AddMatchListItem(matchListItem); var handler = new GetMatchByIdQueryHandler(matchListItemService); //Act MatchListItem result = await handler.Handle(new GetMatchByIdQuery { Id = matchListItem.Id }, CancellationToken.None); //Assert result.Should().NotBeNull(); result.Id.Should().Be(matchListItem.Id); }
private void OnMatchListReceived(bool success, string extendedinfo, List <MatchInfoSnapshot> matchInfoList) { if (!success) { Status = "Match list could not be fetched"; } else if (matchInfoList == null || matchInfoList.Count == 0) { Status = "No matches found"; } else { Status = "Matches found"; foreach (MatchInfoSnapshot matchInfoSnapshot in matchInfoList) { MatchListItem matchButton = Instantiate(matchButtonPrefab, matchListParent); matchButton.SetMatchInfo(matchInfoSnapshot, JoinMatch); matchList.Add(matchButton); } } }
public async Task ShouldAddMatchListItem() { //Arrange IMatchListItemsService matchListItemService = new MatchListItemsService(); MatchListItem matchListItem = new MatchListItem { Id = Guid.NewGuid().ToString(), Url = Guid.NewGuid().ToString(), Name = "Game", Password = "******", }; var handler = new AddMatchListItemCommandHandler(matchListItemService); //Act await handler.Handle(new AddMatchListItemCommand { MatchListItem = matchListItem }, CancellationToken.None); //Assert MatchListItem result = matchListItemService.GetMatchById(matchListItem.Id); result.Should().NotBeNull(); result.Should().Be(matchListItem); }
public void AddMatchListItem(MatchListItem match) { _matches.Add(match); }
public void AddMatchListItem(MatchListItem match) { new MatchListItemValidator().ValidateAndThrow(match); _matches.Add(match); }
private void MatchClicked(TableView sender, MatchListItem matchListItem) { MatchSelected?.Invoke(matchListItem.match); }