Beispiel #1
0
        public void EnqueueSubjectTest()
        {
            var subscriber = new TestSubscriber();

            MessageSenderService.EnqueueSubject.Subscribe(subscriber);

            var messageSenderService = new MessageSenderService();
            var testMessage          = new TestMessage
            {
                Title = "Test Message"
            };

            messageSenderService.Send <TestMessageSender, TestMessage>(testMessage);

            Thread.Sleep(TimeSpan.FromSeconds(1));
            Assert.AreEqual(1, TestSubscriber.ActionContexts.Count);
            var actionContext = TestSubscriber.ActionContexts[0];
            var data          = JsonConvert.DeserializeObject <TestMessage>(actionContext.Data);

            Assert.AreEqual(testMessage.Title, data.Title);
            Assert.AreEqual("Message Enqueue", actionContext.Action);
            Assert.AreEqual(typeof(TestMessageSender), actionContext.MessageSenderType);
            Assert.AreEqual(typeof(TestMessage), actionContext.MessageType);
            Assert.AreNotEqual(null, actionContext.JobId);
        }
Beispiel #2
0
        public void SendTestMessage()
        {
            var messageSenderService = new MessageSenderService();
            var testMessage          = new TestMessage
            {
                Title = "Test Message"
            };

            messageSenderService.Send <TestMessageSender, TestMessage>(testMessage);

            Thread.Sleep(TimeSpan.FromSeconds(2));
            Assert.AreEqual(1, TestMessage.TestMessages.Count);
            Assert.AreEqual(testMessage.Title, TestMessage.TestMessages[0].Title);
        }
Beispiel #3
0
        public void SendTestMessages()
        {
            var messageSenderService = new MessageSenderService();
            var testMessages         = new TestMessage[20];

            for (int i = 0; i < testMessages.Length; i++)
            {
                testMessages[i] = new TestMessage
                {
                    Title = $"Test message #{i}"
                }
            }
            ;

            messageSenderService.Send <TestMessageSender, TestMessage>(testMessages);

            Thread.Sleep(TimeSpan.FromSeconds(2));
            Assert.AreEqual(testMessages.Length, TestMessage.TestMessages.Count);
        }
        static void Main(string[] args)
        {
            System.Console.WriteLine("The mail sender service has started...");

            GlobalConfiguration.Configuration.AddMailServer(x =>
            {
            }).AddConsole().HangfireConfig(x =>
            {
                x.RetryCount       = 5;
                x.ConnectionString = "Server=.;Initial catalog=MessageServiceTestDatabase;user id=sa;password=12345";
            });

            var messageSenderService = new MessageSenderService();

            var email = new Email()
            {
                Subject = "Test email"
            };

            messageSenderService.Send <EmailMessageSender, Email>(email);

            var key = System.Console.ReadKey();
        }