Example #1
0
        ///Sprawdza czy da się połączyć i przesłać jakie kolwiek dane
        public async Task PlayMatch()
        {
            int      userIdFirst  = getRandomUserId();
            int      userIdSecend = getRandomUserId(userIdFirst);
            int      gameType     = 1;
            GamePlay gp1          = null;
            GamePlay gp2          = null;
            AsyncDuplexStreamingCall <PlayMatchRequest, GamePlay> call = Client.PlayMatch();
            var dateStartNew = DateTime.Now.AddDays(10).ToString();
            var setDateEnd   = DateTime.Now.AddDays(20).ToShortDateString();

            //Act
            AsyncUnaryCall <SearchOpponentRespons> responsAsync1 = Client.SearchOpponentAsync(new SearchOpponentRequest {
                GameType = gameType, UserId = userIdFirst
            });
            AsyncUnaryCall <SearchOpponentRespons> responsAsync2 = Client.SearchOpponentAsync(new SearchOpponentRequest {
                GameType = gameType, UserId = userIdSecend
            });
            SearchOpponentRespons respons1 = await responsAsync1;
            SearchOpponentRespons respons2 = await responsAsync2;

            gp1 = new GamePlay {
                Match = respons1.Match
            };
            gp2 = new GamePlay {
                Match = respons2.Match
            };

            gp1.Match.DateStart = dateStartNew;
            call.RequestStream.WriteAsync(new PlayMatchRequest {
                GamePlay = gp1, UserId = userIdFirst
            });                                                                                           //Wywołuje ruch
            while (await call.ResponseStream.MoveNext(CancellationToken.None))
            {
                gp2 = call.ResponseStream.Current;
                break;
            }

            gp2.Match.DateEnd = setDateEnd;
            call.RequestStream.WriteAsync(new PlayMatchRequest {
                GamePlay = gp2, UserId = userIdSecend
            });                                                                                           //Wywołuje ruch
            while (await call.ResponseStream.MoveNext(CancellationToken.None))
            {
                gp1 = call.ResponseStream.Current;
                break;
            }

            //Asert
            Assert.NotNull(gp1);
            Assert.NotNull(gp2);
            Assert.NotNull(gp1.Match);
            Assert.NotNull(gp2.Match);
            Assert.AreEqual(gp2.Match.DateStart, dateStartNew);
            Assert.AreEqual(gp1.Match.DateStart, dateStartNew);
            Assert.AreEqual(gp2.Match.DateEnd, setDateEnd);
            Assert.AreEqual(gp1.Match.DateEnd, setDateEnd);
        }
Example #2
0
        public async Task <SearchOpponentRespons> SearchOpponentAsync(GameTypes gametype, int userID) //dokładniej request
        {
            GameOnlineGrpc.SearchOpponentRespons match = await this.server.GameClient.SearchOpponentAsync(new GameOnlineGrpc.SearchOpponentRequest {
                GameType = (int)gametype, UserId = userID
            });

            Responses.SearchOpponentRespons respons = new SearchOpponentRespons
            {
                Messages = new Dictionary <string, string>(),
                Status   = (ServiceResponseStatus)match.Respons.Status,
                Match    = Mapping.Mapper.Map <Match>(match.Match)
            };

            foreach (var responsMessage in match.Respons.Messages)
            {
                respons.Messages.Add(responsMessage.Key, responsMessage.Value);
            }

            return(respons);
        }