public static Version Select (ClientVersion clientVersion, ServerSupportedVersions supportedVersions) { if (clientVersion.IsNotMalformed () && supportedVersions.HasVersionMatching (clientVersion)) return new AcceptedVersion (clientVersion); return supportedVersions.GetHighestVersion (); }
public void Given_a_client_prefers_the_same_version_as_the_server_When_selecting_which_version_to_use_Then_the_server_returns_the_clients_preferred_version () { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var clientVersion = new ClientVersion (1, 0, 0); var serverSupportedVersions = new ServerSupportedVersions (Version.Exactly (1, 0, 0)); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- var result = VersionSelector.Select (clientVersion, serverSupportedVersions); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- result.Should ().Be (new AcceptedVersion (clientVersion)); }
public void Given_a_client_prefers_a_version_which_the_server_does_not_support_When_selecting_which_version_to_use_Then_the_server_returns_its_preferred_version_And_closes_the_connection (byte major, byte minor, byte revision) { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var clientVersion = new ClientVersion (major, minor, revision); var serverSupportedVersions = new ServerSupportedVersions (Version.Exactly (1, 1, 0)); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- var result = VersionSelector.Select (clientVersion, serverSupportedVersions); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- result.Should ().Be (new ServerVersion (new Version (1, 1, 0))); }