Пример #1
0
        /// <summary>
        /// Sends a message to storage queue with properties.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message">The message body to be sent.</param>
        /// <param name="properties">The properties of the message.</param>
        /// <returns>Task.</returns>
        public async Task Send <T>(T message, KeyValuePair <string, object>[] properties) where T : class
        {
            var obj      = new MessageEntity <T>(message, properties);
            var outgoing = new CloudQueueMessage(obj.AsJson());

            const long maxAllowedSizeBytes = 64 * 1024;
            var        messageLengthBytes  = outgoing.AsBytes.Length;

            if (messageLengthBytes > maxAllowedSizeBytes)
            {
                throw new ArgumentOutOfRangeException(nameof(message), $"Max message size of {maxAllowedSizeBytes} bytes exceeded (message size was {messageLengthBytes})");
            }

            await SenderQueue.AddMessageAsync(outgoing);
        }
        public void Test_MessageEntity_ToFromJson()
        {
            // Arrage
            var wrapper = new MessageEntity <string>("body", new KeyValuePair <string, object>[1]
            {
                new KeyValuePair <string, object>("Key", "value")
            });

            // Act
            var jsonVersion = wrapper.AsJson();
            var converted   = JsonConvert.DeserializeObject <MessageEntity <string> >(jsonVersion);
            var typedProps  = wrapper.GetPropertiesTyped <TypedPropsSample>();

            // Assert
            converted.Body.Should().Be("body");
            converted.Properties.Should().BeEquivalentTo(new KeyValuePair <string, object>[1]
            {
                new KeyValuePair <string, object>("Key", "value")
            });
            typedProps.Should().NotBeNull();
            typedProps.Key.Should().Be("value");
        }