public void ShouldBeAbleToRetrieveUpdatedPreferencesForAnExistingIpAddress() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); Color newColor = RandomColorGenerator.GenerateColor().ToUnity(); PlayerPreference newPlayerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, newColor); //When playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, playerPreference); playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, newPlayerPreference); PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.RedAdditive.Should().Be(newColor.r); result.GreenAdditive.Should().Be(newColor.g); result.BlueAdditive.Should().Be(newColor.b); }
public void ShouldBeAbleToRetrieveANewPreferenceEntry() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor()); Color preferredColor = playerPreference.PreferredColor(); //When playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, playerPreference); PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.PlayerName.Should().Be(TestConstants.TEST_PLAYER_NAME); result.RedAdditive.Should().Be(preferredColor.r); result.GreenAdditive.Should().Be(preferredColor.g); result.BlueAdditive.Should().Be(preferredColor.b); }
private void SetCurrentPreference(string playerName, Color playerColor) { PlayerPreference newPreference = new PlayerPreference(playerName, playerColor); if (activePlayerPreference.Equals(newPreference)) { return; } preferencesManager.SetPreference(ServerIp, newPreference); }
public void ShouldGetTheLastSetPlayerPreferenceWhenJoiningANewServer() { //Given PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference firstPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); string firstIpAddress = "127.0.0.1"; playerPreferenceManager.SetPreference(firstIpAddress, firstPreference); PlayerPreference secondPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); string secondIpAddress = "123.456.789.321"; playerPreferenceManager.SetPreference(secondIpAddress, secondPreference); PlayerPreference thirdPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); Color expectedColor = thirdPreference.PreferredColor(); string thirdIpAddress = "000.000.000.000"; playerPreferenceManager.SetPreference(thirdIpAddress, thirdPreference); //When PlayerPreference result = playerPreferenceManager.GetPreference(TestConstants.TEST_IP_ADDRESS); //Then result.PlayerName.Should().Be(thirdPreference.PlayerName); result.RedAdditive.Should().Be(expectedColor.r); result.GreenAdditive.Should().Be(expectedColor.g); result.BlueAdditive.Should().Be(expectedColor.b); }
private void OnJoinClick() { string playerName = playerNameInputField.text; //https://regex101.com/r/eTWiEs/2/ if (!Regex.IsMatch(playerName, @"^[a-zA-Z0-9._-]{3,25}$")) { NotifyUser(Language.main.Get("Nitrox_InvalidUserName")); return; } preferencesManager.SetPreference(serverIp, new PlayerPreference(playerName, colorPicker.currentColor)); AuthenticationContext authenticationContext = passwordEntered ? new AuthenticationContext(playerName, serverPassword) : new AuthenticationContext(playerName); multiplayerSession.RequestSessionReservation(new PlayerSettings(colorPicker.currentColor.ToDto()), authenticationContext); }
public void SetPreferenceShouldThrowExceptionWhenGivenANullJoinServerSettingsReference() { //Arrange PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); //Act Action action = () => playerPreferenceManager.SetPreference(TestConstants.TEST_IP_ADDRESS, null); //Assert action.ShouldThrow <ArgumentNullException>(); }
public void SetPreferenceShouldThrowExceptionWhenGivenANullIpAddress() { //Arrange PlayerPreferenceState playerPreferenceState = new PlayerPreferenceState(); playerPreferenceState.Preferences = new Dictionary <string, PlayerPreference>(); IPreferenceStateProvider stateProvider = Substitute.For <IPreferenceStateProvider>(); stateProvider.GetPreferenceState().Returns(playerPreferenceState); PlayerPreferenceManager playerPreferenceManager = new PlayerPreferenceManager(stateProvider); PlayerPreference playerPreference = new PlayerPreference(TestConstants.TEST_PLAYER_NAME, RandomColorGenerator.GenerateColor().ToUnity()); //Act Action action = () => playerPreferenceManager.SetPreference(null, playerPreference); //Assert action.ShouldThrow <ArgumentNullException>(); }