public void TestSendMessage()
        {
            // Arrange
            var TestQueueName     = "foo";
            var TestTransactionID = 100;
            var TestHeaders       = new Dictionary <string, object> {
                { "bar", "baz" }
            };
            var TestRequestMessage = new TransmissionMessageDTO()
            {
                Content = "Test message!"
            };
            var TestTransaction = new TransactionDTO()
            {
                TransactionID = TestTransactionID, Headers = TestHeaders, RequestMessage = TestRequestMessage
            };

            var TestContext = new LinkerSharpContext();

            TestContext.DirectQueues.Add(TestQueueName, new Queue <TransactionDTO>());
            TestContext.DirectQueues[TestQueueName].Enqueue(TestTransaction);

            var TestFactory  = new EndpointFactory <IConsumer>();
            var TestConsumer = TestFactory.GetFrom($"direct->{TestQueueName}", TestContext);

            // Execution
            var TestResults = TestConsumer.ReceiveMessages();

            // Assertions
            Assert.AreEqual(1, TestResults.Count, "TestConsumer should have results!");
            Assert.AreEqual(TestTransactionID, TestResults[0].TransactionID);
            Assert.AreEqual(TestHeaders["bar"], TestResults[0].Headers["bar"]);
            Assert.AreEqual(TestRequestMessage.Content, TestResults[0].RequestMessage.Content);
            Assert.IsTrue(TestResults[0].ResponseMessage == null);
        }
Beispiel #2
0
        public void TestFullRouteEndpoints()
        {
            // Arrange
            var TestContext  = new LinkerSharpContext();
            var TestFilePath = AppDomain.CurrentDomain.BaseDirectory.Replace(@"bin\Debug", "TestFiles");
            var TestDestiny  = $"{TestFilePath}\\Destiny\\";

            var TestConsumerFactory = new EndpointFactory <IConsumer>();
            var TestProducerFactory = new EndpointFactory <IProducer>();

            var TestFileConsumer = TestConsumerFactory.GetFrom($"file->{TestFilePath}\\Origin\\->autoclean=false", TestContext);
            var TestFileProducer = TestProducerFactory.GetFrom($"file->{TestDestiny}", TestContext);

            // Execute
            var TestTransactions = TestFileConsumer.ReceiveMessages();
            var TestResults      = new List <bool>();

            foreach (var TestTransaction in TestTransactions)
            {
                var Date = DateTime.Now;

                TestFileProducer.Transaction = TestTransaction;
                TestFileProducer.Transaction.ResponseMessage.Content = TestTransaction.RequestMessage.Content;
                TestFileProducer.Transaction.ResponseMessage.Name    = $"TestReal_{Date.Year}_{Date.Month}_{Date.Day}_{Date.Hour}_{Date.Minute}_{Date.Millisecond}.txt";

                TestResults.Add(TestFileProducer.SendMessage());
            }

            this.CleanFiles(TestDestiny);

            // Assertions
            Assert.AreEqual(TestTransactions.Count(), TestResults.Count(t => t), "There are unsent messages!");
        }
Beispiel #3
0
        /// <summary>
        /// Starting point for the messaging route
        /// </summary>
        /// <param name="Uri">A complete URI with LinkerSharp syntax.</param>
        /// <returns></returns>
        public RouteDefinition From(string Uri)
        {
            var ConsumerFactory = new EndpointFactory <IConsumer>();

            var Consumer = ConsumerFactory.GetFrom(Uri, this.Context);

            return(new RouteDefinition(Consumer.ReceiveMessages(), this.Context));
        }
        public void TestGetProducer()
        {
            // Arrange
            var TestFactory      = new EndpointFactory <IProducer>();
            var TestFileEndpoint = "\\foo\bar";
            var TestFTPEndpoint  = "ftp://foo/bar";

            // Execute
            var TestExistingFileProducer = TestFactory.GetFrom($"file->{TestFileEndpoint}", this.TestContext);
            var TestExistingFtpProducer  = TestFactory.GetFrom($"ftp->{TestFTPEndpoint}", this.TestContext);

            // Assertions
            Assert.AreEqual("FILE", TestExistingFileProducer.Protocol, $"Wrong protocol assigned!");
            Assert.AreEqual("FTP", TestExistingFtpProducer.Protocol, $"Wrong protocol assigned!");
            Assert.AreEqual(TestFileEndpoint, TestExistingFileProducer.Endpoint, $"Wrong endpoint assigned!");
            Assert.AreEqual(TestFTPEndpoint, TestExistingFtpProducer.Endpoint, $"Wrong endpoint assigned!");
        }
