public void DsfPublishRabbitMQActivity_Execute_Failure_NullException() { //------------Setup for test-------------------------- DsfPublishRabbitMQActivity dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); Mock <IResourceCatalog> resourceCatalog = new Mock <IResourceCatalog>(); Mock <RabbitMQSource> rabbitMQSource = new Mock <RabbitMQSource>(); Mock <ConnectionFactory> connectionFactory = new Mock <ConnectionFactory>(); resourceCatalog.Setup(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(rabbitMQSource.Object); connectionFactory.Setup(c => c.CreateConnection()).Returns <IConnection>(null); PrivateObject p = new PrivateObject(dsfPublishRabbitMQActivity); p.SetProperty("ConnectionFactory", connectionFactory.Object); p.SetProperty("ResourceCatalog", resourceCatalog.Object); //------------Execute Test--------------------------- var result = p.Invoke("PerformExecution", new Dictionary <string, string> { { "QueueName", "Q1" }, { "Message", "Test message" } }); //------------Assert Results------------------------- Assert.Fail("Exception not thrown"); }
public void RabbitSource_Different_Object_Is_Not_Equal() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var rabbitMqActivity = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A", }; var rabbitMqActivity1 = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A", }; //---------------Assert Precondition---------------- Assert.IsTrue(rabbitMqActivity.Equals(rabbitMqActivity1)); //---------------Execute Test ---------------------- rabbitMqActivity.RabbitMQSource = new RabbitMQSource() { ResourceID = Guid.NewGuid() }; rabbitMqActivity1.RabbitMQSource = new RabbitMQSource(); var @equals = rabbitMqActivity.Equals(rabbitMqActivity1); //---------------Test Result ----------------------- Assert.IsFalse(@equals); }
public void DsfPublishRabbitMQActivity_Execute_Failure_NullException() { //------------Setup for test-------------------------- var dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); var resourceCatalog = new Mock <IResourceCatalog>(); var rabbitMQSource = new Mock <RabbitMQSource>(); var connectionFactory = new Mock <ConnectionFactory>(); resourceCatalog.Setup(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(rabbitMQSource.Object); connectionFactory.Setup(c => c.CreateConnection()).Returns <IConnection>(null); var p = new Warewolf.Testing.PrivateObject(dsfPublishRabbitMQActivity); p.SetProperty("ConnectionFactory", connectionFactory.Object); dsfPublishRabbitMQActivity.ResourceCatalog = resourceCatalog.Object; try { //------------Execute Test--------------------------- _ = p.Invoke("PerformExecution", new Dictionary <string, string> { { "QueueName", "Q1" }, { "Message", "Test message" } }); } catch (TargetInvocationException e) { //------------Assert Results------------------------- Assert.AreEqual("Object reference not set to an instance of an object.", e.InnerException?.Message, "Incorrect exception thrown."); } }
public void DsfPublishRabbitMQActivity_Execute_Failure_InvalidParams() { //------------Setup for test-------------------------- DsfPublishRabbitMQActivity dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); Mock <IResourceCatalog> resourceCatalog = new Mock <IResourceCatalog>(); Mock <RabbitMQSource> rabbitMQSource = new Mock <RabbitMQSource>(); resourceCatalog.Setup(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(rabbitMQSource.Object); PrivateObject p = new PrivateObject(dsfPublishRabbitMQActivity); p.SetProperty("ResourceCatalog", resourceCatalog.Object); //------------Execute Test--------------------------- var result = p.Invoke("PerformExecution", new Dictionary <string, string> { { "Param1", "Blah1" }, { "Param2", "Blah2" } }) as List <string>; //------------Assert Results------------------------- if (result != null) { Assert.AreEqual(result[0], "Failure: Queue Name and Message are required."); } }
public void DsfSqlBulkInsertActivity_Construct_Paramterless_SetsDefaultPropertyValues() { //------------Setup for test-------------------------- //------------Execute Test--------------------------- DsfPublishRabbitMQActivity dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); //------------Assert Results------------------------- Assert.IsNotNull(dsfPublishRabbitMQActivity); Assert.AreEqual("RabbitMQ Publish", dsfPublishRabbitMQActivity.DisplayName); }
public void GivenIDragRabbitMQPublishToolOntoTheDesignSurface() { var publishActivity = new DsfPublishRabbitMQActivity(); var modelItem = ModelItemUtils.CreateModelItem(publishActivity); var model = new Mock <IRabbitMQSourceModel>(); var viewModel = new RabbitMQPublishDesignerViewModel(modelItem, model.Object); scenarioContext.Add("ViewModel", viewModel); scenarioContext.Add("Model", model); scenarioContext.Add("Activity", publishActivity); }
public void UniqueIDDifferent_EmptyPublishRabbitMQ_Is_Not_Equal() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var rabbitMqActivity = new DsfPublishRabbitMQActivity(); var rabbitMqActivity1 = new DsfPublishRabbitMQActivity(); //---------------Assert Precondition---------------- Assert.IsNotNull(rabbitMqActivity); //---------------Execute Test ---------------------- var @equals = rabbitMqActivity.Equals(rabbitMqActivity1); //---------------Test Result ----------------------- Assert.IsFalse(@equals); }
public void DsfPublishRabbitMQActivity_Execute_Sucess() { //------------Setup for test-------------------------- var dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); const string queueName = "Q1", message = "Test Message"; var body = Encoding.UTF8.GetBytes(message); var resourceCatalog = new Mock <IResourceCatalog>(); var rabbitMQSource = new Mock <RabbitMQSource>(); var connectionFactory = new Mock <ConnectionFactory>(); var connection = new Mock <IConnection>(); var channel = new Mock <IModel>(); var mockBasicProperties = new Mock <IBasicProperties>(); mockBasicProperties.SetupAllProperties(); resourceCatalog.Setup(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(rabbitMQSource.Object); connectionFactory.Setup(c => c.CreateConnection()).Returns(connection.Object); connection.Setup(c => c.CreateModel()).Returns(channel.Object); channel.Setup(c => c.QueueDeclare(queueName, false, false, false, null)); channel.Setup(c => c.BasicPublish(string.Empty, queueName, It.IsAny <bool>(), null, body)); channel.Setup(c => c.CreateBasicProperties()).Returns(mockBasicProperties.Object); var p = new PrivateObject(dsfPublishRabbitMQActivity); p.SetProperty("ConnectionFactory", connectionFactory.Object); p.SetProperty("ResourceCatalog", resourceCatalog.Object); //------------Execute Test--------------------------- var result = p.Invoke("PerformExecution", new Dictionary <string, string> { { "QueueName", queueName }, { "Message", message } }) as List <string>; //------------Assert Results------------------------- resourceCatalog.Verify(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); connectionFactory.Verify(c => c.CreateConnection(), Times.Once); connection.Verify(c => c.CreateModel(), Times.Once); channel.Verify(c => c.ExchangeDeclare(It.IsAny <String>(), It.IsAny <String>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, object> >()), Times.Once); channel.Verify(c => c.QueueDeclare(It.IsAny <String>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, object> >()), Times.Once); channel.Verify(c => c.BasicPublish(It.IsAny <String>(), It.IsAny <String>(), It.IsAny <bool>(), It.IsAny <IBasicProperties>(), It.IsAny <byte[]>()), Times.Once); Assert.AreEqual(result[0], "Success"); Assert.IsTrue(mockBasicProperties.Object.Persistent); }
public void Result_Different_Object_Is_Not_Equal() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var multiAssign = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "" }; var multiAssign1 = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "a" }; //---------------Assert Precondition---------------- Assert.IsNotNull(multiAssign); //---------------Execute Test ---------------------- var @equals = multiAssign.Equals(multiAssign1); //---------------Test Result ----------------------- Assert.IsFalse(@equals); }
public void RabbitMQSourceResourceId_Different_Object_Is_Not_Equal_CaseSensitive() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var multiAssign = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A", DisplayName = "A", RabbitMQSourceResourceId = Guid.Empty }; var multiAssign1 = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A", DisplayName = "a", RabbitMQSourceResourceId = Guid.Empty.ToString().ToLower().ToGuid() }; //---------------Assert Precondition---------------- Assert.IsNotNull(multiAssign); //---------------Execute Test ---------------------- var @equals = multiAssign.Equals(multiAssign1); //---------------Test Result ----------------------- Assert.IsFalse(@equals); }
public void RabbitMQSourceResourceId_Same_Object_IsEqual() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var multiAssign = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "", RabbitMQSourceResourceId = Guid.Empty }; var multiAssign1 = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "", RabbitMQSourceResourceId = Guid.Empty }; //---------------Assert Precondition---------------- Assert.IsNotNull(multiAssign); //---------------Execute Test ---------------------- var @equals = multiAssign.Equals(multiAssign1); //---------------Test Result ----------------------- Assert.IsTrue(@equals); }
public void Message_Different_Object_Is_Not_Equal_CaseSensitive() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var multiAssign = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A", QueueName = "AAA", Message = "KLKL" }; var multiAssign1 = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A", QueueName = "AAA", Message = "klkl" }; //---------------Assert Precondition---------------- Assert.IsNotNull(multiAssign); //---------------Execute Test ---------------------- var @equals = multiAssign.Equals(multiAssign1); //---------------Test Result ----------------------- Assert.IsFalse(@equals); }
public void DsfPublishRabbitMQActivity_Execute_Failure_NullSource() { //------------Setup for test-------------------------- var dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); var resourceCatalog = new Mock <IResourceCatalog>(); resourceCatalog.Setup(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns <RabbitMQSource>(null); var p = new PrivateObject(dsfPublishRabbitMQActivity); p.SetProperty("ResourceCatalog", resourceCatalog.Object); //------------Execute Test--------------------------- //------------Assert Results------------------------- if (p.Invoke("PerformExecution", new Dictionary <string, string>()) is List <string> result) { Assert.AreEqual(result[0], "Failure: Source has been deleted."); } }
public void DsfPublishRabbitMQActivity_Execute_Failure_NoParams() { //------------Setup for test-------------------------- var dsfPublishRabbitMQActivity = new DsfPublishRabbitMQActivity(); var resourceCatalog = new Mock <IResourceCatalog>(); var rabbitMQSource = new Mock <RabbitMQSource>(); resourceCatalog.Setup(r => r.GetResource <RabbitMQSource>(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(rabbitMQSource.Object); var p = new Warewolf.Testing.PrivateObject(dsfPublishRabbitMQActivity); dsfPublishRabbitMQActivity.ResourceCatalog = resourceCatalog.Object; //------------Execute Test--------------------------- //------------Assert Results------------------------- if (p.Invoke("PerformExecution", new Dictionary <string, string>()) is List <string> result) { Assert.AreEqual(result[0], "Failure: Queue Name and Message are required."); } }
public void IsAutoDelete_Same_Object_Is_Equal() { //---------------Set up test pack------------------- var uniqueId = Guid.NewGuid().ToString(); var rabbitMqActivity = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A" }; var rabbitMqActivity1 = new DsfPublishRabbitMQActivity() { UniqueID = uniqueId, Result = "A" }; //---------------Assert Precondition---------------- Assert.IsTrue(rabbitMqActivity.Equals(rabbitMqActivity1)); //---------------Execute Test ---------------------- rabbitMqActivity.IsAutoDelete = true; rabbitMqActivity1.IsAutoDelete = true; var @equals = rabbitMqActivity.Equals(rabbitMqActivity1); //---------------Test Result ----------------------- Assert.IsTrue(@equals); }
public void DsfPublishRabbitMQActivity_GetState_ReturnsStateVariable() { //---------------Set up test pack------------------- var sourceId = Guid.NewGuid(); //------------Setup for test-------------------------- var act = new DsfPublishRabbitMQActivity { QueueName = "bob", IsDurable = true, IsExclusive = false, Message = "hello", RabbitMQSourceResourceId = sourceId, IsAutoDelete = false, Result = "[[res]]", }; //------------Execute Test--------------------------- var stateItems = act.GetState(); Assert.AreEqual(7, stateItems.Count()); var expectedResults = new[] { new StateVariable { Name = "QueueName", Type = StateVariable.StateType.Input, Value = "bob" }, new StateVariable { Name = "IsDurable", Type = StateVariable.StateType.Input, Value = "True" }, new StateVariable { Name = "IsExclusive", Type = StateVariable.StateType.Input, Value = "False" }, new StateVariable { Name = "Message", Type = StateVariable.StateType.Input, Value = "hello" }, new StateVariable { Name = "RabbitMQSourceResourceId", Type = StateVariable.StateType.Input, Value = sourceId.ToString() }, new StateVariable { Name = "IsAutoDelete", Type = StateVariable.StateType.Input, Value = "False" }, new StateVariable { Name = "Result", Type = StateVariable.StateType.Output, Value = "[[res]]" } }; var iter = act.GetState().Select( (item, index) => new { value = item, expectValue = expectedResults[index] } ); //------------Assert Results------------------------- foreach (var entry in iter) { Assert.AreEqual(entry.expectValue.Name, entry.value.Name); Assert.AreEqual(entry.expectValue.Type, entry.value.Type); Assert.AreEqual(entry.expectValue.Value, entry.value.Value); } }