public ElasticSearchStorageTests()
        {
            var options = new ElasticSearchStorageOptions {
                Uri   = $"http://{host}:9200",
                Index = "middlemail-test",
            };

            this.elasticSearchStorage = new ElasticSearchStorage(Options.Create(options));

            // after writes to elasticsearch it takes some time that they are reflected in search results
            // we simply wait 1 second after each write operation and before each read.
            // The IMailStorage implementation should however always be robust enough to not rely on the underlying storage to serve up-to-date data.
            elasticSearchStorageWithDelay = new Mock <IMailStorage>();

            elasticSearchStorageWithDelay
            .Setup(s => s.SetProcessedAsync(It.IsAny <EmailMessage>()))
            .Returns(async(EmailMessage emailMessage) => {
                await elasticSearchStorage.SetProcessedAsync(emailMessage);
                await Task.Delay(DELAY);
            });

            elasticSearchStorageWithDelay
            .Setup(s => s.SetErrorAsync(It.IsAny <EmailMessage>(), It.IsAny <string>()))
            .Returns(async(EmailMessage emailMessage, string error) => {
                await elasticSearchStorage.SetErrorAsync(emailMessage, error);
                await Task.Delay(DELAY);
            });

            elasticSearchStorageWithDelay
            .Setup(s => s.SetSentAsync(It.IsAny <EmailMessage>()))
            .Returns(async(EmailMessage emailMessage) => {
                await elasticSearchStorage.SetSentAsync(emailMessage);
                await Task.Delay(DELAY);
            });

            elasticSearchStorageWithDelay
            .Setup(s => s.GetErrorAsync(It.IsAny <EmailMessage>()))
            .Returns(async(EmailMessage emailMessage) => {
                await Task.Delay(DELAY);
                var error = await elasticSearchStorage.GetErrorAsync(emailMessage);
                return(error);
            });

            elasticSearchStorageWithDelay
            .Setup(s => s.GetSentAsync(It.IsAny <EmailMessage>()))
            .Returns(async(EmailMessage emailMessage) => {
                await Task.Delay(DELAY);
                var sent = await elasticSearchStorage.GetSentAsync(emailMessage);
                return(sent);
            });
        }
예제 #2
0
 /// <summary>
 /// Initialises LogElastic.NET Storage.
 /// </summary>
 public static void Initialise()
 {
     if (storage == null) storage = Injector.Get<ElasticSearchStorage>();
 }