Beispiel #5
0
        public void To(string Uri)
        {
            var ProducerFactory = new EndpointFactory <IProducer>();

            var Producer = ProducerFactory.GetFrom(Uri, Context);

            foreach (var Transaction in this.Transactions)
            {
                Producer.Transaction = Transaction;

                Producer.SendMessage();
            }
        }
Beispiel #6
0
        public void Init()
        {
            this.TestFilePath = $"{AppDomain.CurrentDomain.BaseDirectory.Replace(@"bin\Debug", "TestFiles")}\\Destiny\\";

            this.TestContext = new LinkerSharpContext();

            var TestFactory = new EndpointFactory <IProducer>();

            this.TestProducer = TestFactory.GetFrom($"file->{this.TestFilePath}", this.TestContext);

            this.TestMessage = new TransmissionMessageDTO()
            {
                Content = "this is a test file.", Name = "Testfile.txt", Destiny = this.TestFilePath
            };
        }
Beispiel #7
0
        /// <summary>
        /// Gets info from another endpoint and stores it into the transaction's request message
        /// </summary>
        /// <param name="Uri">A complete URI with LinkerSharp syntax.</param>
        /// <returns></returns>
        public RouteDefinition Enrich(string Uri)
        {
            var ConsumerFactory = new EndpointFactory <IConsumer>();

            var Consumer = ConsumerFactory.GetFrom(Uri, Context);

            Consumer.Params[Headers.JUST_IN] = "true";

            var Result = Consumer.ReceiveMessages().FirstOrDefault();

            foreach (var Transaction in this.Transactions)
            {
                foreach (var Header in Result.Headers)
                {
                    Transaction.Headers[Header.Key] = Header.Value;
                }
                Transaction.RequestMessage = Result.RequestMessage;
            }

            return(this);
        }
        public void TestBadRouteTags()
        {
            // Arrange
            var CorrectExceptionMsg = "Consumer with name {0} was not found.";
            var UnexpectedExMsg     = "Unexpected exception message!";
            var UnexpectedEx        = "Unexpected exception: {0}";
            var NotThrownFailMsg    = "TestBadEndpoint should throw an exception!";

            var TestConsumerFactory = new EndpointFactory <IConsumer>();
            var TestProducerFactory = new EndpointFactory <IProducer>();

            // Execution and assertions
            try
            {
                var TestBadEndpoint = TestConsumerFactory.GetFrom(@"foo->\\foo\bar", this.TestContext);
                Assert.Fail(NotThrownFailMsg);
            }
            catch (KeyNotFoundException NotFoundEx)
            {
                Assert.AreEqual(string.Format(CorrectExceptionMsg, "FOOConsumer"), NotFoundEx.Message, UnexpectedExMsg);
            }
            catch (Exception ex)
            {
                Assert.Fail(string.Format(UnexpectedEx, ex.Message));
            }

            try
            {
                var TestBadEndpoint = TestProducerFactory.GetFrom(@"foo->\\foo\bar", this.TestContext);
                Assert.Fail(NotThrownFailMsg);
            }
            catch (KeyNotFoundException NotFoundEx)
            {
                Assert.AreEqual(string.Format(CorrectExceptionMsg, "FOOProducer"), NotFoundEx.Message, UnexpectedExMsg);
            }
            catch (Exception ex)
            {
                Assert.Fail(string.Format(UnexpectedEx, ex.Message));
            }
        }
        public void TestSendMessage()
        {
            // Arrange
            var TestContext   = new LinkerSharpContext();
            var TestQueueName = "foo";
            var TestMessage   = new TransmissionMessageDTO()
            {
                Content = "this is a direct test message.", Name = "", Destiny = TestQueueName
            };
            var TestTransaction = new TransactionDTO()
            {
                RequestMessage = TestMessage, ResponseMessage = TestMessage
            };

            var TestFactory  = new EndpointFactory <IProducer>();
            var TestProducer = TestFactory.GetFrom($"direct->{TestQueueName}", TestContext);

            TestProducer.Transaction = TestTransaction;

            // Execution
            var Result = TestProducer.SendMessage();

            // Assertions
        }