Exemple #1
0
        private RoomManager GetMockedRoomManager(Mock <ISessionRepo> sessionRepo = null,
                                                 Mock <IMasterRepo> masterRepo   =
                                                 null,
                                                 Mock <IRequestCache> requestCache = null)
        {
            sessionRepo ??= new Mock <ISessionRepo>();
            masterRepo ??= new Mock <IMasterRepo>();

            sessionRepo.Setup(_ => _.DoesRoomUserExist(It.IsAny <string>())).Returns(false);
            sessionRepo.SetReturnsDefault(new Room(0, 0));
            sessionRepo.SetReturnsDefault(new RoomUser());

            return(new RoomManager(MasterHubTests.GetMockWithSendFuns().Object, masterRepo.Object,
                                   new Mock <IServerLoop>().Object, new Mock <ILogger <RoomManager> >().Object,
                                   new Mock <IFinalizeManager>().Object));
        }
Exemple #2
0
        public void CalcScore(int[] types, int[] eatenCounts, int[] basraCounts,
                              int[] bigBasraCounts, int[] scores)
        {
            var roomActors = new List <RoomActor>();

            for (int i = 0; i < eatenCounts.Length; i++)
            {
                if (types[i] == 0)
                {
                    roomActors.Add(new RoomUser
                    {
                        EatenCardsCount = eatenCounts[i],
                        BasraCount      = basraCounts[i],
                        BigBasraCount   = bigBasraCounts[i],
                    });
                }
                else
                {
                    roomActors.Add(new RoomBot
                    {
                        EatenCardsCount = eatenCounts[i],
                        BasraCount      = basraCounts[i],
                        BigBasraCount   = bigBasraCounts[i],
                    });
                }
            }


            var finMan = new FinalizeManager(MasterHubTests.GetMockWithSendFuns().Object,
                                             new Mock <IMasterRepo>().Object, new
                                             Mock <ISessionRepo>().Object, new Mock <ILogger <FinalizeManager> >().Object);

            var actualScores = (List <int>)TestHelper.CallPrivateMethod("CalcScores", finMan,
                                                                        new Object[] { roomActors });

            Assert.Equal(scores, actualScores);
        }
Exemple #3
0
        public async Task FinalizeGame_RightWinner(int eaten1, int eaten2, int basra1, int basra2,
                                                   int bbasra1, int bbasra2, int winner)
        {
            var roomDataUsers = new List <User>()
            {
                new()
                {
                    Id    = "0",
                    Level = 9999,
                },
                new()
                {
                    Id    = "1",
                    Level = 9999,
                },
            };
            //every int is 0

            var roomUsers = new List <RoomUser>
            {
                new()
                {
                    Id = "0",
                    EatenCardsCount = eaten1,
                    BasraCount      = basra1,
                    BigBasraCount   = bbasra1,
                    ActiveUser      = new("0", "00", typeof(UserDomain.App)),
                },
                new()
                {
                    Id = "1",
                    EatenCardsCount = eaten2,
                    BasraCount      = basra2,
                    BigBasraCount   = bbasra2,
                    ActiveUser      = new("0", "00", typeof(UserDomain.App)),
                }
            };

            var room = new Room(0, 0);

            room.RoomUsers.AddRange(roomUsers);
            room.RoomActors.AddRange(roomUsers);

            room.LastEater   = roomUsers[0];
            room.GroundCards = new List <int>();

            var masterRepoMock = new Mock <IMasterRepo>();

            masterRepoMock.Setup(mr => mr.GetUsersByIdsAsync(It.IsAny <List <string> >()))
            .Returns(() => Task.FromResult(roomDataUsers));

            var finMan = new FinalizeManager(MasterHubTests.GetMockWithSendFuns().Object,
                                             masterRepoMock.Object, new Mock <ISessionRepo>()
                                             .Object, new Mock <ILogger <FinalizeManager> >().Object);

            await finMan.FinalizeRoom(room);

            _testOutputHelper.WriteLine(JsonConvert.SerializeObject(roomDataUsers));

            if (winner == 0)
            {
                Assert.True(roomDataUsers[0].Money > roomDataUsers[1].Money);
            }
            else if (winner == 1)
            {
                Assert.True(roomDataUsers[1].Money > roomDataUsers[0].Money);
            }
            else if (winner == -1)
            {
                Assert.Equal(roomDataUsers[1].Money, roomDataUsers[0].Money);
            }
        }