public void ShouldAddParentNodeToNode() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer"); var order = customer.AddChild(10, "Order"); string expected = @"-Customer --Order"; Assert.That(customer.getDebugString(), Is.EqualTo(expected)); order.AddParent(1, "CustomerGroup"); expected = @"Root -Customer --CustomerGroup ---Order"; Assert.That(root.getDebugString(), Is.EqualTo(expected)); customer.AddParent(1, "Country"); expected = @"Root -Country --Customer ---CustomerGroup ----Order"; Assert.That(root.getDebugString(), Is.EqualTo(expected)); }
public void ShouldReturnTablesInCorrectOrder() { // Scenario: Make 2 customers, for each customer make two accounts and do one deposit and one withdraw for each account string[] requestedOrder = { "Customer", "Account", "Deposit", "Withdraw", "Account", "Deposit", "Withdraw", "Customer", "Account", "Deposit", "Withdraw", "Account", "Deposit", "Withdraw", }; // 2 Customers ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer"); customer.AddTable(new TableEntity("dbo", "Customer")); // Make 2 accounts var accounts = customer.AddChild(2, "Accounts"); accounts.AddTable(new TableEntity("dbo", "Account")); // make one one Deposit and one WithDraw var accountTransactions = accounts.AddChild(1, "AccountTransactions"); accountTransactions.AddTable(new TableEntity("dbo", "Deposit")); accountTransactions.AddTable(new TableEntity("dbo", "Withdraw")); NodeIterator it = new NodeIterator(customer); var actual = new List <TableEntity>(it.GetTablesRecursive().Select(x => x.Table)); for (int i = 0; i < requestedOrder.Length; i++) { Console.WriteLine(actual[i].TableName); Assert.That(requestedOrder[i], Is.EqualTo(actual[i].TableName)); } }
public void ShouldSimulateCompleteWorkflow() { DataAccess.TableEntityDataAccess tda = new DataAccess.TableEntityDataAccess(Connection()); var person = tda.GetTableAndColumns("Person", "NewPerson"); var personDetail = tda.GetTableAndColumns("Person", "AnotherTable"); personDetail.Columns.First().Generator = new ValueFromOtherColumnIntGenerator(personDetail.Columns.First().ColumnDataType); personDetail.Columns.First().Generator.GeneratorParameters.ValueFromOtherColumn.Value = person.Columns.First(); ExecutionNode node = ExecutionNode.CreateLevelOneNode(100, "Root"); node.AddTable(person); node.AddTable(personDetail); var consumerMeta = PluginLoader.GetMetaDataOfType(typeof(InsertConsumer)); var wrapper = new DataConsumerPluginWrapper(consumerMeta.ConsumerName, typeof(InsertConsumer), consumerMeta.OptionsTemplate); ExecutionResultBuilder builder = new ExecutionResultBuilder(); WorkflowManager manager = new WorkflowManager(); manager.RunWorkFlow(Connection(), wrapper, builder, options, node); var result = builder.Build(); Assert.That(result.InsertCount, Is.EqualTo(200)); Assert.That(result.Errors.Count, Is.EqualTo(0)); Assert.That(result.Duration, Is.GreaterThan(new TimeSpan(1))); }
public void shouldAddChildNodesToNode() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1); node.AddChild(100); Assert.AreEqual(1, node.Children.Count(), "Number of children"); node.AddChild(1); node.AddChild(1); Assert.AreEqual(3, node.Children.Count(), "Number of children"); foreach (var item in node.Children) { Assert.That(item.Level, Is.GreaterThan(1)); Console.WriteLine(item.Level); for (int i = 0; i < 3; i++) { item.AddChild(1); } foreach (var child in item.Children) { Assert.That(item.Level, Is.LessThan(child.Level)); } } }
public void ShouldGetZeroTotalExpectedInsertedRowWhenThereIsNoTable() { ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "No tables"); NodeIterator it = new NodeIterator(customer); long actualExpectedCount = it.GetExpectedInsertCount(); Assert.That(actualExpectedCount, Is.EqualTo(0)); }
public void shouldCreateExecutionNodeBySettingRepeatCount() { int numberOfRepeats = 10; ExecutionNode node = ExecutionNode.CreateLevelOneNode(numberOfRepeats); Assert.NotNull(node); Assert.That(node.RepeatCount, Is.EqualTo(numberOfRepeats)); }
public void ShouldNotBeAbleToRemoveRootNode() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer"); var someNode = root.RemoveNode(); Assert.That(someNode, Is.EqualTo(root)); }
public void ShouldNotBeAbleToAddSameTableTwice() { ExecutionNode node1 = ExecutionNode.CreateLevelOneNode(1); TableEntity customerTable = new TableEntity("dbo", "Customer"); node1.AddTable(customerTable); node1.AddTable(customerTable); node1.AddTable(customerTable); Assert.That(node1.Tables.Count(), Is.EqualTo(1)); }
public void ShouldNotBeAbleToMergeRootNodeWithParent() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer").AddTable(new TableEntity("dbo", "Customer")); var merged = root.MergeWithParent(); Assert.That(merged, Is.EqualTo(root)); Assert.That(merged.Tables, Is.Empty); }
public void ShouldHaveParentIfItIsChild() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1); Assert.That(root.HasChildren, Is.False); var child = root.AddChild(1); Assert.That(root.HasChildren, Is.True); Assert.That(child.Parent, Is.EqualTo(root)); }
public void ShouldRemoveNode() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer"); var order = customer.AddChild(10, "Order"); var recall = order.AddChild(1, "Recall"); var someNode = order.RemoveNode(); Assert.That(someNode, Is.EqualTo(customer), "When removing a node, the parent node should be returned"); Assert.That(customer.Children.Contains(order), Is.Not.True); }
public void ShouldInstantiateWorkflowManager() { builder = new ExecutionResultBuilder().Begin(); ExecutionNode rootNode = ExecutionNode.CreateLevelOneNode(1, "Root"); manager.RunWorkFlow(connectionString, wrapper, builder, options, rootNode); var result = builder.Build(); Assert.That(result.Errors.Count, Is.EqualTo(0), "error count"); Assert.That(result.InsertCount, Is.EqualTo(0), "insert count"); }
public void ShouldHaveNoNullValuesAfterInitialization() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1); Assert.That(node, Is.Not.Null); Assert.That(node.NodeName, Is.Not.Null); Assert.That(node.Level, Is.Not.Null); Assert.That(node.NodeId, Is.Not.Null); Assert.That(node.Tables, Is.Not.Null); Assert.That(node.Children, Is.Not.Null); Assert.That(node.RepeatCount, Is.Not.Null); }
public void ShouldNotBeAbleToAddParentToRoot() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer"); var order = customer.AddChild(10, "Order"); string beforeAddingParent = root.getDebugString(); var returnNode = root.AddParent(1, "Nono"); Assert.That(returnNode, Is.EqualTo(root)); Assert.That(root.getDebugString(), Is.EqualTo(beforeAddingParent)); }
public void ShouldRunWorkflowAsync() { builder = new ExecutionResultBuilder().Begin(); ExecutionNode rootNode = ExecutionNode.CreateLevelOneNode(1, "Root"); rootNode.AddTable(new TableEntity("dbo", "Customer")); manager.RunWorkFlowAsync(connectionString, wrapper, builder, options, rootNode); Thread.Sleep(10); // give some time for the async method to complete var result = builder.Build(); Assert.That(result.Errors.Count, Is.EqualTo(0)); Assert.That(result.InsertCount, Is.EqualTo(1)); }
public void ShouldConsumeOneRow() { builder = new ExecutionResultBuilder(); builder.Begin(); ExecutionNode rootNode = ExecutionNode.CreateLevelOneNode(1, "Root"); rootNode.AddTable(new TableEntity("dbo", "Customer")); manager.RunWorkFlow(connectionString, wrapper, builder, options, rootNode); var result = builder.Build(); Assert.That(result.Errors.Count, Is.EqualTo(0)); Assert.That(result.InsertCount, Is.EqualTo(1)); }
public void shouldProduceUniqueIdentitiesForEachNodeAdded() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1); var node2 = node.AddChild(1); var node3 = node2.AddChild(1); var node4 = node2.AddChild(1); var node5 = node.AddChild(1); Assert.That(node, Is.Not.EqualTo(node2)); Assert.That(node3, Is.Not.EqualTo(node2)); Assert.That(node4, Is.Not.EqualTo(node2)); Assert.That(node5, Is.Not.EqualTo(node)); Assert.That(node, Is.EqualTo(node)); Assert.That(node2, Is.EqualTo(node2)); }
public void ShouldNotMoveATableThatIsNotPartOfTheNode() { ExecutionNode node1 = ExecutionNode.CreateLevelOneNode(1); var customerTable = new TableEntity("dbo", "Customer"); var orderTable = new TableEntity("dbo", "Order"); node1.AddTable(customerTable); node1.MoveTableUp(orderTable); node1.MoveTableUp(orderTable); node1.MoveTableDown(orderTable); node1.MoveTableDown(orderTable); Assert.That(node1.Tables.Count(), Is.EqualTo(1)); }
public void shouldBeEqual() { ExecutionNode node1 = ExecutionNode.CreateLevelOneNode(1); ExecutionNode node2 = ExecutionNode.CreateLevelOneNode(1); ExecutionNode node3 = node1; Assert.That(node1, Is.EqualTo(node1)); Assert.That(node1, Is.EqualTo(node3)); Assert.That(node3, Is.EqualTo(node1)); Assert.That(node2, Is.EqualTo(node2)); object boxed = node1; Assert.That(boxed, Is.EqualTo(node1)); }
public void shouldIncreaseTheLevelOfEachChild() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1); var node2 = node.AddChild(100); var node3 = node2.AddChild(24); var node4 = node.AddChild(1); Assert.That(node2.Level, Is.GreaterThan(node.Level)); Assert.That(node2.Level, Is.EqualTo(node.Level + 1)); Assert.That(node3.Level, Is.GreaterThan(node2.Level)); Assert.That(node3.Level, Is.EqualTo(node2.Level + 1)); Assert.That(node4.Level, Is.GreaterThan(node.Level)); Assert.That(node4.Level, Is.EqualTo(node.Level + 1)); }
public void ShouldBeAbleToRemoveSeveralTablesFromExecutionNode() { // 2 Customers ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer"); customer.AddTable(_CustomerTable); customer.AddTable(_AccountTable); NodeIterator it = new NodeIterator(customer); Assert.That(it.GetExpectedInsertCount(), Is.EqualTo(4)); AssertOrder(it.GetTablesRecursive().Select(x => x.Table), "Customer", "Accounts", "Customer", "Accounts"); customer.RemoveTables(_AccountTable, _CustomerTable); Assert.That(it.GetExpectedInsertCount(), Is.EqualTo(0)); // AssertOrder(it.GetTablesRecursive(), "Customer", "Customer"); }
public void ShouldMoveTableDownInTheListOfTables() { ExecutionNode node1 = ExecutionNode.CreateLevelOneNode(1); TableEntity customerTable = new TableEntity("dbo", "Customer"); var orderTable = new TableEntity("dbo", "Order"); node1.AddTable(orderTable); node1.AddTable(customerTable); Assert.That(node1.Tables.Last(), Is.EqualTo(customerTable)); node1.MoveTableDown(orderTable); Assert.That(node1.Tables.Count(), Is.EqualTo(2)); Assert.That(node1.Tables.Last(), Is.EqualTo(orderTable)); node1.MoveTableUp(customerTable); Assert.That(node1.Tables.Last(), Is.EqualTo(orderTable), "moving a table below the bottom should leave it where it is"); }
public void ShouldRestartNodeCounterWhenNodeIsRestarted() { // 2 Customers ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer"); customer.AddTable(new TableEntity("dbo", "Customer")); // Make 2 accounts var accounts = customer.AddChild(2, "Accounts"); accounts.AddTable(new TableEntity("dbo", "Account")); // make one one Deposit and one WithDraw var accountTransactions = accounts.AddChild(1, "AccountTransactions"); accountTransactions.AddTable(new TableEntity("dbo", "Deposit")); accountTransactions.AddTable(new TableEntity("dbo", "Withdraw")); NodeIterator it = new NodeIterator(customer); var et = it.GetTablesRecursive().ToList(); int rowCounter = 0; et[rowCounter++].AssertNAndTable(1, "Customer"); et[rowCounter++].AssertNAndTable(1, "Account"); et[rowCounter++].AssertNAndTable(1, "Deposit"); et[rowCounter++].AssertNAndTable(1, "Withdraw"); // first customer, second account et[rowCounter++].AssertNAndTable(2, "Account"); et[rowCounter++].AssertNAndTable(1, "Deposit"); et[rowCounter++].AssertNAndTable(1, "Withdraw"); // second customer et[rowCounter++].AssertNAndTable(2, "Customer"); et[rowCounter++].AssertNAndTable(1, "Account"); et[rowCounter++].AssertNAndTable(1, "Deposit"); et[rowCounter++].AssertNAndTable(1, "Withdraw"); et[rowCounter++].AssertNAndTable(2, "Account"); et[rowCounter++].AssertNAndTable(1, "Deposit"); et[rowCounter++].AssertNAndTable(1, "Withdraw"); }
public void shouldNotBeEqual() { ExecutionNode node1 = ExecutionNode.CreateLevelOneNode(1); ExecutionNode node2 = ExecutionNode.CreateLevelOneNode(1); ExecutionNode node3 = node1; ExecutionNode node4 = null; ExecutionNode node5 = node2; Assert.That(node1, Is.Not.EqualTo(node2)); Assert.That(node2, Is.Not.EqualTo(node1)); Assert.That(node4, Is.Not.EqualTo(node1)); Assert.That(node4, Is.Null); Assert.That(node1, Is.Not.EqualTo(node4)); Assert.That(node1, Is.Not.EqualTo(new List <int>())); Console.WriteLine(node2); }
public void ShouldStopWhenAskedToBeCancled() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1000000); node.AddTable(new TableEntity("", "")); var tables = new List <ExecutionTable>(); NodeIterator iterator = new NodeIterator(node); Action a = new Action(() => { tables.AddRange(iterator.GetTablesRecursive()); }); a.BeginInvoke(null, null); Thread.Sleep(10); iterator.Cancel(); Console.WriteLine(tables.Count); Assert.That(tables.Count, Is.LessThan(1000000)); Assert.That(tables.Count, Is.GreaterThan(0)); }
public void ShouldMergeNodeWithParent() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer"); var order = customer.AddChild(10, "Order"); var recall = order.AddChild(1, "Recall"); customer.AddTable(new TableEntity("dbo", "Customer")).AddTable(new TableEntity("dbo", "Account")); order.AddTable(new TableEntity("dbo", "Order")).AddTable(new TableEntity("dbo", "OrderLine")).AddTable(new TableEntity("dbo", "Invoice")); var tablesBeforeMerge = new List <TableEntity>(customer.Tables); var tablesToBeMerged = new List <TableEntity>(order.Tables); var mergedInto = order.MergeWithParent(); Assert.That(mergedInto, Is.EqualTo(customer)); CollectionAssert.IsSubsetOf(tablesBeforeMerge, customer.Tables); CollectionAssert.IsSubsetOf(tablesToBeMerged, customer.Tables); Assert.That(customer.Tables.Count(), Is.EqualTo(tablesBeforeMerge.Count + tablesToBeMerged.Count)); Assert.That(customer.Children.Contains(recall)); }
public void ShouldBeAbleToRemoveOneTableFromExecutionNode() { // 2 Customers ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer"); customer.AddTable(_CustomerTable); // Make 2 accounts per customer ExecutionNode accounts = customer.AddChild(2, "Accounts"); accounts.AddTable(_AccountTable); NodeIterator it = new NodeIterator(customer); Assert.That(it.GetExpectedInsertCount(), Is.EqualTo(6)); AssertOrder(it.GetTablesRecursive().Select(x => x.Table), "Customer", "Accounts", "Accounts", "Customer", "Accounts", "Accounts"); accounts.RemoveTable(_AccountTable); Assert.That(it.GetExpectedInsertCount(), Is.EqualTo(2)); AssertOrder(it.GetTablesRecursive().Select(x => x.Table), "Customer", "Customer"); }
public void shouldReturnOnlyTheNodeIfOnlyOne() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1); node.AddTable(new TableEntity("", "")); int counter = 0; NodeIterator it = new NodeIterator(node); Assert.That(node.Children.Count(), Is.EqualTo(0)); HashSet <TableEntity> nodes = new HashSet <TableEntity>(); foreach (var item in it.GetTablesRecursive()) { nodes.Add(item.Table); counter++; } Assert.That(counter, Is.EqualTo(1)); Assert.That(nodes.Count, Is.EqualTo(1)); }
public void ShouldCreateDebugString() { ExecutionNode root = ExecutionNode.CreateLevelOneNode(1, "Root"); var customer = root.AddChild(1, "Customer"); var order = customer.AddChild(10, "Order"); root.AddChild(1, "Invoice"); string expected = @"Root -Customer --Order -Invoice"; string actual = root.getDebugString(); Console.WriteLine("{" + actual + "}"); Console.WriteLine("{" + expected + "}"); Assert.That(actual, Is.EqualTo(expected)); Assert.That(order.getDebugString(), Is.EqualTo("--Order")); Assert.That(customer.getDebugString(), Is.EqualTo("-Customer" + Environment.NewLine + "--Order")); }
public void ShouldGetAllExecutionItems() { ExecutionNode node = ExecutionNode.CreateLevelOneNode(1); node.AddTable(new TableEntity("", "")); node.AddTable(new TableEntity("", "")); var child = node.AddChild(1); node.AddTable(new TableEntity("", "")); node.AddTable(new TableEntity("", "")); node.AddTable(new TableEntity("", "")); NodeIterator it = new NodeIterator(node); int counter = 0; foreach (var ei in it.GetTablesRecursive()) { Console.WriteLine(ei); counter++; } Assert.That(counter, Is.EqualTo(5)); }