public void SuccessWhenUserIsNotInTheLobby() { //arrange var options = Utils.GetDbOptions("AddUserShould_SuccessWhenUserIsNotInTheLobby"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { ID = 5 }); context.Users.Add(new User() { Id = "test_user" }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var lobbyInvitationSenderService = new Mock <ILobbyInvitationSenderService>(); var service = new LobbyService(context, null, null); service.AddUser(5, "test_user"); } //assert using (var context = new ApplicationDbContext(options)) { var participation = context.UserParticipationInLobbies.Find(new object[] { 5, "test_user" }); Assert.NotNull(participation); Assert.True(context.Lobbies.Find(5).UserParticipations.Contains(participation)); Assert.Equal(context.Users.Find("test_user").LobbyParticipation, participation); } }
public void ThrowExceptionWhenUserIsNotInTheLobby() { //arrange var options = Utils.GetDbOptions("RemoveUserShould_ThrowExceptionWhenUserIsNotInTheLobby"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { ID = 5 }); context.Users.Add(new User() { Id = "test_user" }); context.SaveChanges(); } //act & assert using (var context = new ApplicationDbContext(options)) { var chatService = new Mock <IChatService>(); var service = new LobbyService(context, null, chatService.Object); Assert.Throws <InvalidOperationException>(() => service.RemoveUser(5, "test_user")); } }
public LobbyManagement(Random random, GameService gameService, LobbyService lobbyService, PremiumService premiumService) { Random = random; GameService = gameService; LobbyService = lobbyService; PremiumService = premiumService; }
public void SucceedWhenGivenUniqueName() { //assert var options = Utils.GetDbOptions("CreateLobbyShould_SucceedWhenGivenUniqueName"); Lobby lobby; using (var context = new ApplicationDbContext(options)) { context.Users.Add(new User() { Id = "test_user" }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); lobby = service.CreateLobby("test_user", "new_lobby", true); } //assert using (var context = new ApplicationDbContext(options)) { Assert.NotNull(lobby); Assert.Equal("new_lobby", lobby.Name); Assert.Equal("test_user", lobby.OwnerID); Assert.True(lobby.Private); } }
public void SetupTest() { RedisConnectionMock = new Mock <IConnectionMultiplexer>(); LoggerMock = new Mock <ILogger <LobbyService> >(); SubscriberMock = new Mock <ISubscriber>(); DatabaseMock = new Mock <IDatabase>(); LobbyOptions = new OptionsWrapper <GametekiLobbyOptions>(new GametekiLobbyOptions { NodeName = "TestNode" }); TestUsers = new List <LobbyUser>(); RedisConnectionMock.Setup(c => c.GetSubscriber(It.IsAny <object>())).Returns(SubscriberMock.Object); RedisConnectionMock.Setup(c => c.GetDatabase(It.IsAny <int>(), It.IsAny <object>())).Returns(DatabaseMock.Object); Service = new LobbyService(RedisConnectionMock.Object, LobbyOptions, LoggerMock.Object); for (var i = 0; i < 50; i++) { var testUser = TestUtils.GetRandomLobbyUser(); TestUsers.Add(testUser); Service.NewUserAsync(testUser); } SubscriberMock.Reset(); }
public LobbyHub(LobbyService lobbyService, IPlayerServiceClient playerService) { _lobbyService = lobbyService ?? throw new ArgumentNullException(nameof(lobbyService)); _playerService = playerService ?? throw new ArgumentNullException(nameof(playerService)); }
public void SucceedWhenLobbyExists() { //arrange var options = Utils.GetDbOptions("RemoveLobbyShould_SucceedWhenLobbyExists"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { ID = 5, Name = "new_lobby", OwnerID = "test_user" }); context.Users.Add(new User() { Id = "test_user" }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); service.RemoveLobby(5, "test_user"); } //assert using (var context = new ApplicationDbContext(options)) { Assert.Null(context.Lobbies.Find(5)); } }
public void ThrowExceptionWhenUserIsAlreadyInTheLobby() { //arrange var options = Utils.GetDbOptions("InviteUserShould_ThrowExceptionWhenUserIsAlreadyInTheLobby"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { ID = 5 }); context.Users.Add(new User() { Id = "test_user" }); context.UserParticipationInLobbies.Add(new UserParticipationInLobby() { UserID = "test_user", LobbyID = 5 }); context.SaveChanges(); } //act & assert using (var context = new ApplicationDbContext(options)) { var lobbyInvitationSenderService = new Mock <ILobbyInvitationSenderService>(); var service = new LobbyService(context, lobbyInvitationSenderService.Object, null); Assert.Throws <InvalidOperationException>(() => service.InviteUser(5, "test_user")); } }
public void DoNotHandleUserLeftWhenUserHaveOtherConnections() { //assert var options = Utils.GetDbOptions("RemoveUserConnectionShould_DoNotHandleUserLeftWhenUserHaveOtherConnections"); var chatService = new Mock <IChatService>(); using (var context = new ApplicationDbContext(options)) { context.Users.Add(new User() { Id = "test_user" }); context.Lobbies.Add(new Lobby() { ID = 5 }); context.UserParticipationInLobbies.Add(new UserParticipationInLobby() { UserID = "test_user", LobbyID = 5, ConnectionIds = new HashSet <string> { "otherConnectionId", "connectionId" } }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, chatService.Object); service.RemoveUserConnection("test_user", "connectionId"); } //assert chatService.Verify(cs => cs.OnUserLeft(It.IsAny <string>(), It.IsAny <string>()), Times.Never()); }
public void HandleUserJoinWhenAddedFirstConnection() { //assert var options = Utils.GetDbOptions("SaveUserConnectionShould_HandleUserJoinWhenAddedFirstConnection"); var chatService = new Mock <IChatService>(); using (var context = new ApplicationDbContext(options)) { context.Users.Add(new User() { Id = "test_user", UserName = "******" }); context.Lobbies.Add(new Lobby() { ID = 5 }); context.UserParticipationInLobbies.Add(new UserParticipationInLobby() { UserID = "test_user", LobbyID = 5 }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, chatService.Object); service.SaveUserConnection("test_user", "connectionId"); } //assert chatService.Verify(cs => cs.OnUserJoined( It.Is <string>(username => username == "TestUser"), It.Is <string>(chatId => chatId == "5"))); }
public void UpdateDatabaseGivenExistingId() { //arrange var options = Utils.GetDbOptions("EditLobbyShould_UpdateDatabaseGivenExistingId"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby { ID = 5, Name = "Test", Private = false }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var chatService = new Mock <IChatService>(); var service = new LobbyService(context, null, null); service.EditLobby(5, "GoodName", true); } //assert using (var context = new ApplicationDbContext(options)) { Assert.True(context.Lobbies.Find(5).Private); Assert.Equal("GoodName", context.Lobbies.Find(5).Name); } }
public void ThrowInvalidOperationExceptionWhenUserIsNotOwnerOfTheLobby() { //arrange var options = Utils.GetDbOptions("RemoveLobbyShould_ThrowInvalidOperationExceptionWhenUserIsNotOwnerOfTheLobby"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { ID = 5, Name = "new_lobby", OwnerID = "test_user" }); context.Users.Add(new User() { Id = "test_user" }); context.SaveChanges(); } //act & assert using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); Assert.Throws <InvalidOperationException>(() => service.RemoveLobby(5, "not_owner_id")); } }
static void Main(string[] args) { WebHttpBinding binding = new WebHttpBinding(); WebHttpBehavior behavior = new WebHttpBehavior(); GameService aGameService = new GameService(); LobbyService aLobbyService = new LobbyService(); WebServiceHost aGameHost = new WebServiceHost(aGameService, new Uri("http://localhost:22415/Lisk/v1/")); WebServiceHost aLobbyHost = new WebServiceHost(aLobbyService, new Uri("http://localhost:22415/Lisk/v1/")); try { aGameHost.AddServiceEndpoint(typeof(IGameService), binding, "game"); aLobbyHost.AddServiceEndpoint(typeof(ILobbyService), binding, "lobby"); aGameHost.Open(); aLobbyHost.Open(); Console.WriteLine(string.Format("Starting GameService {0}\nStarting LobbyService {1}", ServiceVersion.GameServiceVersion.Version, ServiceVersion.LobbyServiceVersion.Version)); Console.WriteLine("Press any key to close..."); } catch (Exception e) { Console.WriteLine("Error starting Endpoint..."); Console.WriteLine(e.Message); } Console.ReadKey(); Console.WriteLine("Closing..."); aGameHost.Close(); }
public LobbyHandler(IMapper mapper, LobbyService lobbyService, PlayerService playerService) { _mapper = mapper; _lobbyService = lobbyService; _playerService = playerService; }
public void TestGetLobbiesNon() { var lobbyService = new LobbyService(); var lobbies = lobbyService.GetLobbies(); Assert.Empty(lobbies); }
public void TestCreateLobby() { var lobbyService = new LobbyService(); var lobby = lobbyService.CreateLobby("apples", null); Assert.Equal("apples", lobby.Name); Assert.Equal(0, lobby.Id); Assert.Empty(lobby.Players); }
public void TestGetLobby() { var lobbyService = new LobbyService(); var createdLobby = lobbyService.CreateLobby("apples", null); var lobby = lobbyService.GetLobby("apples"); Assert.Same(createdLobby, lobby); }
/// <summary> /// 작업큐로부터 꺼내 작업 수행 /// </summary> private void Service() { if (_serviceQueue.Count == 0) { return; } OriginPacket originPacket; lock (_locker) { originPacket = _serviceQueue.Dequeue(); } Header header = originPacket.Header; byte[] data = originPacket.Data; Service service = null; Packet packet; switch (header.MsgType) { case Protocol.Register: packet = JsonManager.BytesToObject <ReceivingRegisterPacket>(data); service = new RegisterService(packet); break; case Protocol.Login: packet = JsonManager.BytesToObject <ReceivingLoginPacket>(data); service = new LoginService(packet); break; case Protocol.Lobby: packet = JsonManager.BytesToObject <ReceivingLobbyPacket>(data); service = new LobbyService(packet); break; case Protocol.LobbyChat: packet = JsonManager.BytesToObject <ReceivingChatPacket>(data); service = new LobbyChatService(packet); break; case Protocol.CreateRoom: packet = JsonManager.BytesToObject <ReceivingCreateRoomPacket>(data); service = new CreateRoomService(packet); break; case Protocol.EnterRoom: packet = JsonManager.BytesToObject <ReceivingEnterRoomPacket>(data); service = new EnterRoomService(packet); break; } if (service != null) { service.Execute(); } }
public void TestGetJoinedLobbyNotJoined() { var lobbyService = new LobbyService(); lobbyService.CreateLobby("apples", null); var lobby = lobbyService.GetJoinedLobby("2"); Assert.Null(lobby); }
public void TestGetLobbyNonExisting() { var lobbyService = new LobbyService(); var createdLobby = lobbyService.CreateLobby("apples", null); var lobby = lobbyService.GetLobby("pears"); Assert.NotSame(createdLobby, lobby); Assert.Null(lobby); }
public void TestGetLobbies() { var lobbyService = new LobbyService(); lobbyService.CreateLobby("apples", null); lobbyService.CreateLobby("pears", null); var lobbies = lobbyService.GetLobbies(); Assert.Equal(2, lobbies.Count()); }
public void TestGetJoinedLobby() { var lobbyService = new LobbyService(); var lobby = lobbyService.CreateLobby("apples", null); lobby.AddPlayer("name", Color.Blue); var joinedLobby = lobbyService.GetJoinedLobby("name"); Assert.NotNull(joinedLobby); }
public void Awake() { networkManager = GameObject.Find("NetworkManager"); networkConnector = networkManager.GetComponent <MonoTcpNetworkConnector>(); monoClientMessageProcessor = networkManager.GetComponent <MonoClientMessageProcessor>(); loggedInUser = networkManager.GetComponent <UserLobbyObject>().GetLoggedInUser(); lobbyService = new LobbyService(networkConnector, monoClientMessageProcessor, loggedInUser); GetAllLobbies(); }
public GameService(LobbyService lobbyService, PhaseService phaseService, ICardGameRepository cardGameRepository, IHubContext <LobbyHub, ILobbyHubClient> lobbyHub, IHubContext <GameHub, IGameHubClient> gameHub) { this.lobbyService = lobbyService; this.phaseService = phaseService; this.cardGameRepository = cardGameRepository; this.lobbyHub = lobbyHub; this.gameHub = gameHub; }
public void ThrowExceptionGivenIdOutOfRange() { //arrange var options = Utils.GetDbOptions("EditLobbyShould_ThrowExceptionGivenIdOutOfRange"); //act & assert using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); Assert.Throws <ArgumentOutOfRangeException>(() => service.EditLobby(5, "SomeLobby", true)); } }
public void ThrowExceptionWhenUserNotFound() { //assert var options = Utils.GetDbOptions("RemoveUserConnectionShould_ThrowExceptionWhenUserNotFound"); var chatService = new Mock <IChatService>(); //act & assert using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, chatService.Object); Assert.Throws <ArgumentOutOfRangeException>(() => service.RemoveUserConnection("ghost_user", "connectionId")); } }
public void RemoveConnectionWhenUserParticipatesInLobby() { //assert var options = Utils.GetDbOptions("RemoveUserConnectionShould_RemoveConnectionWhenUserParticipatesInLobby"); var chatService = new Mock <IChatService>(); using (var context = new ApplicationDbContext(options)) { context.Users.Add(new User() { Id = "test_user" }); context.Lobbies.Add(new Lobby() { ID = 5 }); context.UserParticipationInLobbies.Add(new UserParticipationInLobby() { UserID = "test_user", LobbyID = 5, ConnectionIds = new HashSet <string> { "connectionId" } }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, chatService.Object); service.RemoveUserConnection("test_user", "connectionId"); } //assert using (var context = new ApplicationDbContext(options)) { var connections = context.UserParticipationInLobbies.Find(new object[] { 5, "test_user" }).ConnectionIds; Assert.Equal(0, connections.Count); chatService.Verify(cs => cs.RemoveConnectionsFromChat( It.IsAny <ICollection <string> >(), It.Is <string>(chatId => chatId == "5"))); } }
public void ReturnCorrectLobbiesList() { //arrange var options = Utils.GetDbOptions("GetAllPublicOrOnwedLobbiesShould_ReturnCorrectLobbiesList"); IEnumerable <string> lobbyNamesList; using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { Name = "OurUserPublicLobby", OwnerID = "our_user", Private = false }); context.Lobbies.Add(new Lobby() { Name = "OtherUserPublicLobby", OwnerID = "other_user", Private = false }); context.Lobbies.Add(new Lobby() { Name = "OurUserPrivateLobby", OwnerID = "our_user", Private = true }); context.Lobbies.Add(new Lobby() { Name = "OtherUserPrivateLobby", OwnerID = "other_user", Private = true }); context.SaveChanges(); } //act using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); lobbyNamesList = from l in service.GetAllPublicOrOwnedLobbies("our_user") select l.Name; } //assert using (var context = new ApplicationDbContext(options)) { Assert.Contains("OurUserPublicLobby", lobbyNamesList); Assert.Contains("OtherUserPublicLobby", lobbyNamesList); Assert.Contains("OurUserPrivateLobby", lobbyNamesList); Assert.DoesNotContain("OtherUserPrivateLobby", lobbyNamesList); } }
public void ThrowArgumentOutOfRangeExceptionWhenLobbyDoesNotExists() { //arrange var options = Utils.GetDbOptions("RemoveLobbyShould_ThrowArgumentOutOfRangeExceptionWhenLobbyDoesNotExists"); using (var context = new ApplicationDbContext(options)) { context.Users.Add(new User() { Id = "test_user" }); context.SaveChanges(); } //act & assert using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); Assert.Throws <ArgumentOutOfRangeException>(() => service.RemoveLobby(1, "test_user")); } }
public void ThrowExceptionGivenUserIdOutOfRange() { //arrange var options = Utils.GetDbOptions("AddUserShould_ThrowExceptionGivenUserIdOutOfRange"); using (var context = new ApplicationDbContext(options)) { context.Lobbies.Add(new Lobby() { ID = 5 }); context.SaveChanges(); } //act & assert using (var context = new ApplicationDbContext(options)) { var service = new LobbyService(context, null, null); Assert.Throws <ArgumentOutOfRangeException>(() => service.AddUser(5, "unknown_user")); } }
void Start() { for(int i=0;i<56;i++) { loadingpercent[i]=GameObject.Find("percent"+i).GetComponent<Image>(); } for(int i=0;i<10;i++) { load[i]=GameObject.Find(""+i).GetComponent<RectTransform>(); y[i]=load [i].localPosition.y; up_down[i] =false ; } BeginConnectTime=Time.time; time=Time.time; guy_image=GameObject.Find ("guy").GetComponent<Image>(); guy_rect=GameObject.Find ("guy").GetComponent<RectTransform>(); proxy = Singletons.GET<LobbyService>(); model = Singletons.GET<UserModel>(); roommodel=Singletons.GET <RoomModel>(); proxy.OnLobbyUserInfo = OnUserInfo; proxy.OnLobbyMyHousingItemList=OnMyHousingItemList; proxy.OnLobbyCharInfo=OnCharInfo; proxy.OnLobbyCashInfo=OnCashInfo; proxy.OnLobbyConnectAuth = delegate(Cmdlib.cmdGAME_ANSWER_CONNECT_AUTH data) { if (data.GetAck () == 1) { proxy.LobbyLoginAuth (model.LALA_data.login_name, model.LALA_data.auth_key, 0, 0, 0); } else { } }; proxy.OnLobbyLoginAuth = delegate(Cmdlib.cmdGAME_ANSWER_LOGIN_AUTH data) { if (data.GetAck () == 1) { model.GALA_data=data; WebLog.Log("登陆成功了!!!!"); proxy.LobbyUserInfo(data.security_key); } else { } }; proxy.OnLobbyEnterLobby=delegate(cmdGAME_ANSWER_ENTER_LOBBY data) { if(data.GetAck()==1) { WebLog.Log(data+"进入大厅"); //proxy.LobbyEventList(); } }; /* proxy.OnLobbyEventList=delegate(cmdGAME_ANSWER_EVENT_LIST data) { roommodel.GAEL_EventList=data; proxy.LobbyRoomList((byte)eROOM_PAGE_TYPE.ROOM_PAGE_TYPE_NONE,(byte)eMATCH_VIEW_TYPE.MATCH_VIEW_TYPE_ITEM,(byte)eROOM_VIEW_TYPE.ROOM_VIEW_TYPE_INDIVIDUAL); }; proxy.OnLobbyRoomList=delegate(cmdGAME_ANSWER_ROOM_LIST data) { if(data.GetAck()==1) { WebLog.Log(data); // roommodel.RoomInfo.Clear(); } }; proxy.OnLobbyNotifyRoomListPage=delegate(cmdGameNotifyRoomListPage data) { roommodel.GNRLG_Page=data; WebLog.Log(data); }; proxy.OnLobbyNotifyRoomListAdd=delegate(cmdGameNotifyRoomListAdd data) { WebLog.Log("添加房间"); roommodel.RoomInfo.Add(data.info); };*/ lobbynetwork=Singletons.GET<LobbyNetWork>(); lobbynetwork.Connect(1,model .LALA_data.ip,model.LALA_data.port,OnConnected); }
void Start() { roommodel=Singletons.GET<RoomModel>(); proxy=Singletons.GET<LobbyService>(); gameService=Singletons.GET<GameService>(); usermodel=Singletons.GET<UserModel>(); // proxy.OnLobbyRoomCreate=OnRoomCreate; // gameService.OnGameRoomJoin=OnGameRoomJoin; switch(RoomGrid.BtnModel()){ case 0: model=2; m_IsCollider.isOn=false; break; case 1: model=0; m_IsCollider.isOn=true; break; case 2: model=11; m_IsCollider.isOn=true; break; } }