public void CheckVersionRangeTestSuccess(int major, int minor, int lowerMajor, int lowerMinor)
        {
            var version      = new BoltProtocolVersion(major, minor);
            var lowerVersion = new BoltProtocolVersion(lowerMajor, lowerMinor);

            version.CheckVersionRange(lowerVersion);
        }
 public static IBoltProtocol ForVersion(BoltProtocolVersion version, IDictionary <string, string> routingContext = null)
 {
     if (version.Equals(3, 0))
     {
         return(new BoltProtocolV3());
     }
     else if (version.Equals(4, 0))
     {
         return(new BoltProtocolV4());
     }
     else if (version.Equals(4, 1))
     {
         return(new BoltProtocolV4_1(routingContext));
     }
     else if (version.Equals(0, 0))
     {
         throw new NotSupportedException(
                   "The Neo4j server does not support any of the protocol versions supported by this client. " +
                   "Ensure that you are using driver and server versions that are compatible with one another.");
     }
     else if (version == new BoltProtocolVersion(BoltHTTPIdentifier))
     {
         throw new NotSupportedException(
                   "Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
                   $"(HTTP defaults to port 7474 whereas BOLT defaults to port {GraphDatabase.DefaultBoltPort})");
     }
     else
     {
         throw new NotSupportedException(
                   "Protocol error, server suggested unexpected protocol version: " + version.MajorVersion + "." + version.MinorVersion);
     }
 }
Пример #3
0
            public void ShouldThrowExceptionIfVersionIsNotSupported(int majorVersion, int minorVersion, string errorMessage)
            {
                var version   = new BoltProtocolVersion(majorVersion, minorVersion);
                var exception = Record.Exception(() => BoltProtocolFactory.ForVersion(version));

                exception.Should().BeOfType <NotSupportedException>();
                exception.Message.Should().StartWith(errorMessage);
            }
        public void LessOrEqaulThanSuccess(int lhsMajor, int lhsMinor, int rhsMajor, int rhsMinor)
        {
            var lhs = new BoltProtocolVersion(lhsMajor, lhsMinor);
            var rhs = new BoltProtocolVersion(rhsMajor, rhsMinor);

            var result = (lhs <= rhs);

            result.Should().BeTrue();
        }
        public void LessThanFailure(int lhsMajor, int lhsMinor, int rhsMajor, int rhsMinor)
        {
            var lhs = new BoltProtocolVersion(lhsMajor, lhsMinor);
            var rhs = new BoltProtocolVersion(rhsMajor, rhsMinor);

            var result = (lhs < rhs);

            result.Should().BeFalse();
        }
        public void PackToRangeSuccess(int major, int minor, int lowerMajor, int lowerMinor, int expectedValue)
        {
            var version      = new BoltProtocolVersion(major, minor);
            var lowerVersion = new BoltProtocolVersion(lowerMajor, lowerMinor);

            int packedValue = version.PackToIntRange(lowerVersion);

            packedValue.Should().Equals(expectedValue);
        }
        public void InequalityFailure(int lhsMajor, int lhsMinor, int rhsMajor, int rhsMinor)
        {
            var lhs = new BoltProtocolVersion(lhsMajor, lhsMinor);
            var rhs = new BoltProtocolVersion(rhsMajor, rhsMinor);

            var result = (lhs != rhs);

            result.Should().BeFalse();
        }
        public void InequalitySuccess(int lhsMajor, int lhsMinor, int rhsMajor, int rhsMinor)
        {
            var lhs = new BoltProtocolVersion(lhsMajor, lhsMinor);
            var rhs = new BoltProtocolVersion(rhsMajor, rhsMinor);

            var result = (lhs != rhs);

            result.Should().BeTrue();
        }
        public void CheckVersionRangeTestFailureOnNewerMinorVersion(int major, int minor, int lowerMajor, int lowerMinor)
        {
            var version      = new BoltProtocolVersion(major, minor);
            var lowerVersion = new BoltProtocolVersion(lowerMajor, lowerMinor);

            var ex = Record.Exception(() => version.CheckVersionRange(lowerVersion));

            ex.Should().BeOfType <NotSupportedException>();
            ex.Message.Should().Be("Max version should be newer than minimum version");
        }
        public void CheckVersionRangeTestFailureOnMajorMismatch(int major, int minor, int lowerMajor, int lowerMinor)
        {
            var version      = new BoltProtocolVersion(major, minor);
            var lowerVersion = new BoltProtocolVersion(lowerMajor, lowerMinor);

            var ex = Record.Exception(() => version.CheckVersionRange(lowerVersion));

            ex.Should().BeOfType <NotSupportedException>();
            ex.Message.Should().Be("Versions should be from same major version");
        }
        public void EqualsSuccess()
        {
            var v1 = new BoltProtocolVersion(1, 1);
            var v2 = new BoltProtocolVersion(1, 1);

            (v1.Equals(v2)).Should().BeTrue();

            v2 = new BoltProtocolVersion(1, 3);
            (v1.Equals(v2)).Should().BeFalse();

            (v1.Equals(null)).Should().BeFalse();
        }
        public void ProtocolLargeBoundsTest()
        {
            int       successLargeNumber = 1213486160; ////0x‭48 54 54 50 - or HTTP in ascii codes...
            const int majorVersion       = 80,
                      minorVersion       = 84;
            var bv = new BoltProtocolVersion(successLargeNumber);

            (bv.MajorVersion == majorVersion && bv.MinorVersion == minorVersion).Should().BeTrue();


            string errorMessage = "Attempting to create a BoltProtocolVersion with a large (error code) version number.  Resulting Major and Minor are in range of valid versions, which is not allowed: ";

            int failureLargeNumber = new BoltProtocolVersion(majorVersion - 1, minorVersion - 1).PackToInt();
            var exception          = Record.Exception(() => new BoltProtocolVersion(failureLargeNumber));

            exception.Should().BeOfType <NotSupportedException>();
            exception.Message.Should().StartWith(errorMessage);
        }
        public void PackAndUnpackSuccess()
        {
            const int packedIntVersion      = 260,
                      majorVersion          = 4,
                      minorVersion          = 1;
            const ushort packedShortVersion = 260;
            const byte   packedByteVersion  = 20;

            var bv = new BoltProtocolVersion(majorVersion, minorVersion);

            (bv.PackToInt() == packedIntVersion).Should().BeTrue();
            (bv.PackToUShort() == packedShortVersion).Should().BeTrue();
            (bv.PackToByte() == packedByteVersion).Should().BeTrue();

            bv = BoltProtocolVersion.FromPackedInt(packedIntVersion);
            (bv.MajorVersion == majorVersion && bv.MinorVersion == minorVersion).Should().BeTrue();

            bv = BoltProtocolVersion.FromPackedUShort(packedShortVersion);
            (bv.MajorVersion == majorVersion && bv.MinorVersion == minorVersion).Should().BeTrue();

            bv = BoltProtocolVersion.FromPackedByte(packedByteVersion);
            (bv.MajorVersion == majorVersion && bv.MinorVersion == minorVersion).Should().BeTrue();
        }
 public static BoltProtocolVersion UnpackAgreedVersion(byte[] data)
 {
     return(BoltProtocolVersion.FromPackedInt(PackStreamBitConverter.ToInt32(data)));
 }