예제 #1
0
        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"));
            }
        }
예제 #2
0
        public void RemoveUserConnectionsToHub()
        {
            //arrange
            var chatService = new Mock <IChatService>();
            var options     = Utils.GetDbOptions("RemoveUserShould_RemoveUserConnectionsToHub");

            using (var context = new ApplicationDbContext(options))
            {
                context.Lobbies.Add(new Lobby()
                {
                    ID = 5
                });
                context.Users.Add(new User()
                {
                    Id       = "test_user",
                    UserName = "******"
                });
                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.RemoveUser(5, "test_user");
            }
            //assert
            chatService.Verify(cs => cs.RemoveConnectionsFromChat(
                                   It.IsAny <ICollection <string> >(),
                                   It.Is <string>(connectionId => connectionId == "5")));
            chatService.Verify(cs => cs.OnUserLeft(
                                   It.Is <string>(username => username == "TestUser"),
                                   It.Is <string>(chatId => chatId == "5")));
        }
예제 #3
0
        public void RemoveUserParticipationFromDatabase()
        {
            //arrange
            var options = Utils.GetDbOptions("RemoveUserShould_RemoveUserParticipationFromDatabase");

            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
            using (var context = new ApplicationDbContext(options))
            {
                var chatService = new Mock <IChatService>();
                var service     = new LobbyService(context, null, chatService.Object);
                service.RemoveUser(5, "test_user");
            }
            //assert
            using (var context = new ApplicationDbContext(options))
            {
                Assert.Null(context.UserParticipationInLobbies.Find(new object[] { 5, "test_user" }));
                Assert.Equal(0, context.Lobbies.Find(5).UserParticipations.Count);
                Assert.Null(context.Users.Find("test_user").LobbyParticipation);
            }
        }