Esempio n. 1
0
        public async Task Should_add_new_match()
        {
            var matchResults = new MatchResultsDto
            {
                Map = "Hello World",
                GameMode = "DM",
                FragLimit = 10,
                TimeLimit = 10,
                TimeElapsed = 1.2368,
                Scoreboard =
                    new List<ScoreDto>
                    {
                        new ScoreDto {Name = "Player 1", Kills = 1, Frags = 1, Deaths = 0},
                        new ScoreDto {Name = "Player 2", Kills = 0, Frags = 0, Deaths = 1}
                    }
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.Matches.Count());
            Assert.AreEqual(1, _context.GameModes.Count());
            Assert.AreEqual(1, _context.Maps.Count());
            Assert.AreEqual(2, _context.Players.Count());
            Assert.AreEqual(1.2368, _context.Matches.First().TimeElapsed);
        }
Esempio n. 2
0
        public async Task Should_add_new_players_when_does_not_exist()
        {
            var matchResults = new MatchResultsDto
            {
                Scoreboard = new List<ScoreDto> {new ScoreDto {Name = "TAZ"}}
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.Players.Count());
            Assert.AreEqual("TAZ", _context.Players.First().Name);
        }
Esempio n. 3
0
        public async Task Should_add_new_map_when_does_not_exists()
        {
            var matchResults = new MatchResultsDto
            {
                Map = "King of the kill",
                Scoreboard = new List<ScoreDto>()
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.Maps.Count());
        }
Esempio n. 4
0
        public async Task Should_add_new_gamemode_when_does_not_exists()
        {
            var matchResults = new MatchResultsDto
            {
                GameMode = "DM",
                Scoreboard = new List<ScoreDto>()
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.GameModes.Count());
        }
Esempio n. 5
0
        public async Task Should_use_existing_players()
        {
            _context.Players.Add(new Player {Name = "TAZ"});
            _context.SaveChanges();
            var matchResults = new MatchResultsDto
            {
                Scoreboard = new List<ScoreDto> {new ScoreDto {Name = "tAz"}}
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.Players.Count());
            Assert.AreEqual("TAZ", _context.Matches.First().ScoreBoard.First().Player.Name);
        }
Esempio n. 6
0
        public async Task Should_use_existing_map()
        {
            _context.Maps.Add(new Map {Name = "King of the kill"});
            _context.SaveChanges();
            var matchResults = new MatchResultsDto
            {
                Map = "King of THE kill",
                Scoreboard = new List<ScoreDto>()
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.Maps.Count());
            Assert.AreEqual("King of the kill", _context.Matches.First().Map.Name);
        }
Esempio n. 7
0
        public async Task Should_use_existing_gamemode()
        {
            _context.GameModes.Add(new GameMode {Name = "DM"});
            _context.SaveChanges();
            var matchResults = new MatchResultsDto
            {
                GameMode = "dm",
                Scoreboard = new List<ScoreDto>()
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(1, _context.GameModes.Count());
            Assert.AreEqual("DM", _context.Matches.First().GameMode.Name);
        }
Esempio n. 8
0
        public async Task Should_calculate_scoreboard_percent_for_each_score()
        {
            var matchResults = new MatchResultsDto
            {
                Scoreboard = new List<ScoreDto>
                {
                    new ScoreDto {Name = "Player 1"},
                    new ScoreDto {Name = "Player 2"},
                    new ScoreDto {Name = "Player 3"}
                }
            };

            await _handler.Handle(new PutMatchResultsCommand("LOCALhost", DateTime.UtcNow, matchResults));

            Assert.AreEqual(new List<double> {100, 50, 0}, _context.Scores.Select(x => x.ScoreboardPercent));
        }
Esempio n. 9
0
        public async Task GetMatchResults_should_return_match_results_when_match_exists()
        {
            var matchResultsDto = new MatchResultsDto {
                Scoreboard = new List <ScoreDto> {
                    new ScoreDto()
                }
            };

            A.CallTo(() => _fakeMediator.Send(A <GetMatchResultsQuery> ._, A <CancellationToken> ._)).Returns(matchResultsDto);

            var result =
                await _matchesController.GetMatchResults(string.Empty, new DateTimeOffset(DateTime.UtcNow)) as
                OkNegotiatedContentResult <MatchResultsDto>;

            Assert.NotNull(result);
            Assert.AreEqual(1, result.Content.Scoreboard.Count);
        }
Esempio n. 10
0
 public PutMatchResultsCommand(string endpoint, DateTime timestamp, MatchResultsDto matchResults)
 {
     Endpoint     = endpoint;
     Timestamp    = timestamp;
     MatchResults = matchResults;
 }
Esempio n. 11
0
        public async Task <IHttpActionResult> PutMatchResults(string endpoint, DateTimeOffset timestamp, MatchResultsDto matchResults)
        {
            AddModelErrorIfTimestampIsNotUtc(timestamp);
            if (ModelState.IsValid)
            {
                try
                {
                    await _mediator.Send(new PutMatchResultsCommand(endpoint, timestamp.UtcDateTime, matchResults));

                    return(Ok());
                }
                catch (ValidationException e)
                {
                    ModelState.AddModelError(e.Property, e.Message);
                }
            }
            return(BadRequest(ModelState));
        }