示例#1
0
        public void CanSearch() {
            if (ignoreelastic) Assert.Ignore("no elastic search");
            var mq = _container.Get<IMessageQueue>();
            for (var i = 0; i < 10; i++)
            {
                var message = new PostMessage
                {
                    Id = "M" + i,
                    Addresses = new[] { "*****@*****.**" },
                    From = "support",
                    Body = "<h1>Привет</h1>"
                };
                if (i%2 == 0) {
                    message.Tags = new Dictionary<string, object> {
                        {"be","cool"}
                    };
                }
                mq.PushMessage(message);
            }
            var search = mq.SearchMessages(@"{
  ""query"": {
    ""query_string"": {
      ""query"": ""cool""
    }
  }
}").ToArray();
            Assert.AreEqual(5,search.Length);
            search = mq.SearchMessages("cool").ToArray();
            Assert.AreEqual(5,search.Length);
        }
示例#2
0
 public PostMessage CompoundMessage(IUser target, string template, string @from, string subject, IScope scope) {
     var workingtemplate = ResolveTemplate(template);
     scope = scope ?? new Scope();
     scope.Set("user", target);
     scope.Set("resource", AppInfo);
     var resultmessage = workingtemplate.Interpolate(scope);
     subject = (subject ?? "").Interpolate(scope);
     var email = target.Email;
     var pm = new PostMessage {
         Addresses = new[] {email},
         From = @from,
         CanUseDefault = true,
         Subject = subject,
         Body = resultmessage.ToString(),
         Tags = new Dictionary<string, object>()
     };
     foreach (var pair in scope) {
         if (pair.Key == "user") {
             pm.Tags["user"] = target.Login;
         }
         else {
             pm.Tags[pair.Key] = pair.Value;
         }
     }
     return pm;
 }
示例#3
0
        public PostMessage CompoundMessage(IUser target, string template, string @from, string subject, IScope scope)
        {
            var workingtemplate = ResolveTemplate(template);

            scope = scope ?? new Scope();
            scope.Set("user", target);
            scope.Set("resource", AppInfo);
            var resultmessage = workingtemplate.Interpolate(scope);

            subject = (subject ?? "").Interpolate(scope);
            var email = target.Email;
            var pm    = new PostMessage {
                Addresses     = new[] { email },
                From          = @from,
                CanUseDefault = true,
                Subject       = subject,
                Body          = resultmessage.ToString(),
                Tags          = new Dictionary <string, object>()
            };

            foreach (var pair in scope)
            {
                if (pair.Key == "user")
                {
                    pm.Tags["user"] = target.Login;
                }
                else
                {
                    pm.Tags[pair.Key] = pair.Value;
                }
            }
            return(pm);
        }
示例#4
0
 public void CanSendMail() {
     var smtpsender = new SmtpMessageSender();
     var conf = new BxlParser().Parse(File.ReadAllText(EnvironmentInfo.ResolvePath("@repos@/zrepos/mail.bxls")),options:BxlParserOptions.ExtractSingle);
     smtpsender.InitializeFromXml(conf);
     var message = new PostMessage();
     message.From = "ivan";
     message.Addresses = new[] {"*****@*****.**"};
     message.Body = "<h1>Привет!</h1>";
     smtpsender.Send(message);
 }
示例#5
0
 public void CanMarkSent() {
     if (ignoreelastic) Assert.Ignore("no elastic search");
     var mq = _container.Get<IMessageQueue>();
     var message = new PostMessage
     {
         Addresses = new[] { "*****@*****.**" },
         From = "support",
         Body = "<h1>Привет</h1>"
     };
     message = mq.PushMessage(message);
     mq.MarkSent(message.Id);
     var message2 = mq.GetMessage(message.Id);
     Assert.True(message2.WasSent);
     Assert.Greater(1,(DateTime.Now.ToUniversalTime()-message2.SentTime.ToUniversalTime()).TotalMinutes);
 }
示例#6
0
        public void CanStoreAndGet() {
            if(ignoreelastic)Assert.Ignore("no elastic search");
            var mq = _container.Get<IMessageQueue>();
            var message = new PostMessage {
                Addresses = new[] {"*****@*****.**"},
                From = "support",
                Body = "<h1>Привет</h1>"
            };
            message = mq.PushMessage(message);
            Assert.Less(10,message.Id.Length);
            Assert.Less(1990,message.CreateTime.Year);
            Assert.Less(1990,message.StartTime.Year);

            var message2 = mq.GetMessage(message.Id);
            Console.WriteLine(message2.stringify());
            Console.WriteLine(message.stringify());
            Assert.AreEqual(message.stringify(),message2.stringify());
        }
示例#7
0
 public void CanDetectNotSent() {
     if (ignoreelastic) Assert.Ignore("no elastic search");
     var mq = _container.Get<IMessageQueue>();
     for (var i = 0; i < 10; i++) {
         var message = new PostMessage
         {
             Id = "M"+i,
             Addresses = new[] { "*****@*****.**" },
             From = "support",
             Body = "<h1>Привет</h1>"
         };
         if (i > 4) {
             message.StartTime = DateTime.Now.AddDays(1).ToUniversalTime();
         }
         if (i == 2) {
             message.WasSent = true;
             message.SentTime = DateTime.Now.ToUniversalTime();
         }
         mq.PushMessage(message);
     }
     var needsend = mq.GetRequireSendMessages().ToArray();
     Assert.AreEqual(4,needsend.Length);
     Assert.AreEqual("M0,M1,M3,M4",string.Join(",",needsend.Select(_=>_.Id).OrderBy(_=>_)));
 }