public void RabbitMQSource_NewConnection_GivenNoArgConstructor_ConnectionSuccess() { //-------------------------------Arrange----------------------------- var port = 5672; var hostName = Depends.EnableDocker?Depends.RigOpsIP:Depends.SVRDEVIP; var userName = "******"; var password = "******"; var virtualHost = "/"; var rabbitMqSource = new RabbitMQSource { HostName = hostName, UserName = userName, Password = password, Port = port, VirtualHost = virtualHost, }; //----------------------Pre-Assert--------------------------------- Assert.AreEqual(nameof(RabbitMQSource), rabbitMqSource.ResourceType); Assert.AreEqual(5672, rabbitMqSource.Port); Assert.AreEqual(Depends.EnableDocker?Depends.RigOpsIP:Depends.SVRDEVIP, rabbitMqSource.HostName); Assert.AreEqual("test", rabbitMqSource.UserName); Assert.AreEqual("test", rabbitMqSource.Password); Assert.AreEqual("/", rabbitMqSource.VirtualHost); //-------------------------------Act--------------------------------- using (var rabbitConnection = rabbitMqSource.NewConnection()) { //-------------------------------Assert------------------------------ Assert.IsTrue(rabbitConnection.IsOpen); } }
public void RabbitMQSource_NewConnection_Success() { //-------------------------------Arrange----------------------------- string xmlString = $@"<Source ID=""1a82a341-b678-4992-a25a-39cdd57198d4"" Name=""Example Rabbit MQ Source"" ResourceType=""RabbitMQSource"" IsValid=""false"" ConnectionString=""HostName={(Depends.EnableDocker?Depends.RigOpsIP:Depends.SVRDEVIP)};Port=;UserName=test;Password=test;VirtualHost=/"" Type=""RabbitMQSource"" ServerVersion=""1.4.1.27"" ServerID=""693ca20d-fb17-4044-985a-df3051d6bac7""> <DisplayName>Example Rabbit MQ Source</DisplayName> <AuthorRoles> </AuthorRoles> <ErrorMessages /> <TypeOf>RabbitMQSource</TypeOf> <VersionInfo DateTimeStamp=""2017-05-26T14:21:24.3247847+02:00"" Reason="""" User=""NT AUTHORITY\SYSTEM"" VersionNumber=""1"" ResourceId=""1a82a341-b678-4992-a25a-39cdd57198d4"" VersionId=""b1a6de00-3cac-41cd-b0ed-9fac9bb61266"" /> </Source>"; var xElement = XElement.Parse(xmlString); var rabbitMqSource = new RabbitMQSource(xElement); //----------------------Pre-Assert--------------------------------- Assert.AreEqual(nameof(RabbitMQSource), rabbitMqSource.ResourceType); Assert.AreEqual(5672, rabbitMqSource.Port); Assert.AreEqual(Depends.EnableDocker?Depends.RigOpsIP:Depends.SVRDEVIP, rabbitMqSource.HostName); Assert.AreEqual("test", rabbitMqSource.UserName); Assert.AreEqual("test", rabbitMqSource.Password); Assert.AreEqual("/", rabbitMqSource.VirtualHost); //-------------------------------Act--------------------------------- using (var rabbitConnection = rabbitMqSource.NewConnection()) { //-------------------------------Assert------------------------------ Assert.IsTrue(rabbitConnection.IsOpen); } }
public void RabbitMQSource_NewConnection_GivenNoArgConstructor_ConnectionSuccess() { //-------------------------------Arrange----------------------------- //const string xmlString = @"<Source ID=""1a82a341-b678-4992-a25a-39cdd57198d4"" Name=""Example Rabbit MQ Source"" ResourceType=""RabbitMQSource"" IsValid=""false"" // ConnectionString=""HostName=rsaklfsvrdev.dev2.local;Port=;UserName=test;Password=test;VirtualHost=/"" Type=""RabbitMQSource"" ServerVersion=""1.4.1.27"" ServerID=""693ca20d-fb17-4044-985a-df3051d6bac7""> // <DisplayName>Example Rabbit MQ Source</DisplayName> // <AuthorRoles> // </AuthorRoles> // <ErrorMessages /> // <TypeOf>RabbitMQSource</TypeOf> // <VersionInfo DateTimeStamp=""2017-05-26T14:21:24.3247847+02:00"" Reason="""" User=""NT AUTHORITY\SYSTEM"" VersionNumber=""3"" ResourceId=""1a82a341-b678-4992-a25a-39cdd57198d4"" VersionId=""b1a6de00-3cac-41cd-b0ed-9fac9bb61266"" /> // </Source>"; var port = 5672; var hostName = "rsaklfsvrdev.dev2.local"; var userName = "******"; var password = "******"; var virtualHost = "/"; var rabbitMqSource = new RabbitMQSource { HostName = hostName, UserName = userName, Password = password, Port = port, VirtualHost = virtualHost, }; //----------------------Pre-Assert--------------------------------- Assert.AreEqual(nameof(RabbitMQSource), rabbitMqSource.ResourceType); Assert.AreEqual(5672, rabbitMqSource.Port); Assert.AreEqual("rsaklfsvrdev.dev2.local", rabbitMqSource.HostName); Assert.AreEqual("test", rabbitMqSource.UserName); Assert.AreEqual("test", rabbitMqSource.Password); Assert.AreEqual("/", rabbitMqSource.VirtualHost); //-------------------------------Act--------------------------------- using (var rabbitConnection = rabbitMqSource.NewConnection()) { //-------------------------------Assert------------------------------ Assert.IsTrue(rabbitConnection.IsOpen); } }
public void RabbitMQSource_NewConnection_GivenNoArgConstructor_ConnectionSuccess() { //-------------------------------Arrange----------------------------- var dependency = new Depends(Depends.ContainerType.RabbitMQ); var port = int.Parse(dependency.Container.Port); var hostName = dependency.Container.IP; var userName = "******"; var password = "******"; var virtualHost = "/"; var rabbitMqSource = new RabbitMQSource { HostName = hostName, UserName = userName, Password = password, Port = port, VirtualHost = virtualHost, }; //----------------------Pre-Assert--------------------------------- Assert.AreEqual(nameof(RabbitMQSource), rabbitMqSource.ResourceType); Assert.AreEqual(int.Parse(dependency.Container.Port), rabbitMqSource.Port); Assert.AreEqual(dependency.Container.IP, rabbitMqSource.HostName); Assert.AreEqual("test", rabbitMqSource.UserName); Assert.AreEqual("test", rabbitMqSource.Password); Assert.AreEqual("/", rabbitMqSource.VirtualHost); //-------------------------------Act--------------------------------- try { using (var rabbitConnection = rabbitMqSource.NewConnection()) { //-------------------------------Assert------------------------------ Assert.IsTrue(rabbitConnection.IsOpen); } } catch (BrokerUnreachableException e) { Assert.Inconclusive(e.Message); } }
public void RabbitMQSource_Publish_Success() { //----------------------Arrange---------------------- var queueSource = new RabbitMQSource(); var queueName = TestQueueNameGenerator.GetName; var config = new RabbitConfig { QueueName = queueName, Exchange = "", RoutingKey = queueName, }; //----------------------Act-------------------------- var message = Guid.NewGuid().ToString(); var data = Encoding.UTF8.GetBytes(message); var connection = queueSource.NewConnection(config); try { var publisher = connection.NewPublisher(config); publisher.Publish(data); using (var testPublishSuccess = new TestPublishSuccess()) { var sentData = testPublishSuccess.GetSentMessage(config.QueueName); //------------------------Assert---------------------- Assert.AreEqual(config.Exchange, sentData.Exchange); Assert.AreEqual(config.RoutingKey, sentData.RoutingKey); Assert.AreEqual(message, Encoding.UTF8.GetString(sentData.Body)); } } finally { connection.DeleteQueue(config); connection.Dispose(); } }
public void RabbitMQSource_GivenSourceCreateNewConnection_Success() { //----------------------Arrange---------------------- var queueSource = new RabbitMQSource(); var queueName = TestQueueNameGenerator.GetName; var testConsumer = new TestConsumer(); var config = new RabbitConfig { QueueName = queueName, Exchange = "", RoutingKey = queueName, }; //----------------------Act-------------------------- using (var connection = queueSource.NewConnection(config)) { connection.StartConsuming(config, testConsumer); } int i = 0; while (!testConsumer.IsDataReceived) { Thread.Sleep(100); if (i >= 30) { break; } i++; } //----------------------Assert----------------------- Assert.IsFalse(testConsumer.IsDataReceived); }