Beispiel #1
0
        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 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 LobbyDto CreateLobby(LobbyPlayer creator)
        {
            var lobby = _lobbyService.CreateLobby(Lobbies.Select(l => l.Code), creator);

            Lobbies.Add(lobby);

            return(_mapper.Map <LobbyDto>(lobby));
        }
Beispiel #4
0
        public void TestGetLobby()
        {
            var lobbyService = new LobbyService();
            var createdLobby = lobbyService.CreateLobby("apples", null);

            var lobby = lobbyService.GetLobby("apples");

            Assert.Same(createdLobby, lobby);
        }
Beispiel #5
0
        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 async void CreateNewLobby()
    {
        CreateLobbyResponse createNewLobbyResponse = await lobbyService.CreateLobby(lobbyName.text);

        if (createNewLobbyResponse.IsSuccess)
        {
            networkManager.GetComponent <UserLobbyObject>().SetJoinedLobby(createNewLobbyResponse.LobbyDto);
            scene.ChangeScene(Scenes.LOBBY);
        }
    }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public void TestGetJoinedLobbyNotJoined()
        {
            var lobbyService = new LobbyService();

            lobbyService.CreateLobby("apples", null);

            var lobby = lobbyService.GetJoinedLobby("2");

            Assert.Null(lobby);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        public void ThrowInvalidOperationExceptionWhenLobbyWithThisNameExists()
        {
            //arrange
            var options = Utils.GetDbOptions("CreateLobbyShould_ThrowInvalidOperationExceptionWhenLobbyWithThisNameExists");

            using (var context = new ApplicationDbContext(options))
            {
                context.Lobbies.Add(new Lobby()
                {
                    Name = "new_lobby"
                });
                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.CreateLobby("test_user", "new_lobby", true));
            }
        }