示例#1
0
        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);
        }
示例#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!");
        }
示例#3
0
        public DIRECTConsumer(string Path, LinkerSharpContext Context) : base(Context)
        {
            this.Endpoint = Path;

            if (!base.Context.DirectQueues.ContainsKey(this.Endpoint))
            {
                base.Context.DirectQueues[this.Endpoint] = new Queue <TransactionDTO>();
            }
        }
示例#4
0
        public void Init()
        {
            this.TestFtpUrl = $"{AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug", "TestFiles")}\\Origin\\";

            this.TestContext = new LinkerSharpContext();

            this.TestConsumerFactory = new EndpointFactory <IConsumer>();
            //this.TestFtpConsumer = this.TestConsumerFactory.GetFrom($"ftp->{this.TestFtpUrl}");
        }
示例#5
0
        static void Main(string[] args)
        {
            // Context instantiation
            var Context = new LinkerSharpContext();

            // Adding routes
            Context.AddRoute(new BaritizeRouteBuilder());
            Context.AddRoute(new SenderRouteBuilder());

            // Starting process
            Context.Run();
        }
示例#6
0
        public FILEProducer(string Path, LinkerSharpContext Context) : base(Context)
        {
            this.Endpoint = Path;
            if (!this.Params.ContainsKey(Headers.AUTOCLEAN))
            {
                this.Params[Headers.AUTOCLEAN] = "true";
            }

            this.Transaction = new TransactionDTO()
            {
                ResponseMessage = new TransmissionMessageDTO()
            };
        }
示例#7
0
        public DIRECTProducer(string Path, LinkerSharpContext Context) : base(Context)
        {
            this.Endpoint = Path;

            if (!base.Context.DirectQueues.ContainsKey(this.Endpoint))
            {
                base.Context.DirectQueues[this.Endpoint] = new Queue <TransactionDTO>();
            }

            this.Transaction = new TransactionDTO()
            {
                ResponseMessage = new TransmissionMessageDTO()
            };
        }
示例#8
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
            };
        }
示例#9
0
        public T GetFrom(string Endpoint, LinkerSharpContext Context)
        {
            var Protocol    = Endpoint.Substring(0, Endpoint.IndexOf("->")).ToUpper();
            var IFaceSuffix = typeof(T).Name.Replace("I", "");

            var ClassName = $"{Protocol}{IFaceSuffix}";

            if (this.AvailableEndpoints.ContainsKey(ClassName))
            {
                return((T)Activator.CreateInstance(this.AvailableEndpoints[ClassName], new object[] { Endpoint, Context }));
            }
            else
            {
                throw new KeyNotFoundException($"Consumer with name {ClassName} was not found.");
            }
        }
示例#10
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 = new FTPProducer($"ftp->{this.TestFilePath}", this.TestContext, new FTPConnectorMock(FTPConnectorMock.Behaviour.SUCCESS));


            this.TestMessage = new TransmissionMessageDTO()
            {
                Content = "This is a test file.", Name = "Testfile.txt", Destiny = this.TestFilePath
            };
        }
示例#11
0
        public void Init()
        {
            this.TestMessage = new TransmissionMessageDTO()
            {
                Name = TEST_MESSAGE_NAME, Content = TEST_MESSAGE_CONTENT
            };
            this.TestTransaction = new TransactionDTO()
            {
                TransactionID   = TEST_TRANSACT_ID,
                Transport       = TransportTypeEnum.IN_OUT,
                RequestMessage  = this.TestMessage,
                ResponseMessage = this.TestMessage
            };

            this.TestContext = new LinkerSharpContext();

            this.TestRoute = new RouteDefinition(new List <TransactionDTO>()
            {
                TestTransaction
            }, this.TestContext);
        }
示例#12
0
        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
        }
示例#13
0
 public FTPProducer(string Uri, LinkerSharpContext Context, IFTPOutConnector OutConnector) : base(Context)
 {
     this.Endpoint  = Uri;
     this.Connector = OutConnector ?? new DefaultFTPConnector();
 }
示例#14
0
 public RouteDefinition(List <TransactionDTO> Transactions, LinkerSharpContext Context)
 {
     this.Transactions = Transactions;
     this.Context      = Context;
 }
示例#15
0
        public FTPConsumer(string Uri, LinkerSharpContext Context, IFTPInConnector Connector = null) : base(Context)
        {
            this.Endpoint = Uri;

            this.Connector = Connector ?? new DefaultFTPConnector();
        }
示例#16
0
 public void Init()
 {
     this.TestContext = new LinkerSharpContext();
 }
示例#17
0
 public FILEConsumer(string Path, LinkerSharpContext Context) : base(Context)
 {
     this.Endpoint = Path;
 }