Exemple #1
0
        public static void AssertCanEncodeDecodeRequest <T>(this T request, short version, IMembershipEncoder encoder = null, T forComparison = null) where T : class, IRequest
        {
            var encoders = ImmutableDictionary <string, IMembershipEncoder> .Empty;

            if (encoder != null)
            {
                encoders = encoders.Add(encoder.ProtocolType, encoder);
            }

            var context = new RequestContext(17, version, "Test-Request", encoders, encoder?.ProtocolType);
            var bytes   = request.ToBytes(context);
            var decoded = KafkaDecoder.Decode <T>(bytes.Skip(4), context);

            if (forComparison == null)
            {
                forComparison = request;
            }
            Assert.That(forComparison.GetHashCode(), Is.EqualTo(decoded.GetHashCode()), "HashCode equality");
            Assert.That(forComparison.ShortString(), Is.EqualTo(decoded.ShortString()), "ShortString equality");
            var original = forComparison.ToString();
            var final    = decoded.ToString();

            Assert.That(original, Is.EqualTo(final), "ToString equality");
            Assert.That(decoded.Equals(final), Is.False);  // general equality test for sanity
            Assert.That(decoded.Equals(decoded), Is.True); // general equality test for sanity
            Assert.That(forComparison.Equals(decoded), $"Original\n{original}\nFinal\n{final}");
        }