Ejemplo n.º 1
0
        public void ShouldGetDetailsForUser()
        {
            var sessionManager = new SessionManagerMock();
            var aliceSessionMock = sessionManager.AppendPlayerAsSession("Alice");

            var playersRepository = new InMemoryUserRepository();
            playersRepository.Add(aliceSessionMock.Object.User);
            var egorPlayer = new Domain.Entities.User("Egor", "123", "111111", true, 13, string.Empty, "Belarus");
            egorPlayer.GetType().GetProperty("Id").SetValue(egorPlayer, 5);
            playersRepository.Add(egorPlayer);

            var uowFactory = new UnitOfWorkFactoryMock(playersRepository, Mock.Of<IPublicMessageRepository>());
            var searchService = new UsersSearchService(uowFactory, Mock.Of<ITransactionFactory>());

            
            var response = searchService.GetUserDetails(aliceSessionMock.Object, new GetUserDetailsRequest { Name = "Egor" });
            Assert.AreEqual("Egor", response.User.Name);

            response = searchService.GetUserDetails(aliceSessionMock.Object, new GetUserDetailsRequest { Name = "Egorko" });
            Assert.IsNull(response.User);

            response = searchService.GetUserDetails(aliceSessionMock.Object, new GetUserDetailsRequest { UserId = 0 });
            Assert.IsNull(response.User);

            response = searchService.GetUserDetails(aliceSessionMock.Object, new GetUserDetailsRequest { UserId = 0 });
            Assert.IsNull(response.User);

            response = searchService.GetUserDetails(aliceSessionMock.Object, new GetUserDetailsRequest { UserId = egorPlayer.Id });
            Assert.IsNotNull(response.User);
        }
Ejemplo n.º 2
0
        public void DevoicedPeopleAreNotAllowedToChat()
        {
            var sessionManager = new SessionManagerMock();
            var aliceSessionMock = sessionManager.AppendPlayerAsSession("Alice");
            var bobSessionMock = sessionManager.AppendPlayerAsSession("Bob");
            var playerRepo = new InMemoryUserRepository();
            playerRepo.Add(aliceSessionMock.Object.User);
            playerRepo.Add(bobSessionMock.Object.User);

            //grant moderatorship to Bob
            bobSessionMock.Object.User.GrantModeratorship();

            var uowFactory = new UnitOfWorkFactoryMock(playerRepo, Mock.Of<IPublicMessageRepository>());
            var chatService = new ChatService(sessionManager, Mock.Of<ISettings>(), null, Mock.Of<ITransactionFactory>(), uowFactory, Mock.Of<IPushNotificator>());

            //Alice sends a message - everything is ok
            chatService.PublicMessage(aliceSessionMock.Object, new PublicMessageRequest {Body = "F&ck you!"});
            //Make sure Bob has received the message
            bobSessionMock.Verify(i => i.Send(It.Is<PublicMessageDto>(msg => msg.Body == "F&ck you!")), Times.Once());
            //Bob devoices Alice because of foul language
            chatService.Devoice(bobSessionMock.Object, new DevoiceRequest { Reason = "Foul language", TargetUserId = aliceSessionMock.Object.User.Id});
            bobSessionMock.Verify(i => i.Send(It.Is<DevoiceResponse>(response => response.Result == DevoiceResponseType.Success)), Times.Once());
            //Alice doesn't beleave that she is devoiced and tries to send a message
            chatService.PublicMessage(aliceSessionMock.Object, new PublicMessageRequest { Body = "Am I really devoiced?" });
            //Make sure Bob hasn't receive the message
            bobSessionMock.Verify(i => i.Send(It.Is<PublicMessageDto>(msg => msg.Body == "Am I really devoiced?")), Times.Never());
            //Server will send a system message notifying User that he is devoiced.   
        }
