Example #1
0
        public async Task AddAsync(EmailQueueToken token, EmailMessageParams message, CancellationToken cancellationToken)
        {
            _logger.LogTrace("Adding new blob to store for token {0}", token);

            if (!_initialized)
            {
                await InitializeAsync(cancellationToken);
            }

            var serialized = EmailMessageParams.ToJson(message);
            var blobName   = GetBlobName(token);
            var blob       = _container.Value.GetBlockBlobReference(blobName);
            await blob.UploadTextAsync(serialized, Encoding.UTF8, null, null, null, cancellationToken);
        }
        public void ToJson_ShouldDeserializeDataObject()
        {
            // arrange
            var data = new Dictionary <string, object> {
                { "Name", "Keith" }
            };
            var target = new EmailMessageParams {
                Data = data
            };

            // act
            var serialized   = EmailMessageParams.ToJson(target);
            var deserialized = EmailMessageParams.FromJson(serialized);

            // assert
            Assert.Equal(data, deserialized.Data);
        }
        public void ToJson_ShouldSerializeDataAsObject()
        {
            // arrange
            var data = new Dictionary <string, object> {
                { "Name", "Keith" }
            };
            var expected = JsonConvert.SerializeObject(data, Formatting.None);
            var target   = new EmailMessageParams {
                Data = data
            };

            // act
            var actual = EmailMessageParams.ToJson(target, Formatting.None);

            // assert
            Assert.Contains(expected, actual);
        }
        public void ToJson_ShouldSerializeComplexDataAsObject()
        {
            // arrange
            var data = new Dictionary <string, object>
            {
                { "Name", "Keith" },
                { "Roles", new string[] { "Developer", "Manager" } },
                { "Computer", new
                  {
                      Make  = "Microsoft",
                      Model = "Surface Book"
                  } }
            };
            var expected = JsonConvert.SerializeObject(data, Formatting.None);
            var target   = new EmailMessageParams {
                Data = data
            };

            // act
            var actual = EmailMessageParams.ToJson(target, Formatting.None);

            // assert
            Assert.Contains(expected, actual);
        }