Esempio n. 1
0
        public MatchmakingSession CreateSession(Guid userId)
        {
            var session = new MatchmakingSession()
            {
                Id           = Guid.NewGuid(),
                HostPlayerId = userId,
                CreatedOn    = DateTime.Now
            };

            _matchSessionService.Sessions.Add(session);
            return(session);
        }
Esempio n. 2
0
        public async Task KickOff_ReturnsMatch()
        {
            var mockMatchmakingService = new Mock <IMatchmakingService>();
            var sessionId = Guid.NewGuid();
            var session   = new MatchmakingSession
            {
                Id             = sessionId,
                HostPlayerId   = Guid.NewGuid(),
                JoinedPlayerId = Guid.NewGuid()
            };

            mockMatchmakingService.Setup(x => x.GetSession(sessionId)).Returns(session);

            var stubMatchEngine = new Mock <IMatchEngine>();

            stubMatchEngine.Setup(x => x.SimulateReentrant(It.IsAny <ApplicationCore.Models.Match>()))
            .Returns(new ApplicationCore.Models.Match());

            ApplicationCore.Models.Match simulatedMatch = null;

            var mockBus       = new Mock <IBus>();
            var squadResponse = new GetSquadResponse
            {
                Lineup = new Dictionary <string, Card>()
            };

            mockBus.Setup(x => x.RequestAsync <GetSquadRequest, GetSquadResponse>(It.IsAny <GetSquadRequest>()))
            .Returns(Task.FromResult(squadResponse));

            var mockMatchRepository = new Mock <IMatchRepository>();

            mockMatchRepository.Setup(x => x.CreateAsync(It.IsAny <ApplicationCore.Models.Match>()))
            .Callback <ApplicationCore.Models.Match>(r => simulatedMatch = r);

            _matchService = new MatchService(mockMatchmakingService.Object, stubMatchEngine.Object,
                                             mockMatchRepository.Object, mockBus.Object);

            //Act
            await _matchService.KickOff(sessionId);

            //Assert
            Assert.NotNull(simulatedMatch);
        }