public void ShouldNotAuthenticateBannedPlayers() { var playersRepository = new InMemoryUserRepository(); var uowFactory = new UnitOfWorkFactoryMock(playersRepository, Mock.Of<IPublicMessageRepository>()); var moderator = new Domain.Entities.User("Egor", "123", "111111", true, 13, string.Empty, "Belarus"); moderator.GrantModeratorship(); var player = new Domain.Entities.User("Egor", "123", "111111", true, 13, string.Empty, "Belarus"); playersRepository.Add(player); player.Ban(moderator); var sessionMock = new Mock<ISession>(); var transactionFactoryMock = new Mock<ITransactionFactory>(); var authService = new AuthenticationService(Mock.Of<ISettings>(), transactionFactoryMock.Object, uowFactory); var response = authService.Authenticate(sessionMock.Object, new AuthenticationRequest { Name = "Egor", Password = "******", Huid = "111111", }); Assert.AreEqual(AuthenticationResponseType.Banned, response.Result); }
public void ShouldSuccessfullyRegisterPlayerWithValidData() { var transactionFactoryMock = new Mock<ITransactionFactory>(); var playersRepository = new InMemoryUserRepository(); var uowFactory = new UnitOfWorkFactoryMock(playersRepository, Mock.Of<IPublicMessageRepository>()); playersRepository.Add(new Domain.Entities.User("Egor", "123", "111111", true, 13, string.Empty, "Belarus")); var sessionMock = new Mock<ISession>(); var registrationService = new RegistrationService(transactionFactoryMock.Object, uowFactory); var response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 24, Huid = "HUID123", Password = "******", PushUri = "", Sex = true, Comments = "Comments", Country = "Russia", Name = "John", }); Assert.AreEqual(RegistrationResponseType.Success, response.Result); }
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); }
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. }
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()); }
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); }
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()); }
public void ShouldntAllowRegisterWithInvalidData() { var transactionFactoryMock = new Mock<ITransactionFactory>(); var playersRepository = new InMemoryUserRepository(); var uowFactory = new UnitOfWorkFactoryMock(playersRepository, Mock.Of<IPublicMessageRepository>()); var sessionMock = new Mock<ISession>(); var registrationService = new RegistrationService(transactionFactoryMock.Object, uowFactory); //trying to register with empty name var response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 20, Comments = "Comments", Country = "Russia", Name = "", Huid = "111", Password = "******" }); Assert.AreEqual(RegistrationResponseType.InvalidData, response.Result); //trying to register with extremly long name response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 20, Comments = "Comments", Country = "Russia", Huid = "111", Name = string.Join("", Enumerable.Range(1, 1000)), Password = "******" }); Assert.AreEqual(RegistrationResponseType.InvalidData, response.Result); //trying to register with empty psw response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 20, Comments = "Comments", Country = "Russia", Name = "Egor", Huid = "111", Password = "" }); Assert.AreEqual(RegistrationResponseType.InvalidData, response.Result); //trying to register with extremly long psw response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 20, Comments = "Comments", Country = "Russia", Name = "Egor", Huid = "111", Password = string.Join("", Enumerable.Range(1, 1000)) }); Assert.AreEqual(RegistrationResponseType.InvalidData, response.Result); //trying to register with empty country response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 20, Comments = "Comments", Country = "", Name = "Egor", Password = "******", Huid = "111" }); Assert.AreEqual(RegistrationResponseType.InvalidData, response.Result); //trying to register with empty huid response = registrationService.RegisterNewPlayer(sessionMock.Object, new RegistrationRequest { Age = 20, Comments = "Comments", Country = "Belarus", Name = "Egor", Password = "******", Huid = "" }); Assert.AreEqual(RegistrationResponseType.InvalidData, response.Result); }