Ejemplo n.º 3
0
        public void OnlyModeratorsCanDevoice()
        {
            var sessionManager = new SessionManagerMock();
            var aliceSessionMock = sessionManager.AppendPlayerAsSession("Alice");
            var bobSessionMock = sessionManager.AppendPlayerAsSession("Bob");
            var playerRepo = new InMemoryUserRepository();
            playerRepo.Add(aliceSessionMock.Object.User);
            playerRepo.Add(bobSessionMock.Object.User);

            //neither Bob nor Alice are moderators

            var uowFactory = new UnitOfWorkFactoryMock(playerRepo, Mock.Of<IPublicMessageRepository>());
            var chatService = new ChatService(sessionManager, Mock.Of<ISettings>(), null, Mock.Of<ITransactionFactory>(), uowFactory, Mock.Of<IPushNotificator>());

            chatService.Devoice(bobSessionMock.Object, new DevoiceRequest { Reason = "Just for fun", TargetUserId = aliceSessionMock.Object.User.Id });
            bobSessionMock.Verify(i => i.Send(It.Is<DevoiceResponse>(response => response.Result == DevoiceResponseType.Failed)), Times.Once());
        }
Ejemplo n.º 4
0
        public void ShouldFindExistedPlayer()
        {
            var sessionManager = new SessionManagerMock();
            var aliceSessionMock = sessionManager.AppendPlayerAsSession("Alice");

            var playersRepository = new InMemoryUserRepository();
            playersRepository.Add(aliceSessionMock.Object.User);
            playersRepository.Add(new Domain.Entities.User("Egor", "123", "111111", true, 13, string.Empty, "Belarus"));
            playersRepository.Add(new Domain.Entities.User("EgorBo", "123", "111111", true, 13, string.Empty, "Belarus"));
            playersRepository.Add(new Domain.Entities.User("EgoBo", "123", "111111", true, 13, string.Empty, "Belarus"));

            var uowFactory = new UnitOfWorkFactoryMock(playersRepository, Mock.Of<IPublicMessageRepository>());
            
            var searchService = new UsersSearchService(uowFactory, Mock.Of<ITransactionFactory>());
            var response = searchService.SearchUser(aliceSessionMock.Object, new UsersSearchRequest { QueryString = "egor" });

            Assert.AreEqual(2, response.Result.Length);
        }
Ejemplo n.º 5
0
        public void EveryoneInChatExceptBusyShouldReceiveTheMessage()
        {
            var playersRepository = new InMemoryUserRepository();
            var uowFactory = new UnitOfWorkFactoryMock(playersRepository, Mock.Of<IPublicMessageRepository>());
            var transactionFactoryMock = new Mock<ITransactionFactory>();

            var sessionManager = new SessionManagerMock();
            var aliceSessionMock = sessionManager.AppendPlayerAsSession("Alice");
            var bobSessionMock = sessionManager.AppendPlayerAsSession("Bob");
            var egorSessionMock = sessionManager.AppendPlayerAsSession("Egor");
            //var johnSessionMock = sessionManager.AppendPlayerAsSession("John", PlayerState.Dueling);

            var chatService = new ChatService(sessionManager, Mock.Of<ISettings>(), null, transactionFactoryMock.Object, uowFactory, Mock.Of<IPushNotificator>());
            
            chatService.PublicMessage(aliceSessionMock.Object, new PublicMessageRequest { Body = "Hi dudes!" });

            bobSessionMock.Verify(i => i.Send(It.Is<PublicMessageDto>(msg => msg.Body == "Hi dudes!" && msg.AuthorName == "Alice")), Times.Once());
            egorSessionMock.Verify(i => i.Send(It.Is<PublicMessageDto>(msg => msg.Body == "Hi dudes!" && msg.AuthorName == "Alice")), Times.Once());
            
            //John should not receive the message because he is busy (dueling or whatever)
            //johnSessionMock.Verify(i => i.Send(It.IsAny<PublicMessageDto>()), Times.Never());
        }