public void UpdateAndExtractCloudEvent_V0_6_0Header_ExtensionsAddedToCloudEvent()
    {
        var channel                      = _fixture.Connection.CreateModel();
        var basicProperties              = channel.CreateBasicProperties();
        var publisherOptions             = new RabbitMQPublisherOptions <byte[]>();
        var content                      = new byte[] { 1, 2, 3 };
        var inputCloudEvent              = MotorCloudEvent.CreateTestCloudEvent(content);
        var mockedApplicationNameService = Mock.Of <IApplicationNameService>();

        basicProperties.SetPriority(inputCloudEvent, publisherOptions);
        basicProperties.WriteCloudEventIntoHeader(inputCloudEvent);
        // manipulate basic properties to simulate outdated version
        basicProperties.Headers.Remove($"{BasicPropertiesExtensions.CloudEventPrefix}{MotorVersionExtension.MotorVersionAttribute.Name}");
        basicProperties.ContentEncoding = null;
        basicProperties.Headers.Add(
            $"{BasicPropertiesExtensions.CloudEventPrefix}{CloudEventsSpecVersion.V1_0.DataContentTypeAttribute.Name}",
            Encoding.UTF8.GetBytes($"{basicProperties.ContentType}"));
        foreach (var(key, value) in basicProperties.Headers)
        {
            if (value is byte[] byteValue)
            {
                basicProperties.Headers[key] = EscapeWithQuotes(byteValue);
            }
        }

        var outputCloudEvent = basicProperties.ExtractCloudEvent(mockedApplicationNameService,
                                                                 new ReadOnlyMemory <byte>(content));

        Assert.Equal(MotorCloudEventInfo.RequiredAttributes(Version.Parse("0.6.0.0")).Count(),
                     outputCloudEvent.GetPopulatedAttributes().Count());
        foreach (var requiredAttribute in MotorCloudEventInfo.RequiredAttributes(Version.Parse("0.6.0.0")))
        {
            Assert.Equal(inputCloudEvent[requiredAttribute], outputCloudEvent[requiredAttribute]);
        }
    }
    private static void VerifyPresenceOfRequiredAttributes <TData>(IBasicProperties basicProperties,
                                                                   // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
                                                                   MotorCloudEvent <TData> cloudEvent) where TData : class
    {
        Assert.Equal(cloudEvent.ContentType, basicProperties.ContentType);
        // ContentType is required but not saved in the header. Instead, the native
        // AMQP ContentType is used and therefore, we expect #RequiredAttributes - 1
        var requiredAttributes = MotorCloudEventInfo.RequiredAttributes(CurrentMotorVersion);

        Assert.Equal(requiredAttributes.Count() - 1, basicProperties.Headers.Count);
    }
    public void UseProtocolFormat_NoExtensions_OnlyRequiredAttributesInHeader()
    {
        var publisher       = GetKafkaPublisher <byte[]>();
        var consumer        = GetKafkaConsumer <byte[]>();
        var inputCloudEvent = MotorCloudEvent.CreateTestCloudEvent(Array.Empty <byte>());

        var kafkaMessage     = publisher.CloudEventToKafkaMessage(inputCloudEvent);
        var outputCloudEvent = consumer.KafkaMessageToCloudEvent(kafkaMessage);

        Assert.Equal(MotorCloudEventInfo.RequiredAttributes(CurrentMotorVersion).Count(),
                     outputCloudEvent.GetPopulatedAttributes().Count());
        foreach (var requiredAttribute in MotorCloudEventInfo.RequiredAttributes(CurrentMotorVersion))
        {
            Assert.Equal(inputCloudEvent[requiredAttribute], outputCloudEvent[requiredAttribute]);
        }
    }
    public void UpdateAndExtractCloudEvent_NoExtensions_CloudEventWithRequiredExtensions()
    {
        var channel                      = _fixture.Connection.CreateModel();
        var basicProperties              = channel.CreateBasicProperties();
        var publisherOptions             = new RabbitMQPublisherOptions <byte[]>();
        var content                      = new byte[] { 1, 2, 3 };
        var inputCloudEvent              = MotorCloudEvent.CreateTestCloudEvent(content);
        var mockedApplicationNameService = Mock.Of <IApplicationNameService>();

        basicProperties.SetPriority(inputCloudEvent, publisherOptions);
        basicProperties.WriteCloudEventIntoHeader(inputCloudEvent);
        var outputCloudEvent = basicProperties.ExtractCloudEvent(mockedApplicationNameService,
                                                                 new ReadOnlyMemory <byte>(content));

        foreach (var requiredAttribute in MotorCloudEventInfo.RequiredAttributes(CurrentMotorVersion))
        {
            Assert.Equal(inputCloudEvent[requiredAttribute], outputCloudEvent[requiredAttribute]);
        }
    }